From 725c637b3d6f4e41773b83f7977e2ba962b5b1b7 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Thu, 14 Apr 2011 12:28:17 +0200 Subject: [PATCH] get_slices is now ListSlices and supports call_id --- sfa/client/sfi.py | 2 +- sfa/managers/aggregate_manager_pl.py | 13 +++++++------ sfa/managers/aggregate_manager_vini.py | 2 +- sfa/managers/component_manager_default.py | 4 ++-- sfa/managers/component_manager_pl.py | 3 ++- sfa/managers/slice_manager_pl.py | 20 ++++++++++---------- sfa/methods/ListSlices.py | 8 ++++---- tests/testInterfaces.py | 4 ++-- 8 files changed, 29 insertions(+), 27 deletions(-) diff --git a/sfa/client/sfi.py b/sfa/client/sfi.py index a6f80f6f..01071429 100755 --- a/sfa/client/sfi.py +++ b/sfa/client/sfi.py @@ -796,7 +796,7 @@ class Sfi: delegated_cred = self.delegate_cred(user_cred, get_authority(self.authority)) creds.append(delegated_cred) server = self.get_server_from_opts(opts) - results = server.ListSlices(creds) + results = server.ListSlices(creds, unique_call_id()) display_list(results) return diff --git a/sfa/managers/aggregate_manager_pl.py b/sfa/managers/aggregate_manager_pl.py index 8a39c0b5..5355f97b 100644 --- a/sfa/managers/aggregate_manager_pl.py +++ b/sfa/managers/aggregate_manager_pl.py @@ -278,9 +278,13 @@ def DeleteSliver(api, xrn, creds, call_id): api.plshell.BindObjectToPeer(api.plauth, 'slice', slice['slice_id'], peer, slice['peer_slice_id']) return 1 -def get_slices(api, creds): +# xxx Thierry : caching at the aggregate level sounds wrong... +caching=True +#caching=False +def ListSlices(api, creds, call_id): + if Callids().already_handled(call_id): return [] # look in cache first - if api.cache: + if caching and api.cache: slices = api.cache.get('slices') if slices: return slices @@ -291,14 +295,11 @@ def get_slices(api, creds): slice_urns = [hrn_to_urn(slice_hrn, 'slice') for slice_hrn in slice_hrns] # cache the result - if api.cache: + if caching and api.cache: api.cache.add('slices', slice_urns) return slice_urns -# xxx Thierry : caching at the aggregate level sounds wrong... -caching=True -#caching=False def ListResources(api, creds, options,call_id): if Callids().already_handled(call_id): return "" # get slice's hrn from options diff --git a/sfa/managers/aggregate_manager_vini.py b/sfa/managers/aggregate_manager_vini.py index f4e919b1..92e0bdc4 100644 --- a/sfa/managers/aggregate_manager_vini.py +++ b/sfa/managers/aggregate_manager_vini.py @@ -26,7 +26,7 @@ from sfa.util.callids import Callids # VINI aggregate is almost identical to PLC aggregate for many operations, # so lets just import the methods form the PLC manager from sfa.managers.aggregate_manager_pl import ( -start_slice, stop_slice, RenewSliver, reset_slice, get_slices, get_ticket, slice_status) +start_slice, stop_slice, RenewSliver, reset_slice, ListSlices, get_ticket, slice_status) def GetVersion(api): diff --git a/sfa/managers/component_manager_default.py b/sfa/managers/component_manager_default.py index bf7b8527..b79c7cc8 100644 --- a/sfa/managers/component_manager_default.py +++ b/sfa/managers/component_manager_default.py @@ -11,8 +11,8 @@ def DeleteSliver(api, slicename, call_id): def reset_slice(api, slicename): return -def get_slices(api): - return +def ListSlices(api): + return [] def reboot(): return diff --git a/sfa/managers/component_manager_pl.py b/sfa/managers/component_manager_pl.py index 961c0354..3d4f76ac 100644 --- a/sfa/managers/component_manager_pl.py +++ b/sfa/managers/component_manager_pl.py @@ -46,7 +46,8 @@ def reset_slice(api, xrn): raise SliverDoesNotExist(slicename) api.nodemanager.ReCreate(slicename) -def get_slices(api): +# xxx outdated - this should accept a credential & call_id +def ListSlices(api): # this returns a tuple, the data we want is at index 1 xids = api.nodemanager.GetXIDs() # unfortunately the data we want is given to us as diff --git a/sfa/managers/slice_manager_pl.py b/sfa/managers/slice_manager_pl.py index 9676fe90..44b1a5e8 100644 --- a/sfa/managers/slice_manager_pl.py +++ b/sfa/managers/slice_manager_pl.py @@ -288,10 +288,15 @@ def status(api, xrn, creds): """ return 1 -def get_slices(api, creds): +# Thierry : caching at the slicemgr level makes sense to some extent +caching=True +#caching=False +def ListSlices(api, creds, call_id): + + if Callids().already_handled(call_id): return [] # look in cache first - if api.cache: + if caching and api.cache: slices = api.cache.get('slices') if slices: return slices @@ -312,7 +317,7 @@ def get_slices(api, creds): if caller_hrn == aggregate and aggregate != api.hrn: continue server = api.aggregates[aggregate] - threads.run(server.ListSlices, credential) + threads.run(server.ListSlices, credential, call_id) # combime results results = threads.get_results() @@ -321,20 +326,15 @@ def get_slices(api, creds): slices.extend(result) # cache the result - if api.cache: + if caching and api.cache: api.cache.add('slices', slices) return slices -# Thierry : caching at the slicemgr level makes sense to some extent -caching=True -#caching=False def ListResources(api, creds, options, call_id): - if Callids().already_handled(call_id): - api.logger.info("%d received ListResources with known call_id %s"%(api.interface,call_id)) - return "" + if Callids().already_handled(call_id): return "" # get slice's hrn from options xrn = options.get('geni_slice_urn', '') diff --git a/sfa/methods/ListSlices.py b/sfa/methods/ListSlices.py index 271bf9ed..78a1f6bc 100644 --- a/sfa/methods/ListSlices.py +++ b/sfa/methods/ListSlices.py @@ -17,17 +17,17 @@ class ListSlices(Method): accepts = [ Mixed(Parameter(str, "Credential string"), Parameter(type([str]), "List of credentials")), + Parameter(str, "call_id"), ] returns = Parameter(list, "List of slice names") - def call(self, creds): - valid_creds = self.api.auth.checkCredentials(creds, 'listslices') - + def call(self, creds, call_id=""): #log the call origin_hrn = Credential(string=valid_creds[0]).get_gid_caller().get_hrn() self.api.logger.info("interface: %s\tcaller-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, self.name)) + valid_creds = self.api.auth.checkCredentials(creds, 'listslices') manager = self.api.get_interface_manager() - return manager.get_slices(self.api, creds) + return manager.ListSlices(self.api, creds, call_id) diff --git a/tests/testInterfaces.py b/tests/testInterfaces.py index 4aa905a9..4d49d089 100755 --- a/tests/testInterfaces.py +++ b/tests/testInterfaces.py @@ -184,7 +184,7 @@ class AggregateTest(BasicTestCase): BasicTestCase.setUp(self) def testGetSlices(self): - self.aggregate.get_slices(self.credential) + self.aggregate.ListSlices(self.credential) def testGetResources(self): # available resources @@ -240,7 +240,7 @@ class ComponentTest(BasicTestCase): self.cm.restart_slice(self.slice_cred, self.slice['hrn']) def testGetSlices(self): - self.cm.get_slices(self.slice_cred, self.slice['hrn']) + self.cm.ListSlices(self.slice_cred, self.slice['hrn']) def testRedeemTicket(self): rspec = self.aggregate.get_resources(self.credential) -- 2.43.0