source: genesis/tools/check-batch-cmd@ 10074

Last change on this file since 10074 was 10074, checked in by rick, 13 years ago

Which bridge type do we configure?

Requested-By: richardvm

  • Property svn:executable set to *
File size: 1.8 KB
Line 
1#!/usr/bin/env python
2# vim:ts=2:et:sw=2:ai
3#
4# Check configs with remote addresses
5#
6# Rick van der Zwet <info@rickvanderzwet.nl>
7#
8import gformat
9import sys
10import socket
11import paramiko
12
13class CmdError(Exception):
14 pass
15
16try:
17 raise CmdError("rick")
18except (socket.timeout, socket.error):
19 print "### Conection failed"
20except paramiko.AuthenticationException:
21 print "### Conection failed (invalid username/password)"
22except CmdError, e:
23 print "### Command error: %s" % e
24
25def check_host(hostname):
26 cmd = "cat /etc/board.info"
27
28 ssh = paramiko.SSHClient()
29 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
30 ssh.connect(hostname, username='root', password='p2nn3nk03k',timeout=3)
31 stdin, stdout, stderr = ssh.exec_command(cmd)
32 stdout = stdout.readlines()
33 stderr = stderr.readlines()
34 ssh.close()
35 if stderr:
36 raise CmdError(stderr)
37
38 return dict(map(lambda x: x.strip().split('='),stdout))
39
40
41def main():
42 for host in gformat.get_hostlist():
43 print "# Processing host", host
44 datadump = gformat.get_yaml(host)
45 for iface_key in datadump['autogen_iface_keys']:
46 ifacedump = datadump[iface_key]
47 if ifacedump.has_key('ns_ip'):
48 addr = ifacedump['ns_ip'].split('/')[0]
49 print "## Bridge IP: %s" % addr
50 try:
51 socket.create_connection((addr,80),2)
52 d = check_host(addr)
53 datadump[iface_key]['bridge_type'] = d['board.name']
54 except (socket.timeout, socket.error):
55 print "### Conection failed"
56 except paramiko.AuthenticationException:
57 print "### Conection failed (invalid username/password)"
58 except CmdError, e:
59 print "### Command error: %s" % e
60 gformat.store_yaml(datadump)
61
62
63if __name__ == '__main__':
64 if sys.argv[1:]:
65 for host in sys.argv[1:]:
66 check_host(host)
67 main()
Note: See TracBrowser for help on using the repository browser.