本文整理汇总了Python中paramiko.ssh_exception方法的典型用法代码示例。如果您正苦于以下问题:Python paramiko.ssh_exception方法的具体用法?Python paramiko.ssh_exception怎么用?Python paramiko.ssh_exception使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类paramiko
的用法示例。
在下文中一共展示了paramiko.ssh_exception方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import ssh_exception [as 别名]
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)
示例2: _get_pkey_object
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import ssh_exception [as 别名]
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)
示例3: _is_key_file_needs_passphrase
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import ssh_exception [as 别名]
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
示例4: cleanup
# 需要导入模块: import paramiko [as 别名]
# 或者: from paramiko import ssh_exception [as 别名]
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])