Merge branch 'master' of ssh://git.planet-lab.org/git/sfa
[sfa.git] / sfa / plc / network.py
index d1345bc..1553e3b 100644 (file)
@@ -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']
@@ -551,7 +564,7 @@ class Network:
         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)
@@ -561,7 +574,7 @@ class Network:
         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)