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

Last change on this file since 13987 was 13987, checked in by rick, 7 years ago

Fix unknown variables which yields errors later in the process where not checked properly

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