get_slices is now ListSlices and supports call_id
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 14 Apr 2011 10:28:17 +0000 (12:28 +0200)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 14 Apr 2011 10:28:17 +0000 (12:28 +0200)
sfa/client/sfi.py
sfa/managers/aggregate_manager_pl.py
sfa/managers/aggregate_manager_vini.py
sfa/managers/component_manager_default.py
sfa/managers/component_manager_pl.py
sfa/managers/slice_manager_pl.py
sfa/methods/ListSlices.py
tests/testInterfaces.py

index a6f80f6..0107142 100755 (executable)
@@ -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
     
index 8a39c0b..5355f97 100644 (file)
@@ -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
index f4e919b..92e0bdc 100644 (file)
@@ -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):
index bf7b852..b79c7cc 100644 (file)
@@ -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
index 961c035..3d4f76a 100644 (file)
@@ -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 
index 9676fe9..44b1a5e 100644 (file)
@@ -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', '')
index 271bf9e..78a1f6b 100644 (file)
@@ -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)
  
index 4aa905a..4d49d08 100755 (executable)
@@ -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)