CreateSliver/create_slice also honor call_id
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 7 Apr 2011 14:18:45 +0000 (16:18 +0200)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Thu, 7 Apr 2011 14:18:45 +0000 (16:18 +0200)
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/managers/slice_manager_pl.py
sfa/methods/CreateSliver.py

index 2a36ce9..f6bb946 100644 (file)
@@ -490,7 +490,9 @@ def get_rspec(api, creds, options, call_id):
 """
 Hook called via 'sfi.py create'
 """
-def create_slice(api, xrn, creds, xml, users):
+def create_slice(api, xrn, creds, xml, users, call_id):
+    if Callids().already_handled(call_id): return False
+
     global cloud
     hrn = urn_to_hrn(xrn)[0]
 
@@ -569,7 +571,7 @@ def main():
     #theRSpec = None
     #with open(sys.argv[1]) as xml:
     #    theRSpec = xml.read()
-    #create_slice(None, 'planetcloud.pc.test', theRSpec)
+    #create_slice(None, 'planetcloud.pc.test', theRSpec, 'call-id-cloudtest')
 
     #rspec = get_rspec('euca', 'planetcloud.pc.test', 'planetcloud.pc.marcoy', 'test_euca')
     #print rspec
index 9e233ff..6f4382b 100644 (file)
@@ -271,7 +271,9 @@ def get_rspec(api, creds, options, call_id):
     return (ret_rspec)
 
 
-def create_slice(api, xrn, creds, rspec_xml, users):
+def create_slice(api, xrn, creds, rspec_xml, users, call_id):
+    if Callids().already_handled(call_id): return False
+
     global topology
     hrn = urn_to_hrn(xrn)[0]
     topology = get_interface_map()
@@ -336,7 +338,7 @@ def main():
     r = RSpec()
     rspec_xml = open(sys.argv[1]).read()
     #get_rspec(None,'foo')
-    create_slice(None, "plc.princeton.sap0", rspec_xml)
+    create_slice(None, "plc.princeton.sap0", rspec_xml, 'call-id-sap0')
     
 if __name__ == "__main__":
     main()
index 5577c28..41ced8e 100755 (executable)
@@ -111,7 +111,9 @@ def reset_slices(cred, xrn):
     if DEBUG: print "Received reset_slices call"
     return msg_aggrMgr(SFA_RESET_SLICES)
 
-def create_slice(cred, xrn, rspec):
+def create_slice(cred, xrn, rspec, call_id):
+    if Callids().already_handled(call_id): return False
+
     hrn = urn_to_hrn(xrn)[0]
     if DEBUG: print "Received create_slice call"
     slice_id = generate_slide_id(cred, hrn)
@@ -169,7 +171,7 @@ def main():
     r = RSpec()
     r.parseFile(sys.argv[1])
     rspec = r.toDict()
-    create_slice(None,'plc',rspec)
+    create_slice(None,'plc',rspec,'call-id-plc')
     
 if __name__ == "__main__":
     main()
index 3607e66..9dd2680 100644 (file)
@@ -154,11 +154,12 @@ def slice_status(api, slice_xrn, creds):
     # XX remove me
     return result
 
-def create_slice(api, slice_xrn, creds, rspec, users):
+def create_slice(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
 
     reg_objects = __get_registry_objects(slice_xrn, creds, users)
 
@@ -392,7 +393,7 @@ def main():
     f = open(sys.argv[1])
     xml = f.read()
     f.close()
-    create_slice(api, "plc.princeton.sapan", xml)
+    create_slice(api, "plc.princeton.sapan", xml, 'create_slice_sapan')
 
 if __name__ == "__main__":
     main()
index 72ff27f..f5d598f 100644 (file)
@@ -47,11 +47,13 @@ def delete_slice(api, xrn, creds):
     api.plshell.DeleteSliceFromNodes(api.plauth, slicename, slice['node_ids'])
     return 1
 
-def create_slice(api, xrn, creds, xml, users):
+def create_slice(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
+
     hrn, type = urn_to_hrn(xrn)
     peer = None
     reg_objects = __get_registry_objects(xrn, creds, users)
@@ -124,7 +126,7 @@ def main():
     f = open(sys.argv[1])
     xml = f.read()
     f.close()
-    create_slice(api, "plc.princeton.iias", xml)
+    create_slice(api, "plc.princeton.iias", xml, 'call-id-iias')
 
 if __name__ == "__main__":
     main()
index 80588f7..a851d5d 100644 (file)
@@ -54,7 +54,10 @@ def GetVersion(api):
         sm_version['peers'][api.hrn]=local_am_url.replace('localhost',sm_version['hostname'])
     return sm_version
 
-def create_slice(api, xrn, creds, rspec, users):
+def create_slice(api, xrn, creds, rspec, users, call_id):
+
+    if Callids().already_handled(call_id): return ""
+
     hrn, type = urn_to_hrn(xrn)
 
     # Validate the RSpec against PlanetLab's schema --disabled for now
@@ -93,7 +96,7 @@ def create_slice(api, xrn, creds, rspec, users):
             
         # Just send entire RSpec to each aggregate
         server = api.aggregates[aggregate]
-        threads.run(server.CreateSliver, xrn, credential, rspec, users)
+        threads.run(server.CreateSliver, xrn, credential, rspec, users, call_id)
             
     results = threads.get_results() 
     merged_rspec = merge_rspecs(results)
@@ -384,7 +387,7 @@ def main():
     r = RSpec()
     r.parseFile(sys.argv[1])
     rspec = r.toDict()
-    create_slice(None,'plc.princeton.tmacktestslice',rspec)
+    create_slice(None,'plc.princeton.tmacktestslice',rspec,'create-slice-tmacktestslice')
 
 if __name__ == "__main__":
     main()
index 0c729b9..c221af5 100644 (file)
@@ -23,11 +23,12 @@ class CreateSliver(Method):
         Mixed(Parameter(str, "Credential string"),
               Parameter(type([str]), "List of credentials")),
         Parameter(str, "RSpec"),
-        Parameter(type([]), "List of user information")
+        Parameter(type([]), "List of user information"),
+        Parameter(str, "call_id"),
         ]
     returns = Parameter(str, "Allocated RSpec")
 
-    def call(self, slice_xrn, creds, rspec, users):
+    def call(self, slice_xrn, creds, rspec, users, call_id=""):
         hrn, type = urn_to_hrn(slice_xrn)
 
         self.api.logger.info("interface: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, hrn, self.name))
@@ -43,7 +44,10 @@ class CreateSliver(Method):
             chain_name = 'INCOMING'
         elif self.api.interface in ['slicemgr']:
             chain_name = 'FORWARD-INCOMING'
+        self.api.logger.debug("CreateSliver: sfatables on chain %s"%chain_name)
         rspec = run_sfatables(chain_name, hrn, origin_hrn, rspec)
-        allocated = manager.create_slice(self.api, slice_xrn, creds, rspec, users)
-
-        return rspec 
+        # the aggregate's create_slice returns false if call_id was already handled
+        if manager.create_slice(self.api, slice_xrn, creds, rspec, users, call_id):
+            return rspec 
+        else:
+            return ""