source: genesis/tools/syntax-checker.py@ 11405

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

Show which rev is dying.

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 1.4 KB
Line 
1#!/usr/bin/env python
2# vim:ts=2:et:sw=2:ai
3#
4# Build topological network graph
5# Rick van der Zwet <info@rickvanderzwet.nl>
6import gformat
7import sys
8
9__version__ = '$Id: syntax-checker.py 10904 2012-05-18 21:48:21Z rick $'
10
11allowed_multi_use = ['0.0.0.0', '192.168.1.100']
12
13def check_double_ip():
14 pool = {}
15 try:
16 for host in gformat.get_hostlist():
17 print "## Processing host %-20s: " % host,
18 datadump = gformat.get_yaml(host,add_version_info=False)
19 try:
20 iface_keys = [elem for elem in datadump.keys() if (elem.startswith('iface_') and not "lo0" in elem)]
21 for iface_key in iface_keys:
22 l = datadump[iface_key]['ip']
23 addr, mask = l.split('/')
24
25 label = "%s - %s" % (host, iface_key)
26 if pool.has_key(addr):
27 pool[addr] += [label]
28 else:
29 pool[addr] = [label]
30 print "OK"
31 except (KeyError, ValueError), e:
32 print "[ERROR] in '%s' interface '%s' (%s)" % (host,iface_key, e)
33 raise
34 except Exception as e:
35 raise
36 sys.exit(1)
37
38 error = False
39 for addr,leden in pool.iteritems():
40 if len(leden) > 1:
41 if not addr in allowed_multi_use:
42 print "[ERROR] Multiple usages of IP %s:" % (addr)
43 print " -", "\n - ".join(leden)
44 error = True
45
46 if error:
47 print "# Errors found"
48 return 1
49 else:
50 print "# No multiple usages of IPs found"
51 return 0
52
53
54if __name__ == "__main__":
55 sys.exit(check_double_ip())
56
Note: See TracBrowser for help on using the repository browser.