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

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

Slightly more descriptive where we are failing exactly.

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 1.3 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 10820 2012-05-13 11:57:41Z 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)
19 iface_keys = [elem for elem in datadump.keys() if (elem.startswith('iface_') and not "lo0" in elem)]
20 for iface_key in iface_keys:
21 l = datadump[iface_key]['ip']
22 addr, mask = l.split('/')
23
24 label = "%s - %s" % (host, iface_key)
25 if pool.has_key(addr):
26 pool[addr] += [label]
27 else:
28 pool[addr] = [label]
29 print "OK"
30 except (KeyError, ValueError), e:
31 print "[ERROR] in '%s' interface '%s' (%s)" % (host,iface_key, e)
32 raise
33 sys.exit(1)
34
35 error = False
36 for addr,leden in pool.iteritems():
37 if len(leden) > 1:
38 if not addr in allowed_multi_use:
39 print "[ERROR] Multiple usages of IP %s:" % (addr)
40 print " -", "\n - ".join(leden)
41 error = True
42
43 if error:
44 print "# Errors found"
45 return 1
46 else:
47 print "# No multiple usages of IPs found"
48 return 0
49
50
51if __name__ == "__main__":
52 sys.exit(check_double_ip())
53
Note: See TracBrowser for help on using the repository browser.