This commit is contained in:
Kai Wansart 2018-02-02 20:30:04 +01:00
parent 807e3ebc9e
commit d7875b9535

View File

@ -13,18 +13,25 @@ class SSH(object):
self.devices[device]['ip'] = devices[device]['ip']
##-----------------------------------------------------------------------------------##
def command(self, device, command):
def command(self, data):
##-----------------------------------------------------------------------------------##
self.client = SSHClient()
self.client.load_system_host_keys()
self.client.connect(self.devices[device]['ip'], self.devices[device]['user'])
if(command=="shutdown"):
self.shutdown(device)
if(command=="reboot"):
self.reboot(device)
if(command=="upgrade"):
self.upgrade(device)
for device in data:
if device in self.devices:
ip = self.devices[device]['ip']
user = self.devices[device]['user']
try:
client = SSHClient()
client.load_system_host_keys()
client.connect(ip = ip, user = user)
except:
print("Server nicht erreichbar")
finally:
if(data[device]=="shutdown"):
client.exec_command('poweroff')
if(data[device]=="reboot"):
client.exec_command('reboot')
if(data[device]=="upgrade"):
client.exec_command('apt update && apt upgrade -y')
##-----------------------------------------------------------------------------------##
def config(self):
@ -53,17 +60,14 @@ class SSH(object):
##-----------------------------------------------------------------------------------##
def shutdown(self, device):
##-----------------------------------------------------------------------------------##
self.connect()
self.client.exec_command('poweroff')
##-----------------------------------------------------------------------------------##
def reboot(self, device):
##-----------------------------------------------------------------------------------##
self.connect()
self.client.exec_command('reboot')
##-----------------------------------------------------------------------------------##
def upgrade(self, device):
##-----------------------------------------------------------------------------------##
self.connect()
self.client.exec_command('apt update && apt upgrade -y')