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

Last change on this file since 13564 was 12574, checked in by rick, 11 years ago

Neem ook masterip mee in de checks.

Fixes beheer:ticket:411

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 1.7 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
9from collections import defaultdict
10
11__version__ = '$Id: syntax-checker.py 12574 2013-12-17 20:12:22Z rick $'
12
13allowed_multi_use = ['0.0.0.0', '192.168.1.', '192.168.178.']
14
15def check_double_ip():
16 pool = defaultdict(list)
17 try:
18 for host in gformat.get_hostlist():
19 print "## Processing host %-25s: " % host,
20 datadump = gformat.get_yaml(host,add_version_info=False)
21 try:
22 # Process interfaces
23 iface_keys = [elem for elem in datadump.keys() if (elem.startswith('iface_') and not "lo0" in elem)]
24 for iface_key in iface_keys:
25 l = datadump[iface_key]['ip']
26 addr, mask = l.split('/')
27
28 pool[addr].append((host, iface_key))
29
30 iface_key = 'masterip'
31 addr = datadump['masterip']
32 # Add masterip to the list if IP has not been defined at interface
33 if not host in [x[0] for x in pool[addr]]:
34 pool[addr].append((host, 'masterip'))
35
36 print "OK"
37 except (KeyError, ValueError), e:
38 print "[ERROR] in '%s' interface '%s' (%s)" % (host, iface_key, e)
39 raise
40 except Exception as e:
41 raise
42 sys.exit(1)
43
44 error = False
45 for addr,leden in pool.iteritems():
46 if len(leden) > 1:
47 if not any(map(lambda x: addr.startswith(x), allowed_multi_use)):
48 print "[ERROR] Multiple usages of IP %s:" % (addr)
49 for host, key in leden:
50 print " - %s - %s" % (host, key)
51 error = True
52
53 if error:
54 print "# Errors found"
55 return 1
56 else:
57 print "# No multiple usages of IPs found"
58 return 0
59
60
61if __name__ == "__main__":
62 sys.exit(check_double_ip())
63
Note: See TracBrowser for help on using the repository browser.