cosmetic
[nodemanager.git] / plugins / sliverauth.py
index f22a60d..634d648 100644 (file)
@@ -1,5 +1,9 @@
 #!/usr/bin/python -tt
 # vim:set ts=4 sw=4 expandtab:
+#
+# $Id$
+# $URL$
+#
 # NodeManager plugin to empower slivers to make API calls
 
 """
@@ -24,7 +28,13 @@ def SetSliverTag(plc, slice, tagname, value):
     node_id = tools.node_id()
     slivertags=plc.GetSliceTags({"name":slice,"node_id":node_id,"tagname":tagname})
     if len(slivertags)==0:
-        slivertag_id=plc.AddSliceTag(slice,tagname,value,node_id)
+        # looks like GetSlivers reports about delegated/nm-controller slices that do *not* belong to this node
+        # and this is something that AddSliceTag does not like
+        try:
+            slivertag_id=plc.AddSliceTag(slice,tagname,value,node_id)
+        except:
+            logger.log ("SetSliverTag - CAUGHT exception for (probably delegated) slice=%(slice)s tag=%(tagname)s node_id=%(node_id)d"%locals())
+            pass
     else:
         slivertag_id=slivertags[0]['slice_tag_id']
         plc.UpdateSliceTag(slivertag_id,value)
@@ -36,10 +46,18 @@ def GetSlivers(data, config, plc):
             return
 
     if 'slivers' not in data:
-        logger.log("sliverauth: getslivers data lack's sliver information. IGNORING!")
+        logger.log_missing_data("sliverauth.GetSlivers", 'slivers')
         return
 
     for sliver in data['slivers']:
+        path = '/vservers/%s' % sliver['name']
+        if not os.path.exists(path):
+            # ignore all non-plc-instantiated slivers
+            instantiation = sliver.get('instantiation','')
+            if instantiation == 'plc-instantiated':
+                logger.log("sliverauth: plc-instantiated slice %s does not yet exist. IGNORING!" % sliver['name'])
+            continue
+        
         found_hmac = False
         for attribute in sliver['attributes']:
             name = attribute.get('tagname',attribute.get('name',''))