forked from docc-lab/dsb_k8s
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include python versions of manifest extractors.
- Loading branch information
1 parent
f30552b
commit e525cc7
Showing
2 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env python | ||
|
||
from __future__ import print_function | ||
import sys | ||
import lxml.etree | ||
|
||
f = open(sys.argv[1],'r') | ||
contents = f.read() | ||
f.close() | ||
root = lxml.etree.fromstring(contents) | ||
|
||
def convert(p,v): | ||
if v in [ "True","true" ]: | ||
v = 1 | ||
elif v in [ "False","false" ]: | ||
v = 0 | ||
elif v == None: | ||
return "" | ||
return v | ||
|
||
# Find our node and dump any labels: | ||
for elm in root.getchildren(): | ||
if elm.tag.endswith("}label"): | ||
print("%s=%s" % (elm.get("name").upper(),elm.text)) | ||
if elm.tag.endswith("}data_set"): | ||
for elm2 in elm.getchildren(): | ||
if elm2.tag.endswith("}data_item"): | ||
p = elm2.get("name") | ||
v = str(convert(p,elm2.text)) | ||
if v.find(" ") > -1: | ||
v = '"' + v + '"' | ||
print("%s=%s" % (p.split(".")[-1].upper(),v)) | ||
if elm.tag.endswith("}data_item"): | ||
p = elm.get("name") | ||
print("%s=%s" % (p.split(".")[-1].upper(),str(convert(p,elm.text)))) | ||
|
||
sys.exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/usr/bin/env python | ||
|
||
from __future__ import print_function | ||
from future.utils import iteritems | ||
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) | ||
|
||
mycluster = None | ||
if len(sys.argv) > 2: | ||
mycluster = sys.argv[2] | ||
|
||
# Find all the links: | ||
for elm in root.getchildren(): | ||
if not elm.tag.endswith("}link"): | ||
continue | ||
name = elm.get("client_id") | ||
ifacerefs = [] | ||
cluster = None | ||
for elm2 in elm.getchildren(): | ||
if elm2.tag.endswith("}interface_ref"): | ||
ifacename = elm2.get("client_id") | ||
ifacerefs.append(ifacename) | ||
if elm2.tag.endswith("}label") and elm2.get("name") == "cluster": | ||
cluster = elm2.text | ||
if not mycluster or not cluster or mycluster == cluster: | ||
for ifacename in ifacerefs: | ||
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 = {} | ||
cluster = None | ||
for elm2 in elm.getchildren(): | ||
if elm2.tag.endswith("}interface"): | ||
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 | ||
if elm2.tag.endswith("}label") and elm2.get("name") == "cluster": | ||
cluster = elm2.text | ||
if not mycluster or not cluster or mycluster == cluster: | ||
for (k,v) in iteritems(ifaces): | ||
allifaces[k] = v | ||
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 iteritems(node_ifaces[n]): | ||
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) |