Fix "permission denied to modify tag" error
[sfa.git] / sfa / plc / network.py
index 9650e4c..d8f0c1d 100644 (file)
@@ -148,8 +148,8 @@ class Slice:
     Use with tags that have only one instance
     """
     def get_tag(self, tagname, node = None):
-        try: 
-            for i in self.slice_tag_ids: 
+        for i in self.slice_tag_ids:
+            try:
                 tag = self.network.lookupSliceTag(i) 
                 if tag.tagname == tagname: 
                     if node:
@@ -157,10 +157,10 @@ class Slice:
                             return tag
                     elif not 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 
+            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):
@@ -183,10 +183,14 @@ class Slice:
     
     # Update a slice tag if it exists, else add it             
     def update_tag(self, tagname, value, node = None, role = "user"):
+        tag = self.get_tag(tagname, node)
+        if tag and tag.value == value:
+            return tag
+
         tt = self.network.lookupTagType(tagname)
         if not tt.permit_update(role):
             raise InvalidRSpec("permission denied to modify '%s' tag" % tagname)
-        tag = self.get_tag(tagname, node)
+
         if tag:
             tag.change(value)
         else: