Allocate updates the slice's expiration to the credential's expiration
authorTony Mack <tmack@paris.CS.Princeton.EDU>
Fri, 11 Jan 2013 14:43:58 +0000 (09:43 -0500)
committerTony Mack <tmack@paris.CS.Princeton.EDU>
Fri, 11 Jan 2013 14:43:58 +0000 (09:43 -0500)
sfa/managers/aggregate_manager.py
sfa/methods/Allocate.py
sfa/openstack/nova_driver.py
sfa/planetlab/pldriver.py
sfa/planetlab/plslices.py

index 0bf5d9f..cb8b2a6 100644 (file)
@@ -104,14 +104,14 @@ class AggregateManager:
         return self.driver.status (urns, options=options)
    
 
-    def Allocate(self, api, xrn, creds, rspec_string, options):
+    def Allocate(self, api, xrn, creds, rspec_string, expiration, options):
         """
         Allocate resources as described in a request RSpec argument 
         to a slice with the named URN.
         """
         call_id = options.get('call_id')
         if Callids().already_handled(call_id): return ""
-        return self.driver.allocate(xrn, rspec_string, options)
+        return self.driver.allocate(xrn, rspec_string, expiration, options)
  
     def Provision(self, api, xrns, creds, options):
         """
index 4c74822..4105f31 100644 (file)
@@ -1,4 +1,5 @@
 from sfa.util.faults import SfaInvalidArgument, InvalidRSpec, SfatablesRejected
+from sfa.util.sfatime import datetime_to_string 
 from sfa.util.xrn import Xrn
 from sfa.util.method import Method
 from sfa.util.sfatablesRuntime import run_sfatables
@@ -39,6 +40,9 @@ class Allocate(Method):
 
         # Find the valid credentials
         valid_creds = self.api.auth.checkCredentials(creds, 'createsliver', xrn.get_hrn())
+        # use the expiration from the first valid credential to determine when 
+        # the slivers should expire.
+        expiration = datetime_to_string(Credential(cred=valid_creds[0]).expiration)
         
         # make sure request is not empty
         slivers = RSpec(rspec).version.get_nodes_with_slivers()
@@ -58,5 +62,5 @@ class Allocate(Method):
         if not slivers:
             raise SfatablesRejected(slice_xrn)
 
-        result = self.api.manager.Allocate(self.api, xrn.get_urn(), creds, rspec, options)
+        result = self.api.manager.Allocate(self.api, xrn.get_urn(), creds, rspec, expiration, options)
         return result
index 271bfdc..e0afd07 100644 (file)
@@ -371,7 +371,7 @@ class NovaDriver(Driver):
                   'geni_slivers': desc['geni_slivers']}
         return status
 
-    def allocate (self, urn, rspec_string, options={}):
+    def allocate (self, urn, rspec_string, expiration, options={}):
         xrn = Xrn(urn) 
         aggregate = OSAggregate(self)
 
index d12bc7a..18a2982 100644 (file)
@@ -619,7 +619,7 @@ class PlDriver (Driver):
                   'geni_slivers': desc['geni_slivers']}
         return status
 
-    def allocate (self, urn, rspec_string, options={}):
+    def allocate (self, urn, rspec_string, expiration, options={}):
         xrn = Xrn(urn)
         aggregate = PlAggregate(self)
         slices = PlSlices(self)
@@ -637,7 +637,7 @@ class PlDriver (Driver):
         # ensure site record exists
         site = slices.verify_site(xrn.hrn, slice_record, peer, sfa_peer, options=options)
         # ensure slice record exists
-        slice = slices.verify_slice(xrn.hrn, slice_record, peer, sfa_peer, options=options)
+        slice = slices.verify_slice(xrn.hrn, slice_record, peer, sfa_peer, expiration=expiration, options=options)
         # ensure person records exists
         persons = slices.verify_persons(xrn.hrn, slice, users, peer, sfa_peer, options=options)
         # ensure slice attributes exists
index ae5847c..ec60f36 100644 (file)
@@ -372,11 +372,12 @@ class PlSlices:
         
         return site        
 
-    def verify_slice(self, slice_hrn, slice_record, peer, sfa_peer, options={}):
+    def verify_slice(self, slice_hrn, slice_record, peer, sfa_peer, expiration, options={}):
         slicename = hrn_to_pl_slicename(slice_hrn)
         parts = slicename.split("_")
         login_base = parts[0]
         slices = self.driver.shell.GetSlices([slicename]) 
+        expires = int(datetime_to_epoch(utcparse(expiration)))
         if not slices:
             slice = {'name': slicename,
                      'url': 'No Url', 
@@ -386,18 +387,19 @@ class PlSlices:
             slice['node_ids'] = []
             slice['person_ids'] = []
             if peer and slice_record:
-                slice['peer_slice_id'] = slice_record.get('slice_id', None) 
+                slice['peer_slice_id'] = slice_record.get('slice_id', None)
+            # set the expiration
+            self.driver.shell.UpdateSlice(slice['slice_id'], {'expires': expires}) 
         else:
             slice = slices[0]
             if peer and slice_record:
                 slice['peer_slice_id'] = slice_record.get('slice_id', None)
                 # unbind from peer so we can modify if necessary. Will bind back later
                 self.driver.shell.UnBindObjectFromPeer('slice', slice['slice_id'], peer['shortname'])
-               #Update existing record (e.g. expires field) it with the latest info.
-            if slice_record and slice_record.get('expires'):
-                requested_expires = int(datetime_to_epoch(utcparse(slice_record['expires'])))
-                if requested_expires and slice['expires'] != requested_expires:
-                    self.driver.shell.UpdateSlice( slice['slice_id'], {'expires' : requested_expires})
+            
+               #Update expiration if necessary
+            if slice['expires'] != expires:
+                self.driver.shell.UpdateSlice( slice['slice_id'], {'expires' : expires})
        
         return slice