Advertisement
Guest User

Untitled

a guest
Sep 17th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import paramiko
  4. from MPS.factory.config import config
  5.  
  6. class ssh:
  7.     def __init__(self, command):
  8.         ssh = self.connect()
  9.         command_output = {}
  10.         command_output = self.run_command(ssh, command)
  11.         ssh.close()
  12.  
  13.     def connect(self):
  14.         ssh = paramiko.SSHClient()
  15.         ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  16.         ssh.connect(config.get('login', 'host'),
  17.                     username=config.get('login', 'username'),
  18.                     password=config.get('login', 'password'))
  19.  
  20.         return ssh
  21.  
  22.     def run_command(self, ssh, command):
  23.         output = {}
  24.         try:
  25.             stdin, stdout, stderr = ssh.exec_command(command)
  26.             type(stdin)
  27.         except Exception, e:
  28.             self.ssh_error = str(e)
  29.             self.output = []
  30.             self.output_error = []
  31.             return output
  32.  
  33.         self.output = stdout.readlines()
  34.         self.output_error = stderr.readlines()
  35.         self.ssh_error = []
  36.         return output
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement