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

Last change on this file since 13973 was 13618, checked in by rick, 8 years ago

Re-do bridge configuration to support VLAN administation.

The current bridge implementation has limits when it comes to configuring
interfaces. Since a bridge member does not have an IP yet it has connected
interface (via an VLAN switch) thus this details needs to be stored.

It is also considered to be confusing, since bridge(4) interfaces do appea
even if you did not configure them, potentially changing configurations of all
current nodes as well, which makes testing and deployment an tricky business.

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 1.8 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 13618 2016-08-26 09:43:15Z 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 # Virtual interfaces bridge interfaces do not have IP addreses
26 if not datadump[iface_key].has_key('ip'):
27 continue
28
29 l = datadump[iface_key]['ip']
30 addr, mask = l.split('/')
31
32 pool[addr].append((host, iface_key))
33
34 iface_key = 'masterip'
35 addr = datadump['masterip']
36 # Add masterip to the list if IP has not been defined at interface
37 if not host in [x[0] for x in pool[addr]]:
38 pool[addr].append((host, 'masterip'))
39
40 print "OK"
41 except (KeyError, ValueError), e:
42 print "[ERROR] in '%s' interface '%s' (%s)" % (host, iface_key, e)
43 raise
44 except Exception as e:
45 raise
46 sys.exit(1)
47
48 error = False
49 for addr,leden in pool.iteritems():
50 if len(leden) > 1:
51 if not any(map(lambda x: addr.startswith(x), allowed_multi_use)):
52 print "[ERROR] Multiple usages of IP %s:" % (addr)
53 for host, key in leden:
54 print " - %s - %s" % (host, key)
55 error = True
56
57 if error:
58 print "# Errors found"
59 return 1
60 else:
61 print "# No multiple usages of IPs found"
62 return 0
63
64
65if __name__ == "__main__":
66 sys.exit(check_double_ip())
67
Note: See TracBrowser for help on using the repository browser.