From 862b43a0f7a58567d6fb2dd18e9af17ba8edd111 Mon Sep 17 00:00:00 2001 From: Tony Mack Date: Fri, 11 Jan 2013 09:43:58 -0500 Subject: [PATCH] Allocate updates the slice's expiration to the credential's expiration --- sfa/managers/aggregate_manager.py | 4 ++-- sfa/methods/Allocate.py | 6 +++++- sfa/openstack/nova_driver.py | 2 +- sfa/planetlab/pldriver.py | 4 ++-- sfa/planetlab/plslices.py | 16 +++++++++------- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/sfa/managers/aggregate_manager.py b/sfa/managers/aggregate_manager.py index 0bf5d9f2..cb8b2a6b 100644 --- a/sfa/managers/aggregate_manager.py +++ b/sfa/managers/aggregate_manager.py @@ -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): """ diff --git a/sfa/methods/Allocate.py b/sfa/methods/Allocate.py index 4c748226..4105f31f 100644 --- a/sfa/methods/Allocate.py +++ b/sfa/methods/Allocate.py @@ -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 diff --git a/sfa/openstack/nova_driver.py b/sfa/openstack/nova_driver.py index 271bfdc7..e0afd07f 100644 --- a/sfa/openstack/nova_driver.py +++ b/sfa/openstack/nova_driver.py @@ -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) diff --git a/sfa/planetlab/pldriver.py b/sfa/planetlab/pldriver.py index d12bc7a1..18a29829 100644 --- a/sfa/planetlab/pldriver.py +++ b/sfa/planetlab/pldriver.py @@ -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 diff --git a/sfa/planetlab/plslices.py b/sfa/planetlab/plslices.py index ae5847ce..ec60f36e 100644 --- a/sfa/planetlab/plslices.py +++ b/sfa/planetlab/plslices.py @@ -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 -- 2.47.0