CreateSliver method returns possibly altered rspec
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Sat, 9 Apr 2011 11:49:50 +0000 (13:49 +0200)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Sat, 9 Apr 2011 11:49:50 +0000 (13:49 +0200)
the PL and VINI aggregate start to use this, need to check how
useful/accurate this currently is
(the other aggregates currently return their input rspec, so no change
for them in this changeset)

sfa/managers/aggregate_manager_eucalyptus.py
sfa/managers/aggregate_manager_max.py
sfa/managers/aggregate_manager_openflow.py
sfa/managers/aggregate_manager_pl.py
sfa/managers/aggregate_manager_vini.py
sfa/methods/CreateSliver.py

index e187a56..68669bd 100644 (file)
@@ -491,7 +491,7 @@ def ListResources(api, creds, options, call_id):
 Hook called via 'sfi.py create'
 """
 def CreateSliver(api, xrn, creds, xml, users, call_id):
-    if Callids().already_handled(call_id): return False
+    if Callids().already_handled(call_id): return ""
 
     global cloud
     hrn = urn_to_hrn(xrn)[0]
@@ -499,7 +499,7 @@ def CreateSliver(api, xrn, creds, xml, users, call_id):
     conn = getEucaConnection()
     if not conn:
         print >>sys.stderr, 'Error: Cannot create a connection to Eucalyptus'
-        return False
+        return ""
 
     # Validate RSpec
     schemaXML = ET.parse(EUCALYPTUS_RSPEC_SCHEMA)
@@ -563,7 +563,9 @@ def CreateSliver(api, xrn, creds, xml, users, call_id):
                                     inst_type = instType)
             eucaInst.reserveInstance(conn, pubKeys)
 
-    return True
+    # xxx - should return altered rspec 
+    # with enough data for the client to understand what's happened
+    return xml
 
 def main():
     init_server()
index f289e7d..9f99bcf 100644 (file)
@@ -272,7 +272,7 @@ def ListResources(api, creds, options, call_id):
 
 
 def CreateSliver(api, xrn, creds, rspec_xml, users, call_id):
-    if Callids().already_handled(call_id): return False
+    if Callids().already_handled(call_id): return ""
 
     global topology
     hrn = urn_to_hrn(xrn)[0]
@@ -320,7 +320,9 @@ def CreateSliver(api, xrn, creds, rspec_xml, users, call_id):
 
     unlock_state_file()
 
-    return True
+    # xxx - should return altered rspec 
+    # with enough data for the client to understand what's happened
+    return rspec_xml
 
 def rspec_to_allocations(rspec):
     ifs = []
index 7a965dc..a31c11e 100755 (executable)
@@ -111,8 +111,9 @@ def reset_slices(cred, xrn):
     if DEBUG: print "Received reset_slices call"
     return msg_aggrMgr(SFA_RESET_SLICES)
 
+### Thierry: xxx this should ahve api as a first arg - probably outdated 
 def CreateSliver(cred, xrn, rspec, call_id):
-    if Callids().already_handled(call_id): return False
+    if Callids().already_handled(call_id): return ""
 
     hrn = urn_to_hrn(xrn)[0]
     if DEBUG: print "Received CreateSliver call"
@@ -128,14 +129,14 @@ def CreateSliver(cred, xrn, rspec, call_id):
         aggrMgr_sock.close()
 
         if DEBUG: print "----------------"
-        return 1
+        return rspec
     except socket.error, message:
         print "Socket error"
     except IOerror, message:
         print "IO error"
-    return 0
+    return ""
 
-# Thierry : this would need to handle call_id like the other AMs but is outdated...
+# Thierry : xxx this would need to handle call_id like the other AMs but is outdated...
 def ListResources(cred, xrn=None):
     hrn = urn_to_hrn(xrn)[0]
     if DEBUG: print "Received ListResources call"
index 9e0aa27..e71fc67 100644 (file)
@@ -159,11 +159,11 @@ def CreateSliver(api, slice_xrn, creds, rspec, users, call_id):
     Create the sliver[s] (slice) at this aggregate.    
     Verify HRN and initialize the slice record in PLC if necessary.
     """
-    if Callids().already_handled(call_id): return False
+    if Callids().already_handled(call_id): return ""
 
     reg_objects = __get_registry_objects(slice_xrn, creds, users)
 
-    hrn, type = urn_to_hrn(slice_xrn)
+    (hrn, type) = urn_to_hrn(slice_xrn)
     peer = None
     slices = Slices(api)
     peer = slices.get_peer(hrn)
@@ -205,9 +205,8 @@ def CreateSliver(api, slice_xrn, creds, rspec, users, call_id):
             api.plshell.BindObjectToPeer(api.plauth, 'slice', slice.id, peer, 
                                          slice.peer_id)
 
-    # print network.toxml()
-
-    return True
+    # xxx - check this holds enough data for the client to understand what's happened
+    return network.toxml()
 
 
 def renew_slice(api, xrn, creds, expiration_time):
index b1a7044..40ed258 100644 (file)
@@ -52,7 +52,7 @@ def CreateSliver(api, xrn, creds, xml, users, call_id):
     Verify HRN and initialize the slice record in PLC if necessary.
     """
 
-    if Callids().already_handled(call_id): return False
+    if Callids().already_handled(call_id): return ""
 
     hrn, type = urn_to_hrn(xrn)
     peer = None
@@ -87,9 +87,8 @@ def CreateSliver(api, xrn, creds, xml, users, call_id):
     api.plshell.DeleteSliceFromNodes(api.plauth, slice.name, deleted_nodes)
     network.updateSliceTags()
 
-    # print network.toxml()
-
-    return True
+    # xxx - check this holds enough data for the client to understand what's happened
+    return network.toxml()
 
 def ListResources(api, creds, options,call_id):
     if Callids().already_handled(call_id): return ""
index 96b535d..e62e6f4 100644 (file)
@@ -46,8 +46,5 @@ class CreateSliver(Method):
             chain_name = 'FORWARD-INCOMING'
         self.api.logger.debug("CreateSliver: sfatables on chain %s"%chain_name)
         rspec = run_sfatables(chain_name, hrn, origin_hrn, rspec)
-        # the aggregate's CreateSliver returns false if call_id was already handled
-        if manager.CreateSliver(self.api, slice_xrn, creds, rspec, users, call_id):
-            return rspec 
-        else:
-            return ""
+
+        return manager.CreateSliver(self.api, slice_xrn, creds, rspec, users, call_id)