本文整理匯總了Python中paramiko.SSHConfig._config方法的典型用法代碼示例。如果您正苦於以下問題:Python SSHConfig._config方法的具體用法?Python SSHConfig._config怎麽用?Python SSHConfig._config使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類paramiko.SSHConfig
的用法示例。
在下文中一共展示了SSHConfig._config方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from paramiko import SSHConfig [as 別名]
# 或者: from paramiko.SSHConfig import _config [as 別名]
def main(args):
config = SSHConfig()
if os.path.isfile(SSH_CONFIG):
config.parse(open(SSH_CONFIG))
else:
print "[+] %s does not exists. Creating an empty one." % SSH_CONFIG
file(SSH_CONFIG, 'w').write("")
if args.delete:
print "[+] delete section Host %s" % args.alias
config._config = [
section for section in config._config if
args.alias not in section['host']]
else:
if (args.hostname and args.alias and
(args.key_path or args.key_from_stdin)):
if args.key_from_stdin:
print "[+] read the key from stdin ..."
fd, key_path = tempfile.mkstemp(suffix='_%s.key' % args.alias)
for line in sys.stdin:
os.write(fd, line)
os.fsync(fd)
key_path = copy_key(key_path)
else:
key_path = copy_key(args.key_path)
print "[+] add section Host %s" % args.alias
# Clean section with the name
config._config = [
section for section in config._config if
args.alias not in section['host']]
section = section_template
section['host'] = [args.alias]
section['config']['hostname'] = args.hostname
section['config']['identityfile'] = [key_path]
config._config.append(section)
print "[+] write the ssh_config file"
write(config._config)