# Parser
###################
def get_network_elements(self):
- return self.xml.xpath('//network', self.namespaces)
+ return self.xml.xpath('//network')
def get_networks(self):
- return self.xml.xpath('//network[@name]/@name', self.namespaces)
+ return self.xml.xpath('//network[@name]/@name')
def get_node_element(self, hostname, network=None):
if network:
return None
def get_node_elements(self):
- return self.xml.xpath('//node', self.namespaces)
+ return self.xml.xpath('//node')
def get_nodes(self, network=None):
if network == None:
- nodes = self.xml.xpath('//node/hostname/text()', self.namespaces)
+ nodes = self.xml.xpath('//node/hostname/text()')
else:
- nodes = self.xml.xpath('//network[@name="%s"]//node/hostname/text()' % network, self.namespaces)
+ nodes = self.xml.xpath('//network[@name="%s"]//node/hostname/text()' % network)
return nodes
def get_nodes_with_slivers(self, network = None):
if network:
- return self.xml.xpath('//network[@name="%s"]//node[sliver]/hostname/text()' % network, self.namespaces)
+ return self.xml.xpath('//network[@name="%s"]//node[sliver]/hostname/text()' % network)
else:
- return self.xml.xpath('//node[sliver]/hostname/text()', self.namespaces)
+ return self.xml.xpath('//node[sliver]/hostname/text()')
def get_nodes_without_slivers(self, network=None):
xpath_nodes_without_slivers = '//node[not(sliver)]/hostname/text()'
xpath_nodes_without_slivers_in_network = '//network[@name="%s"]//node[not(sliver)]/hostname/text()'
if network:
- return self.xml.xpath('//network[@name="%s"]//node[not(sliver)]/hostname/text()' % network, self.namespaces)
+ return self.xml.xpath('//network[@name="%s"]//node[not(sliver)]/hostname/text()' % network)
else:
- return self.xml.xpath('//node[not(sliver)]/hostname/text()', self.namespaces)
+ return self.xml.xpath('//node[not(sliver)]/hostname/text()')
def attributes_list(self, elem):
def get_default_sliver_attributes(self, network=None):
if network:
- defaults = self.xml.xpath("//network[@name='%s']/sliver_defaults" % network, self.namespaces)
+ defaults = self.xml.xpath("//network[@name='%s']/sliver_defaults" % network)
else:
- defaults = self.xml.xpath("//network/sliver_defaults" % network, self.namespaces)
+ defaults = self.xml.xpath("//network/sliver_defaults" % network)
return self.attributes_list(defaults)
def get_sliver_attributes(self, hostname, network=None):
def get_site_nodes(self, siteid, network=None):
if network:
nodes = self.xml.xpath('//network[@name="%s"]/site[@id="%s"]/node/hostname/text()' % \
- (network, siteid), self.namespaces)
+ (network, siteid))
else:
- nodes = self.xml.xpath('//site[@id="%s"]/node/hostname/text()' % siteid, self.namespaces)
+ nodes = self.xml.xpath('//site[@id="%s"]/node/hostname/text()' % siteid)
return nodes
def get_links(self, network=None):
if network:
- links = self.xml.xpath('//network[@name="%s"]/link' % network, self.namespaces)
+ links = self.xml.xpath('//network[@name="%s"]/link' % network)
else:
links = self.xml.xpath('//link')
linklist = []
def get_vlinks(self, network=None):
vlinklist = []
if network:
- vlinks = self.xml.xpath("//network[@name='%s']//vlink" % network, self.namespaces)
+ vlinks = self.xml.xpath("//network[@name='%s']//vlink" % network)
else:
- vlinks = self.xml.xpath("//vlink", self.namespaces)
+ vlinks = self.xml.xpath("//vlink")
for vlink in vlinks:
endpoints = vlink.get("endpoints")
(end1, end2) = endpoints.split()
node_tag.set('node_id', 'n'+str(node['node_id']))
if 'hostname' in node:
hostname_tag = etree.SubElement(node_tag, 'hostname').text = node['hostname']
- for interface in node['interfaces']:
- if 'bwlimit' in node:
- bwlimit = etree.SubElement(node_tag, 'bwlimit', units='kbps').tet = str(interface['bwlimit']/1000)
-
+ if 'interfaces' in node:
+ for interface in node['interfaces']:
+ if 'bwlimit' in interface and interface['bwlimit']:
+ bwlimit = etree.SubElement(node_tag, 'bwlimit', units='kbps').tet = str(interface['bwlimit']/1000)
+ if 'tags' in node:
+ for tag in node['tags']:
+ # expose this hard wired list of tags, plus the ones that are marked 'sfa' in their category
+ if tag['tagname'] in ['fcdistro', 'arch'] or 'sfa' in tag['category'].split('/'):
+ tag_element = etree.SubElement(node_tag, tag['tagname'], value=tag['value'])
def add_interfaces(self, interfaces):
pass