diff options
author | Jose Lausuch <jose.lausuch@ericsson.com> | 2017-02-01 11:55:27 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-02-01 11:55:27 +0000 |
commit | 829036742bbb4c75d8528e9fbfc805ca00244b81 (patch) | |
tree | 04863ba199156ea7fce3eada1280633aa366534d /modules/opnfv/utils/SSHUtils.py | |
parent | 800087dd804d8011303154754059087d55a7a549 (diff) | |
parent | 816695878485fb6cb8742e10c81f1d43b2052501 (diff) |
Merge "Create Apex Adapter"
Diffstat (limited to 'modules/opnfv/utils/SSHUtils.py')
-rw-r--r-- | modules/opnfv/utils/SSHUtils.py | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/modules/opnfv/utils/SSHUtils.py b/modules/opnfv/utils/SSHUtils.py index 16e34c3e5..e0a830caa 100644 --- a/modules/opnfv/utils/SSHUtils.py +++ b/modules/opnfv/utils/SSHUtils.py @@ -16,7 +16,11 @@ import os logger = OPNFVLogger.Logger('SSHUtils').getLogger() -def get_ssh_client(hostname, username, password=None, proxy=None): +def get_ssh_client(hostname, + username, + password=None, + proxy=None, + pkey_file=None): client = None try: if proxy is None: @@ -26,14 +30,21 @@ def get_ssh_client(hostname, username, password=None, proxy=None): client.configure_jump_host(proxy['ip'], proxy['username'], proxy['password']) - if client is None: raise Exception('Could not connect to client') client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - client.connect(hostname, - username=username, - password=password) + if pkey_file is not None: + key = paramiko.RSAKey.from_private_key_file(pkey_file) + client.load_system_host_keys() + client.connect(hostname, + username=username, + pkey=key) + else: + client.connect(hostname, + username=username, + password=password) + return client except Exception, e: logger.error(e) @@ -66,6 +77,7 @@ class ProxyHopClient(paramiko.SSHClient): ''' Connect to a remote server using a proxy hop ''' + def __init__(self, *args, **kwargs): self.logger = OPNFVLogger.Logger("ProxyHopClient").getLogger() self.proxy_ssh = None |