[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fab-user] Parsing ssh config files
From: |
Rory Campbell-Lange |
Subject: |
[Fab-user] Parsing ssh config files |
Date: |
Tue, 1 Mar 2011 23:21:20 +0000 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
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
address@hidden
- [Fab-user] Parsing ssh config files,
Rory Campbell-Lange <=