Modify vnf instantiation related stuffs. 85/59985/2
authorlaili <lai.li@zte.com.cn>
Fri, 10 Aug 2018 09:30:22 +0000 (17:30 +0800)
committerlaili <lai.li@zte.com.cn>
Sat, 11 Aug 2018 07:47:46 +0000 (15:47 +0800)
Remove NfvoRegInfo.
Fix logic errors in instantiate_vnf.py.

Change-Id: I9f2c8b28d37364be737c8b588305d41f66e2b8b9
Issue-ID: VFC-1017
Signed-off-by: laili <lai.li@zte.com.cn>
lcm/lcm/nf/biz/instantiate_vnf.py
lcm/lcm/nf/const.py
lcm/lcm/nf/serializers/ext_virtual_link_data.py
lcm/lcm/pub/database/models.py

index 87d4f40..3a9bd85 100644 (file)
@@ -19,7 +19,7 @@ import uuid
 from threading import Thread
 
 from lcm.pub.database.models import NfInstModel, VmInstModel, NetworkInstModel, \
-    SubNetworkInstModel, PortInstModel, StorageInstModel, FlavourInstModel, VNFCInstModel, NfvoRegInfoModel
+    SubNetworkInstModel, PortInstModel, StorageInstModel, FlavourInstModel, VNFCInstModel
 from lcm.pub.exceptions import NFLCMException
 from lcm.pub.msapi.gvnfmdriver import apply_grant_to_nfvo, notify_lcm_to_nfvo
 from lcm.pub.msapi.sdc_run_catalog import query_vnfpackage_by_id
@@ -65,7 +65,7 @@ class InstantiateVnf(Thread):
         self.vnfd_id = vnf_insts[0].vnfdid
         JobUtil.add_job_status(self.job_id, 10, 'Get vnf package info from catalog by csar_id')
         input_parameters = []
-        inputs = ignore_case_get(self.data['additionalParams'], "inputs")
+        inputs = ignore_case_get(self.data, "additionalParams")
         if inputs:
             if isinstance(inputs, (str, unicode)):
                 inputs = json.loads(inputs)
@@ -91,17 +91,19 @@ class InstantiateVnf(Thread):
                    status='NOT_INSTANTIATED',
                    vnfdid=self.vnfd_id,
                    localizationLanguage=ignore_case_get(self.data, 'localizationLanguage'),
-                   input_params=self.data,
+                   input_params=input_parameters,
                    vnfSoftwareVersion=vnfsoftwareversion,
                    lastuptime=now_time())
 
         logger.info("VimId = %s" % self.vim_id)
+        '''
         is_exist = NfvoRegInfoModel.objects.filter(nfvoid=self.nf_inst_id).exists()
         if not is_exist:
             NfvoRegInfoModel.objects.create(
                 nfvoid=self.nf_inst_id,
-                vnfminstid=ignore_case_get(self.data, "vnfmId"),
+                vnfminstid=ignore_case_get(self.data, "vnfmId"),
                 apiurl=self.vim_id)
+        '''
         JobUtil.add_job_status(self.job_id, 15, 'Nf instancing pre-check finish')
         logger.info("Nf instancing pre-check finish")
 
@@ -130,11 +132,14 @@ class InstantiateVnf(Thread):
             res_index += 1
 
         logger.debug("VnfInst = %s", self.nf_inst_id)
+        '''
         vnfmInfo = NfvoRegInfoModel.objects.filter(nfvoid=self.nf_inst_id)
         if len(vnfmInfo) == 0:
             raise NFLCMException('VnfInst(%s) does not exist' % self.nf_inst_id)
-        content_args['additionalParam']['vnfmid'] = vnfmInfo[0].vnfminstid
-        content_args['additionalParam']['vimid'] = vnfmInfo[0].apiurl
+        '''
+        nfInsts = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
+        content_args['additionalParam']['vnfmid'] = nfInsts[0].vnfminstid
+        content_args['additionalParam']['vimid'] = self.vim_id
         logger.info('Grant request data = %s', content_args)
 
         apply_result = apply_grant_to_nfvo(json.dumps(content_args))
@@ -206,10 +211,13 @@ class InstantiateVnf(Thread):
             'affectedCp': affected_cp
         }
 
