Refactor vfc-vnflcm grant update location 95/42395/1
authorying.yunlong <ying.yunlong@zte.com.cn>
Thu, 12 Apr 2018 03:55:43 +0000 (11:55 +0800)
committerying.yunlong <ying.yunlong@zte.com.cn>
Thu, 12 Apr 2018 03:55:43 +0000 (11:55 +0800)
Change-Id: I5b6ea39a315b245d2f4f4c0509fb854a797163d2
Issue-ID: VFC-873
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
lcm/lcm/nf/vnf_create/inst_vnf.py

index 707e105..3c102bd 100644 (file)
@@ -140,25 +140,9 @@ class InstVnf(Thread):
         content_args['additionalParam']['vnfmid'] = vnfmInfo[0].vnfminstid
         content_args['additionalParam']['vimid'] = vnfmInfo[0].apiurl
         logger.info('Grant request data = %s', content_args)
-        apply_result = apply_grant_to_nfvo(json.dumps(content_args))
-
-        for vdu in ignore_case_get(self.vnfd_info, "vdus"):
-            if "location_info" in vdu["properties"]:
-                vdu["properties"]["location_info"]["vimid"] = ignore_case_get(apply_result, "vimid")
-                vdu["properties"]["location_info"]["tenant"] = ignore_case_get(apply_result, "tenant")
-            else:
-                vdu["properties"]["location_info"] = {
-                    "vimid": ignore_case_get(apply_result, "vimid"),
-                    "tenant": ignore_case_get(apply_result, "tenant")}
 
-        for vl in ignore_case_get(self.vnfd_info, "vls"):
-            if "location_info" in vl["properties"]:
-                vl["properties"]["location_info"]["vimid"] = ignore_case_get(apply_result, "vimid")
-                vl["properties"]["location_info"]["tenant"] = ignore_case_get(apply_result, "tenant")
-            else:
-                vl["properties"]["location_info"] = {
-                    "vimid": ignore_case_get(apply_result, "vimid"),
-                    "tenant": ignore_case_get(apply_result, "tenant")}
+        apply_result = apply_grant_to_nfvo(json.dumps(content_args))
+        self.set_location(apply_result)
 
         logger.info('VnfdInfo = %s' % self.vnfd_info)
         NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(status='INSTANTIATED', lastuptime=now_time())
@@ -369,3 +353,14 @@ class InstVnf(Thread):
                     cp["networkId"] = ignore_case_get(extlink, "resourceId")
                     cp["subnetId"] = ignore_case_get(extlink, "resourceSubnetId")
                     break
+
+    def set_location(self, apply_result):
+        for resource_type in ['vdus', 'vls']:
+            for resource in ignore_case_get(self.vnfd_info, resource_type):
+                if "location_info" in resource["properties"]:
+                    resource["properties"]["location_info"]["vimid"] = ignore_case_get(apply_result, "vimid")
+                    resource["properties"]["location_info"]["tenant"] = ignore_case_get(apply_result, "tenant")
+                else:
+                    resource["properties"]["location_info"] = {
+                        "vimid": ignore_case_get(apply_result, "vimid"),
+                        "tenant": ignore_case_get(apply_result, "tenant")}