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'] self.devices[device]['ip'] = devices[device]['ip']
##-----------------------------------------------------------------------------------## ##-----------------------------------------------------------------------------------##
def command(self, device, command): def command(self, data):
##-----------------------------------------------------------------------------------## ##-----------------------------------------------------------------------------------##
self.client = SSHClient() for device in data:
self.client.load_system_host_keys() if device in self.devices:
self.client.connect(self.devices[device]['ip'], self.devices[device]['user']) ip = self.devices[device]['ip']
user = self.devices[device]['user']
if(command=="shutdown"): try:
self.shutdown(device) client = SSHClient()
if(command=="reboot"): client.load_system_host_keys()
self.reboot(device) client.connect(ip = ip, user = user)
if(command=="upgrade"): except:
self.upgrade(device) 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): def config(self):
@ -53,17 +60,14 @@ class SSH(object):
##-----------------------------------------------------------------------------------## ##-----------------------------------------------------------------------------------##
def shutdown(self, device): def shutdown(self, device):
##-----------------------------------------------------------------------------------## ##-----------------------------------------------------------------------------------##
self.connect()
self.client.exec_command('poweroff') self.client.exec_command('poweroff')
##-----------------------------------------------------------------------------------## ##-----------------------------------------------------------------------------------##
def reboot(self, device): def reboot(self, device):
##-----------------------------------------------------------------------------------## ##-----------------------------------------------------------------------------------##
self.connect()
self.client.exec_command('reboot') self.client.exec_command('reboot')
##-----------------------------------------------------------------------------------## ##-----------------------------------------------------------------------------------##
def upgrade(self, device): def upgrade(self, device):
##-----------------------------------------------------------------------------------## ##-----------------------------------------------------------------------------------##
self.connect()
self.client.exec_command('apt update && apt upgrade -y') self.client.exec_command('apt update && apt upgrade -y')