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

Last change on this file since 12304 was 12291, checked in by rick, 12 years ago

Multiple ranges to be ignored, using prefixes making syntaxing more easy.

  • 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 12291 2013-05-08 18:29:39Z rick $'
10
11allowed_multi_use = ['0.0.0.0', '192.168.1.', '192.168.178.']
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 any(map(lambda x: addr.startswith(x), 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.