X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fplc%2Fnetwork.py;h=1553e3ba03df0fc612ec78bf2b2734044ef83bd6;hb=9c3a451f7d42b349462d2c80f81644c5a150b2f2;hp=94f6e04a26bad9cd511f19cd17623f149a590710;hpb=4b61ad89b58f942adb9270a1faf9c7a53466d67b;p=sfa.git diff --git a/sfa/plc/network.py b/sfa/plc/network.py index 94f6e04a..1553e3ba 100644 --- a/sfa/plc/network.py +++ b/sfa/plc/network.py @@ -125,21 +125,31 @@ class Slice: def get_multi_tag(self, tagname, node = None): tags = [] for i in self.slice_tag_ids: - tag = self.network.lookupSliceTag(i) - if tag.tagname == tagname: - if not (node and node.id != tag.node_id): - tags.append(tag) + try: + tag = self.network.lookupSliceTag(i) + if tag.tagname == tagname: + if not (node and node.id != tag.node_id): + tags.append(tag) + except InvalidRSpec, e: + # As they're not needed, we ignore some tag types from + # GetSliceTags call. See Slicetag.ignore_tags + pass return tags """ Use with tags that have only one instance """ def get_tag(self, tagname, node = None): - for i in self.slice_tag_ids: - tag = self.network.lookupSliceTag(i) - if tag.tagname == tagname: - if (not node) or (node.id == tag.node_id): - return tag + try: + for i in self.slice_tag_ids: + tag = self.network.lookupSliceTag(i) + if tag.tagname == tagname: + if (not node) or (node.id == tag.node_id): + return tag + except InvalidRSpec, e: + # As they're not needed, we ignore some tag types from + # GetSliceTags call. See Slicetag.ignore_tags + pass return None def get_nodes(self): @@ -202,6 +212,8 @@ class Slice: class Slicetag: newid = -1 + filter_fields = ['slice_tag_id','slice_id','tagname','value','node_id','category','min_role_id'] + ignore_tags = ['hmac','ssh_key'] def __init__(self, tag = None): if not tag: return @@ -271,6 +283,7 @@ class Slicetag: class TagType: + ignore_tags = ['hmac','ssh_key'] def __init__(self, tagtype): self.id = tagtype['tag_type_id'] self.category = tagtype['category'] @@ -289,13 +302,13 @@ class TagType: return True -""" -A Network is a compound object consisting of: -* a dictionary mapping site IDs to Site objects -* a dictionary mapping node IDs to Node objects -* a dictionary mapping interface IDs to Iface objects -""" class Network: + """ + A Network is a compound object consisting of: + * a dictionary mapping site IDs to Site objects + * a dictionary mapping node IDs to Node objects + * a dictionary mapping interface IDs to Iface objects + """ def __init__(self, api, type = "SFA"): self.api = api self.type = type @@ -306,8 +319,8 @@ class Network: self.tagtypes = self.get_tag_types(api) self.slice = None - """ Lookup site based on id or idtag value """ def lookupSite(self, id): + """ Lookup site based on id or idtag value """ val = None if isinstance(id, basestring): id = int(id.lstrip('s')) @@ -323,8 +336,8 @@ class Network: sites.append(self.sites[s]) return sites - """ Lookup node based on id or idtag value """ def lookupNode(self, id): + """ Lookup node based on id or idtag value """ val = None if isinstance(id, basestring): id = int(id.lstrip('n')) @@ -340,8 +353,8 @@ class Network: nodes.append(self.nodes[n]) return nodes - """ Lookup iface based on id or idtag value """ def lookupIface(self, id): + """ Lookup iface based on id or idtag value """ val = None if isinstance(id, basestring): id = int(id.lstrip('i')) @@ -393,10 +406,10 @@ class Network: tags.append(self.tagtypes[t]) return tags - """ - Process the elements under or - """ def __process_attributes(self, element, node=None): + """ + Process the elements under or + """ if element is None: return @@ -411,10 +424,10 @@ class Network: 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 - """ def addRSpec(self, xml, schema=None): + """ + Annotate the objects in the Network with information from the RSpec + """ try: tree = etree.parse(StringIO(xml)) except etree.XMLSyntaxError: @@ -470,10 +483,10 @@ class Network: return - """ - Annotate the objects in the Network with information from the slice - """ def addSlice(self): + """ + Annotate the objects in the Network with information from the slice + """ slice = self.slice if not slice: raise InvalidRSpec("no slice associated with network") @@ -481,10 +494,10 @@ class Network: for node in slice.get_nodes(): node.add_sliver() - """ - Write any slice tags that have been added or modified back to the DB - """ def updateSliceTags(self): + """ + Write any slice tags that have been added or modified back to the DB + """ for tag in self.getSliceTags(): if tag.category == 'slice/rspec' and not tag.was_updated() and tag.permit_update(None, 40): # The user wants to delete this tag @@ -495,10 +508,10 @@ class Network: if tag.slice_id == self.slice.id: tag.write(self.api) - """ - Produce XML directly from the topology specification. - """ def toxml(self): + """ + Produce XML directly from the topology specification. + """ xml = XMLBuilder(format = True, tab_step = " ") with xml.RSpec(type=self.type): if self.slice: @@ -515,10 +528,10 @@ class Network: header = '\n' return header + str(xml) - """ - Create a dictionary of site objects keyed by site ID - """ def get_sites(self, api): + """ + Create a dictionary of site objects keyed by site ID + """ tmp = [] for site in api.plshell.GetSites(api.plauth, {'peer_id': None}): t = site['site_id'], Site(self, site) @@ -526,50 +539,50 @@ class Network: return dict(tmp) - """ - Create a dictionary of node objects keyed by node ID - """ def get_nodes(self, api): + """ + Create a dictionary of node objects keyed by node ID + """ tmp = [] for node in api.plshell.GetNodes(api.plauth, {'peer_id': None}): t = node['node_id'], Node(self, node) tmp.append(t) return dict(tmp) - """ - Create a dictionary of node objects keyed by node ID - """ def get_ifaces(self, api): + """ + Create a dictionary of node objects keyed by node ID + """ tmp = [] for iface in api.plshell.GetInterfaces(api.plauth): t = iface['interface_id'], Iface(self, iface) tmp.append(t) return dict(tmp) - """ - Create a dictionary of slicetag objects keyed by slice tag ID - """ def get_slice_tags(self, api): + """ + Create a dictionary of slicetag objects keyed by slice tag ID + """ tmp = [] - for tag in api.plshell.GetSliceTags(api.plauth): + for tag in api.plshell.GetSliceTags(api.plauth, {'~tagname':Slicetag.ignore_tags}, Slicetag.filter_fields): t = tag['slice_tag_id'], Slicetag(tag) tmp.append(t) return dict(tmp) - """ - Create a list of tagtype obects keyed by tag name - """ def get_tag_types(self, api): + """ + Create a list of tagtype obects keyed by tag name + """ tmp = [] - for tag in api.plshell.GetTagTypes(api.plauth): + for tag in api.plshell.GetTagTypes(api.plauth, {'~tagname':TagType.ignore_tags}): t = tag['tagname'], TagType(tag) tmp.append(t) return dict(tmp) - """ - Return a Slice object for a single slice - """ def get_slice(self, api, hrn): + """ + Return a Slice object for a single slice + """ slicename = hrn_to_pl_slicename(hrn) slice = api.plshell.GetSlices(api.plauth, [slicename]) if len(slice):