Here is my version of
http://markpasc.typepad.com/blog/2010/04/loading-ssh-config-settings-for-fabric.html
following yesterday's discussion on irc.
Is this useful?
#!/usr/bin/env python
"""
Load an ssh config file using Paramiko
Author : Rory Campbell-Lange
Started : 01 March 2011
"""
from os.path import expanduser
from paramiko.config import SSHConfig
class Host:
def __init__(self, hash):
for k,v in hash.items():
setattr(self, k, v)
def __repr__(self):
printables = [i for i in dir(self) if '_' not in i]
printables.sort()
tpl = '\t%-14s : %s\n'
x = ''
for p in printables:
x += tpl % (p, getattr(self,p))
return x
def load_ssh_config(filer='~/.ssh/config'):
'''Load an ssh config file'''
p = SSHConfig()
f = open(expanduser(filer))
p.parse(f)
# wierd
hosts_array = p.__dict__['_config']
hosts = {}
for h in hosts_array[1:]:
hosts[h['host']] = Host(h)
return hosts
if __name__ == '__main__':
hosts = load_ssh_config()
for h in hosts:
print h
print hosts[h]
--
Rory Campbell-Lange
[email protected]
_______________________________________________
Fab-user mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/fab-user