+        '''
         vnfmInfo = NfvoRegInfoModel.objects.filter(nfvoid=self.nf_inst_id)
         if len(vnfmInfo) == 0:
             raise NFLCMException('nf_inst_id(%s) does not exist in NfvoRegInfoModel' % self.nf_inst_id)
-        content_args['VNFMID'] = vnfmInfo[0].vnfminstid
+        '''
+        nfInsts = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
+        content_args['VNFMID'] = nfInsts[0].vnfminstid
         logger.info('Notify request data = %s' % content_args)
         resp = notify_lcm_to_nfvo(json.dumps(content_args))
         logger.info('Lcm notify end, response %s' % resp)
@@ -226,12 +234,13 @@ class InstantiateVnf(Thread):
 
     def update_cps(self):
         for extlink in ignore_case_get(self.data, "extVirtualLinks"):
-            for cp in ignore_case_get(self.vnfd_info, "cps"):
-                cpdid = ignore_case_get(extlink, "cpdId")
-                if cpdid == ignore_case_get(cp, "cp_id"):
-                    cp["networkId"] = ignore_case_get(extlink, "resourceId")
-                    cp["subnetId"] = ignore_case_get(extlink, "resourceSubnetId")
-                    break
+            for ext_cp in ignore_case_get(extlink, "extCps"):
+                cpdid = ignore_case_get(ext_cp, "cpdId")
+                for cp in ignore_case_get(self.vnfd_info, "cps"):
+                    if cpdid == ignore_case_get(cp, "cp_id"):
+                        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']:
@@ -244,6 +253,17 @@ class InstantiateVnf(Thread):
                         "vimid": ignore_case_get(apply_result, "vimid"),
                         "tenant": ignore_case_get(apply_result, "tenant")}
 
+    '''
+    def get_subnet_ids(self, ext_cp):
+        subnet_ids = []
+        for cp_conf in ignore_case_get(ext_cp, "cpConfig"):
+            for cp_protocol in ignore_case_get(ext_cp, "cpProtocolData"):
+                ip_over_ethernet = ignore_case_get(cp_protocol, "ipOverEthernet")
+                for ip_address in ignore_case_get(ip_over_ethernet, "ipAddresses"):
+                    subnet_ids.append(ignore_case_get(ip_address, "subnetId"))
+        return subnet_ids
+    '''
+
 
 def volume_save(job_id, nf_inst_id, ret):
     JobUtil.add_job_status(job_id, 25, 'Create vloumns!')
index 33ba654..47097d5 100644 (file)
@@ -31,6 +31,7 @@ inst_req_data = {
             "vimConnectionId": "vimConnection_1",
             "resourceProviderId": "resourceProvider_1",
             "resourceId": "resource_1",
+            "resourceSubnetId": "resourceSubnet_1",
             "extCps": [
                 {
                     "cpdId": "cpd_1",
@@ -100,10 +101,9 @@ inst_req_data = {
     ],
     "localizationLanguage": "en_US",
     "additionalParams": {
-        # "inputs": {
+        "vimId": "vim_1",
         "key1": "test1",
-        "key2": "test2"
-        # }
+        "key2": "test2",
     }
 }
 
index 83d5012..612e00c 100644 (file)
@@ -42,6 +42,11 @@ class ExtVirtualLinkDataSerizlizer(serializers.Serializer):
         max_length=255,
         required=True,
         allow_null=False)
+    resourceSubnetId = serializers.CharField(
+        help_text="Subnet defined by the identifier of the subnet resource in the VIM.",
+        max_length=255,
+        required=True,
+        allow_null=False)
     extCps = VnfExtCpDataSerializer(
         help_text="External CPs of the VNF to be connected to this external VL.",
         many=True,
index 02993e7..e54fae2 100644 (file)
@@ -21,6 +21,7 @@ class NfInstModel(models.Model):
 
     nfinstid = models.CharField(db_column='NFINSTID', max_length=200, primary_key=True)
     nf_name = models.CharField(db_column='NFNAME', max_length=100, blank=True, null=True)  # CreateVnfRequest.vnfInstanceName
+    vnfminstid = models.CharField(max_length=255, db_column='VNFMINSTID')
     package_id = models.CharField(db_column='PACKAGEID', max_length=200, blank=True, null=True)
     status = models.CharField(db_column='STATUS', max_length=20, blank=True, null=True)
     flavour_id = models.CharField(db_column='FLAVOURID', max_length=200, blank=True, null=True)  # InstantiateVnfRequest.flavourId