tag.updated = True
def tags_to_xml(self, xml, node = None):
- tag = self.get_tag("cpu_pct", node)
- if tag:
- with xml.cpu_percent:
- xml << tag.value
- tags = self.get_multi_tag("vsys", node)
- for tag in tags:
- with xml.vsys:
- xml << tag.value
+ tagtypes = self.network.getTagTypes()
+ for tt in tagtypes:
+ if tt.multi:
+ tags = self.get_multi_tag(tt.tagname, node)
+ for tag in tags:
+ if not tag.deleted: ### Debugging
+ xml << (tag.tagname, tag.value)
+ else:
+ tag = self.get_tag(tt.tagname, node)
+ if tag:
+ if not tag.deleted: ### Debugging
+ xml << (tag.tagname, tag.value)
def toxml(self, xml):
with xml.sliver_defaults:
api.plshell.DeleteSliceTag(api.plauth, self.id)
+class TagType:
+ def __init__(self, tagtype):
+ self.id = tagtype['tag_type_id']
+ self.tagname = tagtype['tagname']
+ if self.tagname in ['codemux', 'ip_addresses', 'vsys']:
+ self.multi = True
+ else:
+ self.multi = False
+
+
"""
A Network is a compound object consisting of:
* a dictionary mapping site IDs to Site objects
self.nodes = self.get_nodes(api)
self.ifaces = self.get_ifaces(api)
self.tags = self.get_slice_tags(api)
+ self.tagtypes = self.get_tag_types(api)
self.slice = None
""" Lookup site based on id or idtag value """
try:
val = self.sites[id]
except:
- raise KeyError("site ID %s not found" % id)
+ raise InvalidRSpec("site ID %s not found" % id)
return val
def getSites(self):
try:
val = self.nodes[id]
except:
- raise KeyError("node ID %s not found" % id)
+ raise InvalidRSpec("node ID %s not found" % id)
return val
def getNodes(self):
try:
val = self.ifaces[id]
except:
- raise KeyError("interface ID %s not found" % id)
+ raise InvalidRSpec("interface ID %s not found" % id)
return val
def getIfaces(self):
try:
val = self.tags[id]
except:
- raise KeyError("slicetag ID %s not found" % id)
+ raise InvalidRSpec("slicetag ID %s not found" % id)
return val
def getSliceTags(self):
tags.append(self.tags[t])
return tags
-
+ def lookupTagType(self, name):
+ val = None
+ try:
+ val = self.tagstypes[name]
+ except:
+ raise InvalidRSpec("tag %s not found" % name)
+ return val
+
+ def getTagTypes(self):
+ tags = []
+ for t in self.tagtypes:
+ tags.append(self.tagtypes[t])
+ return tags
+
def __process_attributes(self, element, node=None):
- for e in element.iterfind("./vsys"):
- self.slice.update_multi_tag("vsys", e.text, node)
-
+ # Do we need to check caller's role before update???
+ tagtypes = self.getTagTypes()
+ for tt in tagtypes:
+ if tt.multi:
+ for e in element.iterfind("./" + tt.tagname):
+ self.slice.update_multi_tag(tt.tagname, e.text, node)
+ else:
+ e = element.find("./" + tt.tagname)
+ if e is not None:
+ self.slice.update_tag(tt.tagname, e.text, node)
"""
Annotate the objects in the Network with information from the RSpec
for node in self.getNodes():
nodedict[node.idtag] = node
- slicenodes = {}
-
- tree = etree.parse(StringIO(xml))
+ try:
+ tree = etree.parse(StringIO(xml))
+ except etree.XMLSyntaxError:
+ message = str(sys.exc_info()[1])
+ raise InvalidRSpec(message)
if schema:
# Validate the incoming request against the RelaxNG schema
for sliver in rspec.iterfind("./network/site/node/sliver"):
elem = sliver.getparent()
node = nodedict[elem.get("id")]
- slicenodes[node.id] = node
node.add_sliver()
self.__process_attributes(sliver, node)
# Find slivers that specify nodeid
for sliver in rspec.iterfind("./request/sliver[@nodeid]"):
node = nodedict[sliver.get("nodeid")]
- slicenodes[node.id] = node
node.add_sliver()
self.__process_attributes(sliver, node)
def addSlice(self):
slice = self.slice
if not slice:
- raise Error("no slice associated with network")
+ raise InvalidRSpec("no slice associated with network")
for node in slice.get_nodes():
node.add_sliver()
if tag.slice_id == self.slice.id:
if not tag.updated:
tag.delete()
- #tag.write(self.api)
+ #tag.write(self.api) ### Debugging
"""
Produce XML directly from the topology specification.
"""
def get_sites(self, api):
tmp = []
- for site in api.plshell.GetSites(api.plauth):
+ for site in api.plshell.GetSites(api.plauth, {'peer_id': None}):
t = site['site_id'], Site(self, site)
tmp.append(t)
return dict(tmp)
"""
def get_nodes(self, api):
tmp = []
- for node in api.plshell.GetNodes(api.plauth):
+ for node in api.plshell.GetNodes(api.plauth, {'peer_id': None}):
t = node['node_id'], Node(self, node)
tmp.append(t)
return dict(tmp)
tmp.append(t)
return dict(tmp)
+ """
+ Create a list of tagtype obects keyed by tag name
+ """
+ def get_tag_types(self, api):
+ tmp = []
+ for tag in api.plshell.GetTagTypes(api.plauth):
+ if tag['category'] == 'slice/rspec':
+ t = tag['tagname'], TagType(tag)
+ tmp.append(t)
+ return dict(tmp)
+
"""
Return a Slice object for a single slice
"""