Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class myssh(paramiko.SSHClient):
- @classmethod
- @contextmanager
- def connect(cls, credentials, password=None):
- username, host = credentials.split('@')
- ssh = cls()
- try:
- super(SSH, ssh).connect(host, username=username, password=password)
- yield ssh
- finally:
- ssh.close()
- with myssh.connect(user_machine, password=password) as ssh:
- stdin, stdout, stderr = ssh.exec_command(my_command)
- return_code = stdout.channel.recv_exit_status()
- out = stdout.read().decode('utf-8')
- err = stderr.read().decode('utf-8')
- if out.strip():
- print(out.strip())
- if err.strip():
- print(err.strip())
- Exception ignored in: <object repr() failed>
- Traceback (most recent call last):
- File "/home/baralv/.miniconda2/envs/py3/lib/python3.5/site-packages/paramiko/file.py", line 61, in __del__
- File "/home/baralv/.miniconda2/envs/py3/lib/python3.5/site-packages/paramiko/file.py", line 79, in close
- File "/home/baralv/.miniconda2/envs/py3/lib/python3.5/site-packages/paramiko/file.py", line 88, in flush
- TypeError: 'NoneType' object is not callable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement