This repository has been archived on 2023-06-10. You can view files and clone it, but cannot push or open issues or pull requests.

44 lines
2.1 KiB
Python
Raw Normal View History

2018-02-02 00:21:59 +01:00
from paramiko import SSHClient
##---------------------------------------------------------------------------------------##
class SSH(object):
##---------------------------------------------------------------------------------------##
##-----------------------------------------------------------------------------------##
def __init__(self, devices):
##-----------------------------------------------------------------------------------##
for device in devices:
self.devices[device] = {}
self.devices[device]['user'] = devices[device]['user']
self.devices[device]['ip'] = devices[device]['ip']
##-----------------------------------------------------------------------------------##
def command(self, device, command):
##-----------------------------------------------------------------------------------##
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)
##-----------------------------------------------------------------------------------##
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')