Skip to content

Commit e525cc7

Browse files
committedAug 14, 2020
Include python versions of manifest extractors.
1 parent f30552b commit e525cc7

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed
 

‎manifest-to-parameters.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python
2+
3+
from __future__ import print_function
4+
import sys
5+
import lxml.etree
6+
7+
f = open(sys.argv[1],'r')
8+
contents = f.read()
9+
f.close()
10+
root = lxml.etree.fromstring(contents)
11+
12+
def convert(p,v):
13+
if v in [ "True","true" ]:
14+
v = 1
15+
elif v in [ "False","false" ]:
16+
v = 0
17+
elif v == None:
18+
return ""
19+
return v
20+
21+
# Find our node and dump any labels:
22+
for elm in root.getchildren():
23+
if elm.tag.endswith("}label"):
24+
print("%s=%s" % (elm.get("name").upper(),elm.text))
25+
if elm.tag.endswith("}data_set"):
26+
for elm2 in elm.getchildren():
27+
if elm2.tag.endswith("}data_item"):
28+
p = elm2.get("name")
29+
v = str(convert(p,elm2.text))
30+
if v.find(" ") > -1:
31+
v = '"' + v + '"'
32+
print("%s=%s" % (p.split(".")[-1].upper(),v))
33+
if elm.tag.endswith("}data_item"):
34+
p = elm.get("name")
35+
print("%s=%s" % (p.split(".")[-1].upper(),str(convert(p,elm.text))))
36+
37+
sys.exit(0)

‎manifest-to-topomap.py

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env python
2+
3+
from __future__ import print_function
4+
from future.utils import iteritems
5+
import sys
6+
import lxml.etree
7+
8+
iface_link_map = {}
9+
link_members = {}
10+
node_ifaces = {}
11+
link_netmasks = {}
12+
allifaces = {}
13+
14+
f = open(sys.argv[1],'r')
15+
contents = f.read()
16+
f.close()
17+
root = lxml.etree.fromstring(contents)
18+
19+
mycluster = None
20+
if len(sys.argv) > 2:
21+
mycluster = sys.argv[2]
22+
23+
# Find all the links:
24+
for elm in root.getchildren():
25+
if not elm.tag.endswith("}link"):
26+
continue
27+
name = elm.get("client_id")
28+
ifacerefs = []
29+
cluster = None
30+
for elm2 in elm.getchildren():
31+
if elm2.tag.endswith("}interface_ref"):
32+
ifacename = elm2.get("client_id")
33+
ifacerefs.append(ifacename)
34+
if elm2.tag.endswith("}label") and elm2.get("name") == "cluster":
35+
cluster = elm2.text
36+
if not mycluster or not cluster or mycluster == cluster:
37+
for ifacename in ifacerefs:
38+
iface_link_map[ifacename] = name
39+
link_members[name] = ifacerefs
40+
41+
# Find all the node interfaces
42+
for elm in root.getchildren():
43+
if not elm.tag.endswith("}node"):
44+
continue
45+
name = elm.get("client_id")
46+
ifaces = {}
47+
cluster = None
48+
for elm2 in elm.getchildren():
49+
if elm2.tag.endswith("}interface"):
50+
ifacename = elm2.get("client_id")
51+
for elm3 in elm2.getchildren():
52+
if not elm3.tag.endswith("}ip"):
53+
continue
54+
if not elm3.get("type") == 'ipv4':
55+
continue
56+
addrtuple = (elm3.get("address"),elm3.get("netmask"))
57+
ifaces[ifacename] = addrtuple
58+
allifaces[ifacename] = addrtuple
59+
break
60+
if elm2.tag.endswith("}label") and elm2.get("name") == "cluster":
61+
cluster = elm2.text
62+
if not mycluster or not cluster or mycluster == cluster:
63+
for (k,v) in iteritems(ifaces):
64+
allifaces[k] = v
65+
node_ifaces[name] = ifaces
66+
67+
# Dump the nodes a la topomap
68+
print("# nodes: vname,links")
69+
for n in node_ifaces.keys():
70+
for (i,(addr,mask)) in iteritems(node_ifaces[n]):
71+
print("%s,%s:%s" % (n,iface_link_map[i],addr))
72+
73+
# Dump the links a la topomap -- but with fixed cost of 1
74+
print("# lans: vname,mask,cost")
75+
for m in link_members.keys():
76+
ifref = link_members[m][0]
77+
(ip,mask) = allifaces[ifref]
78+
print("%s,%s,1" % (m,mask))
79+
80+
sys.exit(0)

0 commit comments

Comments
 (0)