本文整理匯總了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]