expose leases to nodes
[plcapi.git] / PLC / Methods / GetSlivers.py
index 08196b0..25cdbca 100644 (file)
@@ -18,8 +18,12 @@ from PLC.Roles import Roles
 from PLC.Keys import Key, Keys
 from PLC.SliceTags import SliceTag, SliceTags
 from PLC.InitScripts import InitScript, InitScripts
+from PLC.Leases import Lease, Leases
+from PLC.Timestamp import Duration
 from PLC.Methods.GetSliceFamily import GetSliceFamily
 
+from PLC.Accessors.Accessors_standard import *
+
 # XXX used to check if slice expiration time is sane
 MAXINT =  2L**31-1
 
@@ -166,7 +170,15 @@ class GetSlivers(Method):
                 'tagname': SliceTag.fields['tagname'],
                 'value': SliceTag.fields['value']
             }]
-        }]
+        }],
+        'xmpp': {'server':Parameter(str,"hostname for the XMPP server"),
+                 'user':Parameter(str,"username for the XMPP server"),
+                 'password':Parameter(str,"username for the XMPP server"),
+                 },
+        'leases': [  { 'slice_id' : Lease.fields['slice_id'],
+                       't_from' : Lease.fields['t_from'],
+                       't_until' : Lease.fields['t_until'],
+                       }],
     }
 
     def call(self, auth, node_id_or_hostname = None):
@@ -277,8 +289,30 @@ class GetSlivers(Method):
         personsitekeys=get_all_admin_keys(self.api)
         accounts.append({'name':'root','keys':personsitekeys})
 
+        hrn = GetNodeHrn(self.api).call(auth,node['node_id'])
+
+        # XMPP config for omf federation
+        try:
+            if not self.api.config.PLC_OMF_ENABLED:
+                raise Exception,"OMF disabled"
+            xmpp={'server':self.api.config.PLC_OMF_XMPP_SERVER,
+                  'user':self.api.config.PLC_OMF_XMPP_USER,
+                  'password':self.api.config.PLC_OMF_XMPP_PASSWORD,
+                  }
+        except:
+            xmpp={'server':None,'user':None,'password':None}
+
        node.update_last_contact()
 
+        # expose leases
+        lease_exposed_fields = [ 'slice_id', 't_from', 't_until', ]
+        leases=None
+        if node['node_type'] == 'reservable':
+            # expose the leases for the next 12 hours
+            leases = [ dict ( [ (k,l[k]) for k in lease_exposed_fields ] ) 
+                       for l in Leases (self.api, {'node_id':node['node_id'],
+                                                   'clip': (timestamp, timestamp+12*Duration.HOUR)}) ]
+
         return {
             'timestamp': timestamp,
             'node_id': node['node_id'],
@@ -288,5 +322,8 @@ class GetSlivers(Method):
             'conf_files': conf_files.values(),
            'initscripts': initscripts,
             'slivers': slivers,
-            'accounts': accounts
+            'accounts': accounts,
+            'xmpp':xmpp,
+            'hrn':hrn,
+            'leases':leases,
             }