Advertisement
Guest User

Untitled

a guest
May 6th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. class TransportUtils:
  2.    
  3.     def __init__(self, host, port, login, password):
  4.         self.host = host
  5.         self.port = port
  6.         self.login = login
  7.         self.password = password
  8.    
  9.     def open_connection(self):
  10.         self.client = paramiko.SSHClient()
  11.  
  12.         self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  13.  
  14.         self.client.connect(hostname=self.host, port=self.port, username=self.login, password=self.password)
  15.        
  16.  
  17.     def get_transport(self):
  18.         if self.client is None:
  19.             open_connection(self)
  20.  
  21.         stdin, stdout, stderr = self.client.exec_command('ls -a')  # ('apt list --installed')
  22.  
  23.         results = stdout.read()
  24.  
  25.         transport: paramiko.Transport = self.client.get_transport()
  26.  
  27.         if transport is None:
  28.             raise UnknownTransport()
  29.  
  30.         return transport
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement