forked from docc-lab/openstack-build-ubuntu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manifest-to-topomap.py
executable file
·65 lines (57 loc) · 1.74 KB
/
manifest-to-topomap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python2
import sys
import lxml.etree
iface_link_map = {}
link_members = {}
node_ifaces = {}
link_netmasks = {}
allifaces = {}
f = open(sys.argv[1],'r')
contents = f.read()
f.close()
root = lxml.etree.fromstring(contents)
# Find all the links:
for elm in root.getchildren():
if not elm.tag.endswith("}link"):
continue
name = elm.get("client_id")
ifacerefs = []
for elm2 in elm.getchildren():
if not elm2.tag.endswith("}interface_ref"):
continue
ifacename = elm2.get("client_id")
ifacerefs.append(ifacename)
iface_link_map[ifacename] = name
link_members[name] = ifacerefs
# Find all the node interfaces
for elm in root.getchildren():
if not elm.tag.endswith("}node"):
continue
name = elm.get("client_id")
ifaces = {}
for elm2 in elm.getchildren():
if not elm2.tag.endswith("}interface"):
continue
ifacename = elm2.get("client_id")
for elm3 in elm2.getchildren():
if not elm3.tag.endswith("}ip"):
continue
if not elm3.get("type") == 'ipv4':
continue
addrtuple = (elm3.get("address"),elm3.get("netmask"))
ifaces[ifacename] = addrtuple
allifaces[ifacename] = addrtuple
break
node_ifaces[name] = ifaces
# Dump the nodes a la topomap
print "# nodes: vname,links"
for n in node_ifaces.keys():
for (i,(addr,mask)) in node_ifaces[n].iteritems():
print "%s,%s:%s" % (n,iface_link_map[i],addr)
# Dump the links a la topomap -- but with fixed cost of 1
print "# lans: vname,mask,cost"
for m in link_members.keys():
ifref = link_members[m][0]
(ip,mask) = allifaces[ifref]
print "%s,%s,1" % (m,mask)
sys.exit(0)