Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import paramiko
- from MPS.factory.config import config
- class ssh:
- def __init__(self, command):
- ssh = self.connect()
- command_output = {}
- command_output = self.run_command(ssh, command)
- ssh.close()
- def connect(self):
- ssh = paramiko.SSHClient()
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- ssh.connect(config.get('login', 'host'),
- username=config.get('login', 'username'),
- password=config.get('login', 'password'))
- return ssh
- def run_command(self, ssh, command):
- output = {}
- try:
- stdin, stdout, stderr = ssh.exec_command(command)
- type(stdin)
- except Exception, e:
- self.ssh_error = str(e)
- self.output = []
- self.output_error = []
- return output
- self.output = stdout.readlines()
- self.output_error = stderr.readlines()
- self.ssh_error = []
- return output
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement