Python paramiko.ssh_exception() Examples
The following are 4
code examples of paramiko.ssh_exception().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
paramiko
, or try the search function
.
Example #1
Source File: paramiko.py From testinfra with Apache License 2.0 | 5 votes |
def run(self, command, *args, **kwargs): command = self.get_command(command, *args) command = self.encode(command) try: rc, stdout, stderr = self._exec_command(command) except paramiko.ssh_exception.SSHException: if not self.client.get_transport().is_active(): # try to reinit connection (once) del self.client rc, stdout, stderr = self._exec_command(command) else: raise return self.result(rc, command, stdout, stderr)
Example #2
Source File: paramiko_ssh.py From st2 with Apache License 2.0 | 5 votes |
def _get_pkey_object(self, key_material, passphrase): """ Try to detect private key type and return paramiko.PKey object. """ for cls in [paramiko.RSAKey, paramiko.DSSKey, paramiko.ECDSAKey]: try: key = cls.from_private_key(StringIO(key_material), password=passphrase) except paramiko.ssh_exception.SSHException: # Invalid key, try other key type pass else: return key # If a user passes in something which looks like file path we throw a more friendly # exception letting the user know we expect the contents a not a path. # Note: We do it here and not up the stack to avoid false positives. contains_header = REMOTE_RUNNER_PRIVATE_KEY_HEADER in key_material.lower() if not contains_header and (key_material.count('/') >= 1 or key_material.count('\\') >= 1): msg = ('"private_key" parameter needs to contain private key data / content and not ' 'a path') elif passphrase: msg = 'Invalid passphrase or invalid/unsupported key type' else: msg = 'Invalid or unsupported key type' raise paramiko.ssh_exception.SSHException(msg)
Example #3
Source File: paramiko_ssh.py From st2 with Apache License 2.0 | 5 votes |
def _is_key_file_needs_passphrase(file): for cls in [paramiko.RSAKey, paramiko.DSSKey, paramiko.ECDSAKey]: try: cls.from_private_key_file(file, password=None) except paramiko.ssh_exception.PasswordRequiredException: return True except paramiko.ssh_exception.SSHException: continue return False
Example #4
Source File: CI.py From bubble-toolkit with Apache License 2.0 | 4 votes |
def cleanup(self, jsonpath=None, vm=None, name_path=None, result_filter=None, collect_logs=True): """Collect all data and cleanup VM's and images Example: ci = CI('/data/shared/marvin/marvin.json') ci.cleanup(config=config, jsonpath='zones[*].pods[*].clusters[*].hosts[*]', namepath='url', filter=lambda x: x.split('/')[::-1][0]) :param jsonpath: JSONPath to filter out JSON :param vm: Name of the instance to remove :param name_path: Optional parameter to filter out json :param result_filter: Optional lambda to use on filtered result :param collect_logs: Collect logs and coverage files """ for i in parse(jsonpath).find(self.config): properties = i.value username = properties.get('username', properties.get('user', 'root')) password = properties.get('password', properties.get('passwd', 'password')) if name_path: vm = parse(name_path).find(properties)[0].value if result_filter: vm = result_filter(vm) if collect_logs: print("==> Collecting Logs and Code Coverage Report from %s" % vm) # TODO: Copy logs and coverage reports from HV and SCP them # collect_files_from_vm ${csip} ${csuser} ${cspass} "/var/log/cosmic/management/*.log*" "cs${i}-management-logs/" if vm.startswith('cs'): src = "/var/log/cosmic/management/*.log*" dstdir = "%s-management-logs" % vm hostname = properties['mgtSvrIp'] else: src = "/var/log/cosmic/agent/*.log*" dstdir = "%s-agent-logs" % vm hostname = vm if not os.path.exists(dstdir): os.makedirs(dstdir) try: self.collect_files_from_vm(hostname=hostname, username=username, password=password, src=src, dst="%s" % dstdir) except (scp.SCPException, paramiko.ssh_exception) as e: print("ERROR: %s" % e.message) print("==> Destroying VM %s" % vm) # FIXME: Create library for this instead of a subprocess subprocess.call(['/data/shared/deploy/kvm_local_deploy.py', '-x', vm])