Add create sfc of build-in workflow 53/8553/1
authorfujinhua <fu.jinhua@zte.com.cn>
Thu, 24 Aug 2017 04:01:30 +0000 (12:01 +0800)
committerfujinhua <fu.jinhua@zte.com.cn>
Thu, 24 Aug 2017 04:01:30 +0000 (12:01 +0800)
Change-Id: I7eacc97e3c0c157ba9e524825c7ebd54fe939417
Issue-Id: VFC-132
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
lcm/workflows/build_in.py

index 1e4b292..03a84d0 100644 (file)
@@ -64,8 +64,8 @@ def run_ns_instantiate(input_data):
         wait_until_jobs_done(job_id, jobs)
 
         update_job(job_id, 70, "0", "Start to create SFC")
-        for i in range(sfc_count):
-            create_sfc()
+        jobs = [create_sfc(ns_inst_id, i + 1, nsd_json, sdnc_id) for i in range(sfc_count)] 
+        wait_until_jobs_done(job_id, jobs)
 
         update_job(job_id, 90, "0", "Start to post deal")
         post_deal()
@@ -123,9 +123,24 @@ def create_vnf(ns_inst_id, vnf_index, nf_param):
     logger.debug("Create VNF(%s) started.", vnf_inst_id)
     return vnf_inst_id, job_id, vnf_index - 1
 
-def create_sfc():
-    # TODO:
-    pass
+def create_sfc(ns_inst_id, fp_index, nsd_json, sdnc_id):
+    uri = "/ns/sfcs"
+    data = json.JSONEncoder().encode({
+        "nsInstanceId": ns_inst_id,
+        "context": nsd_json,
+        "fpindex": fp_index,
+        "sdnControllerId": sdnc_id
+    })
+
+    ret = restcall.req_by_msb(uri, "POST", data)
+    if ret[0] != 0:
+        logger.error("Failed to call create_sfc(%s): %s", fp_index, ret[1])
+        raise NSLCMException("Failed to call create_sfc(index is %s)" % fp_index)
+
+    sfc_inst_id = ret[1]["sfcInstId"]
+    job_id = ret[1]["jobId"]
+    logger.debug("Create SFC(%s) started.", sfc_inst_id)
+    return sfc_inst_id, job_id, fp_index - 1
 
 def post_deal():
     # TODO: