X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fmanagers%2Faggregate_manager.py;h=5108c4ff5777fcf52d313022a4d9f11883f54192;hb=7bf7342cffc8e0d38694a1f013d7e77e6eaff2a7;hp=d328c1b5de49935a6a737916abad7d31cbadb07d;hpb=7a541f733e84da2111bff988aaa4cd9b55bdfa2c;p=sfa.git diff --git a/sfa/managers/aggregate_manager.py b/sfa/managers/aggregate_manager.py index d328c1b5..5108c4ff 100644 --- a/sfa/managers/aggregate_manager.py +++ b/sfa/managers/aggregate_manager.py @@ -1,9 +1,12 @@ -import soctet +import socket from sfa.rspecs.version_manager import VersionManager from sfa.util.version import version_core from sfa.util.xrn import Xrn from sfa.util.callids import Callids from sfa.util.sfalogging import logger +from sfa.util.faults import SfaInvalidArgument, InvalidRSpecVersion +from sfa.server.api_versions import ApiVersions + class AggregateManager: @@ -12,7 +15,7 @@ class AggregateManager: # essentially a union of the core version, the generic version (this code) and # whatever the driver needs to expose - def _rspec_versions(self): + def rspec_versions(self): version_manager = VersionManager() ad_rspec_versions = [] request_rspec_versions = [] @@ -22,7 +25,6 @@ class AggregateManager: if rspec_version.content_type in ['*', 'request']: request_rspec_versions.append(rspec_version.to_dict()) return { - 'testbed':self.testbed_name(), 'geni_request_rspec_versions': request_rspec_versions, 'geni_ad_rspec_versions': ad_rspec_versions, } @@ -45,49 +47,29 @@ class AggregateManager: return version_string def GetVersion(self, api, options): - xrn=Xrn(api.hrn) + xrn=Xrn(api.hrn, type='authority+am') version = version_core() + cred_types = [{'geni_type': 'geni_sfa', 'geni_version': str(i)} for i in range(4)[-2:]] + geni_api_versions = ApiVersions().get_versions() + geni_api_versions['3'] = 'http://%s:%s' % (api.config.sfa_aggregate_host, api.config.sfa_aggregate_port) version_generic = { - 'testbed': self.driver.testbed_name(), + 'testbed': api.driver.testbed_name(), 'interface':'aggregate', + 'sfa': 3, 'hrn':xrn.get_hrn(), 'urn':xrn.get_urn(), 'geni_api': 3, - 'geni_api_versions': {'3': 'http://%s:%s' % (socket.gethostname(), api.config.sfa_aggregate_port)}, + 'geni_api_versions': geni_api_versions, 'geni_single_allocation': 0, # Accept operations that act on as subset of slivers in a given state. 'geni_allocate': 'geni_many',# Multiple slivers can exist and be incrementally added, including those which connect or overlap in some way. - 'geni_best_effort': 'true', - 'geni_credential_types': [{ - 'geni_type': 'geni_sfa', - 'geni_version': 3, - }], + 'geni_credential_types': cred_types, } version.update(version_generic) - testbed_version = self.driver.aggregate_version() + version.update(self.rspec_versions()) + testbed_version = api.driver.aggregate_version() version.update(testbed_version) return version - def ListSlices(self, api, creds, options): - call_id = options.get('call_id') - if Callids().already_handled(call_id): return [] - - # look in cache first - if self.driver.cache: - slices = self.driver.cache.get('slices') - if slices: - logger.debug("%s.list_slices returns from cache" % (self.driver.__module__)) - return slices - - # call driver - slices = self.driver.list_slices(creds, options) - - # cache the result - if self.driver.cache: - logger.debug ("%s.list_slices stores value in cache" % (self.driver.__module__)) - self.driver.cache.add('slices', instance_urns) - - return self.driver.list_slices (creds, options) - def ListResources(self, api, creds, options): call_id = options.get('call_id') if Callids().already_handled(call_id): return "" @@ -99,93 +81,88 @@ class AggregateManager: # look in cache first cached_requested = options.get('cached', True) - if cached_requested and self.driver.cache and not slice_hrn: - rspec = self.driver.cache.get(version_string) + if cached_requested and api.driver.cache: + rspec = api.driver.cache.get(version_string) if rspec: - logger.debug("%s.ListResources returning cached advertisement" % (self.driver.__module__)) + logger.debug("%s.ListResources returning cached advertisement" % (api.driver.__module__)) return rspec - rspec = self.driver.list_resources (creds, version, options) - if self.driver.cache: - logger.debug("%s.ListResources stores advertisement in cache" % (self.driver.__module__)) - self.driver.cache.add(version_string, rspec) + rspec = api.driver.list_resources (rspec_version, options) + if api.driver.cache: + logger.debug("%s.ListResources stores advertisement in cache" % (api.driver.__module__)) + api.driver.cache.add(version_string, rspec) return rspec def Describe(self, api, creds, urns, options): call_id = options.get('call_id') if Callids().already_handled(call_id): return "" - # get the rspec's return format from options version_manager = VersionManager() rspec_version = version_manager.get_version(options.get('geni_rspec_version')) - return self.driver.describe(creds, urns, rspec, options) + return api.driver.describe(urns, rspec_version, options) - def SliverStatus (self, api, xrn, creds, options): + def Status (self, api, urns, creds, options): call_id = options.get('call_id') if Callids().already_handled(call_id): return {} - - xrn = Xrn(xrn,'slice') - slice_urn=xrn.get_urn() - slice_hrn=xrn.get_hrn() - return self.driver.sliver_status (slice_urn, slice_hrn) - - def CreateSliver(self, api, xrn, creds, rspec_string, users, options): + return api.driver.status (urns, options=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 api.driver.allocate(xrn, rspec_string, expiration, options) + + def Provision(self, api, xrns, creds, options): """ Create the sliver[s] (slice) at this aggregate. Verify HRN and initialize the slice record in PLC if necessary. """ call_id = options.get('call_id') if Callids().already_handled(call_id): return "" - - xrn = Xrn(xrn, 'slice') - slice_urn=xrn.get_urn() - slice_hrn=xrn.get_hrn() - return self.driver.create_sliver (slice_urn, slice_hrn, creds, rspec_string, users, options) + # make sure geni_rspec_version is specified in options + if 'geni_rspec_version' not in options: + msg = 'geni_rspec_version is required and must be set in options struct' + raise SfaInvalidArgument(msg, 'geni_rspec_version') + # make sure we support the requested rspec version + version_manager = VersionManager() + rspec_version = version_manager.get_version(options['geni_rspec_version']) + if not rspec_version: + raise InvalidRSpecVersion(options['geni_rspec_version']) + + return api.driver.provision(xrns, options) - def DeleteSliver(self, api, xrn, creds, options): + def Delete(self, api, xrns, creds, options): call_id = options.get('call_id') if Callids().already_handled(call_id): return True + return api.driver.delete(xrns, options) - xrn = Xrn(xrn, 'slice') - slice_urn=xrn.get_urn() - slice_hrn=xrn.get_hrn() - return self.driver.delete_sliver (slice_urn, slice_hrn, creds, options) - - def RenewSliver(self, api, xrn, creds, expiration_time, options): + def Renew(self, api, xrns, creds, expiration_time, options): call_id = options.get('call_id') if Callids().already_handled(call_id): return True - - xrn = Xrn(xrn, 'slice') - slice_urn=xrn.get_urn() - slice_hrn=xrn.get_hrn() - return self.driver.renew_sliver (slice_urn, slice_hrn, creds, expiration_time, options) - - ### these methods could use an options extension for at least call_id - def start_slice(self, api, xrn, creds): - xrn = Xrn(xrn) - slice_urn=xrn.get_urn() - slice_hrn=xrn.get_hrn() - return self.driver.start_slice (slice_urn, slice_hrn, creds) - - def stop_slice(self, api, xrn, creds): - xrn = Xrn(xrn) - slice_urn=xrn.get_urn() - slice_hrn=xrn.get_hrn() - return self.driver.stop_slice (slice_urn, slice_hrn, creds) - - def reset_slice(self, api, xrn): - xrn = Xrn(xrn) - slice_urn=xrn.get_urn() - slice_hrn=xrn.get_hrn() - return self.driver.reset_slice (slice_urn, slice_hrn) - - def GetTicket(self, api, xrn, creds, rspec, users, options): - - xrn = Xrn(xrn) - slice_urn=xrn.get_urn() - slice_hrn=xrn.get_hrn() - return self.driver.get_ticket (slice_urn, slice_hrn, creds, rspec, options) + # extend as long as possible + if options.get('geni_extend_alap'): + now = datetime.datetime.now() + requested = utcparse(expiration_time) + max = adjust_datetime(now, days=30) + if requested > max: + expiration_time = max + return api.driver.renew(xrns, expiration_time, options) + + def PerformOperationalAction(self, api, xrns, creds, action, options={}): + call_id = options.get('call_id') + if Callids().already_handled(call_id): return True + return api.driver.perform_operational_action(xrns, action, options) + + def Shutdown(self, api, xrn, creds, options={}): + call_id = options.get('call_id') + if Callids().already_handled(call_id): return True + return api.driver.shutdown(xrn, options) +