本文整理汇总了Python中paramiko.config.SSHConfig.get_hostnames方法的典型用法代码示例。如果您正苦于以下问题:Python SSHConfig.get_hostnames方法的具体用法?Python SSHConfig.get_hostnames怎么用?Python SSHConfig.get_hostnames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类paramiko.config.SSHConfig
的用法示例。
在下文中一共展示了SSHConfig.get_hostnames方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _annotate_hosts_with_ssh_config_info
# 需要导入模块: from paramiko.config import SSHConfig [as 别名]
# 或者: from paramiko.config.SSHConfig import get_hostnames [as 别名]
def _annotate_hosts_with_ssh_config_info(path):
from os.path import expanduser
from paramiko.config import SSHConfig
def hostinfo(host, config):
hive = config.lookup(host)
# if 'hostname' in hive:
# host = hive['hostname']
if 'user' in hive:
host = '%[email protected]%s' % (hive['user'], host)
if 'port' in hive:
host = '%s:%s' % (host, hive['port'])
#print 'hive',hive
#print 'host',host
return host
try:
config_file = file(expanduser(path))
except IOError:
pass
else:
config = SSHConfig()
config.parse(config_file)
# add hosts from ssh config to env.host & sort + unique
env.hosts.extend([h for h in config.get_hostnames() if len(h) > 1])
env.hosts = sorted(set(env.hosts))
keys = [config.lookup(host).get('identityfile', None) for host in env.hosts]
# flatten
keys = [item for sublist in keys if sublist is not None for item in sublist]
env.key_filename = [expanduser(key) for key in keys if key is not None]
env.hosts = [hostinfo(host, config) for host in env.hosts]
for role, rolehosts in env.roledefs.items():
env.roledefs[role] = [hostinfo(host, config) for host in rolehosts]