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

Last change on this file since 13984 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
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 13618 2016-08-26 09:43:15Z 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)
21 try:
[12574]22 # Process interfaces
[10904]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:
[13618]25 # Virtual interfaces bridge interfaces do not have IP addreses
26 if not datadump[iface_key].has_key('ip'):
27 continue
28
[10904]29 l = datadump[iface_key]['ip']
30 addr, mask = l.split('/')
[8268]31
[12574]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
[10904]40 print "OK"
41 except (KeyError, ValueError), e:
[12574]42 print "[ERROR] in '%s' interface '%s' (%s)" % (host, iface_key, e)
[10904]43 raise
44 except Exception as e:
[10820]45 raise
[8268]46 sys.exit(1)
47
48 error = False
49 for addr,leden in pool.iteritems():
50 if len(leden) > 1:
[12291]51 if not any(map(lambda x: addr.startswith(x), allowed_multi_use)):
[8268]52 print "[ERROR] Multiple usages of IP %s:" % (addr)
[12574]53 for host, key in leden:
54 print " - %s - %s" % (host, key)
[8268]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.