Modify models class to remove unused code 85/8885/1
authorfengyuanxing <feng.yuanxing@zte.com.cn>
Mon, 28 Aug 2017 03:41:46 +0000 (11:41 +0800)
committerfengyuanxing <feng.yuanxing@zte.com.cn>
Mon, 28 Aug 2017 03:48:36 +0000 (11:48 +0800)
Change-Id: I491407ae2add826338932042cc702a2f955db2a5
Issue-Id: VFC-152
Signed-off-by: fengyuanxing <feng.yuanxing@zte.com.cn>
catalog/packages/sdc_nf_package.py
catalog/packages/sdc_ns_package.py
catalog/pub/config/config.py
catalog/pub/database/models.py
catalog/pub/msapi/nfvolcm.py [new file with mode: 0644]

index f95baf5..57b6063 100644 (file)
@@ -21,7 +21,7 @@ import threading
 import traceback
 import sys
 
-from catalog.pub.database.models import NfPackageModel, NfInstModel
+from catalog.pub.database.models import NfPackageModel
 from catalog.pub.utils.values import ignore_case_get
 from catalog.pub.utils import fileutil
 from catalog.pub.exceptions import NSLCMException
@@ -30,6 +30,7 @@ from catalog.pub.msapi.extsys import get_vims
 from catalog.pub.utils.jobutil import JobUtil
 from catalog.pub.utils import toscaparser
 from catalog.pub.msapi import sdc
+from catalog.pub.msapi import nfvolcm
 
 logger = logging.getLogger(__name__)
 
@@ -167,12 +168,14 @@ class SdcNfPkgDeleteThread(threading.Thread):
             job_id=self.job_id)
         JobUtil.add_job_status(self.job_id, 5, "Start to delete CSAR(%s)." % self.csar_id)
 
+        '''
         if self.force_delete:
             NfInstModel.objects.filter(package_id=self.csar_id).delete()
         else:
             if NfInstModel.objects.filter(package_id=self.csar_id):
                 raise NSLCMException("NfInst by csar(%s) exists, cannot delete." % self.csar_id)
-
+        '''
+        nfvolcm.delete_ns_mock()
         JobUtil.add_job_status(self.job_id, 50, "Delete CSAR(%s) from Database." % self.csar_id)
 
         NfPackageModel.objects.filter(nfpackageid=self.csar_id).delete()
@@ -215,7 +218,8 @@ class SdcNfPackage(object):
             pkg_info["vnfVersion"] = nf_pkg[0].vnfversion
 
 
-        vnf_insts = NfInstModel.objects.filter(package_id=csar_id)
+        #vnf_insts = NfInstModel.objects.filter(package_id=csar_id)
+        vnf_insts = nfvolcm.getNfInsts()
         vnf_inst_info = [{"vnfInstanceId": vnf_inst.nfinstid,
                           "vnfInstanceName": vnf_inst.nf_name} for vnf_inst in vnf_insts]
 
index 5c42959..094e20c 100644 (file)
@@ -19,13 +19,14 @@ import traceback
 import sys
 import os
 
-from catalog.pub.database.models import NSDModel, NSInstModel, NfPackageModel
+from catalog.pub.database.models import NSDModel, NfPackageModel
 from catalog.pub.utils.values import ignore_case_get
 from catalog.pub.exceptions import NSLCMException
 from catalog.pub.msapi import sdc
 from catalog.pub.config.config import CATALOG_ROOT_PATH
 from catalog.pub.utils import toscaparser
 from catalog.pub.utils import fileutil
+from catalog.pub.msapi import nfvolcm
 
 logger = logging.getLogger(__name__)
 
@@ -129,11 +130,14 @@ class SdcNsPackage(object):
 
 
     def delete_csar(self, csar_id, force_delete):
+        '''
         if force_delete:
             NSInstModel.objects.filter(nspackage_id=csar_id).delete()
         else:
             if NSInstModel.objects.filter(nspackage_id=csar_id):
                 raise NSLCMException("CSAR(%s) is in using, cannot be deleted." % csar_id)
+        '''
+        nfvolcm.delete_ns_mock()
         NSDModel.objects.filter(id=csar_id).delete()
         return [0, "Delete CSAR(%s) successfully." % csar_id]
 
@@ -156,7 +160,8 @@ class SdcNsPackage(object):
             package_info["nsdProvider"] = csars[0].vendor
             package_info["nsdVersion"] = csars[0].version
 
-        nss = NSInstModel.objects.filter(nspackage_id=csar_id)
+        #nss = NSInstModel.objects.filter(nspackage_id=csar_id)
+        nss = nfvolcm.getNsInsts_mock()
         ns_instance_info = [{
             "nsInstanceId": ns.id, 
             "nsInstanceName": ns.name} for ns in nss]
index 0a64cb5..0f51115 100644 (file)
@@ -54,6 +54,10 @@ SDC_BASE_URL = "https://127.0.0.1:1234/api"
 SDC_USER = "admin"
 SDC_PASSWD = "admin"
 
+NFVOLCM_BASE_URL = "https://127.0.0.1:1234/api"
+NFVOLCM_USER = "admin"
+NFVOLCM_PASSWD = "admin"
+
 
 
 
index b04e65f..403189e 100644 (file)
@@ -27,27 +27,6 @@ class NSDModel(models.Model):
     nsd_model = models.TextField(db_column='NSDMODEL', max_length=65535, null=True, blank=True)
     nsd_path = models.CharField(db_column='NSDPATH', max_length=300, null=True, blank=True)
 
-
-class NSInstModel(models.Model):
-    class Meta:
-        db_table = 'NFVO_NSINST'
-
-    id = models.CharField(db_column='ID', primary_key=True, max_length=200)
-    name = models.CharField(db_column='NAME', max_length=200)
-    nspackage_id = models.CharField(db_column='NSPACKAGEID', max_length=200, null=True, blank=True)
-    nsd_id = models.CharField(db_column='NSDID', max_length=200)
-    description = models.CharField(db_column='DESCRIPTION', max_length=255, null=True, blank=True)
-    sdncontroller_id = models.CharField(db_column='SDNCONTROLLERID', max_length=200, null=True, blank=True)
-    flavour_id = models.CharField(db_column='FLAVOURID', max_length=200, null=True, blank=True)
-    ns_level = models.CharField(db_column='NSLEVEL', max_length=200, null=True, blank=True)
-    status = models.CharField(db_column='STATUS', max_length=200, null=True, blank=True)
-    nsd_model = models.TextField(db_column='NSDMODEL', max_length=20000, null=True, blank=True)
-    input_params = models.TextField(db_column='INPUTPARAMS', max_length=2000, null=True, blank=True)
-    scale_params = models.TextField(db_column='SCALEPARAMS', max_length=2000, null=True, blank=True)
-    create_time = models.CharField(db_column='CREATETIME', max_length=200, null=True, blank=True)
-    lastuptime = models.CharField(db_column='LASTUPTIME', max_length=200, null=True, blank=True)
-
-
 class NfPackageModel(models.Model):
     uuid = models.CharField(db_column='UUID', primary_key=True, max_length=255)
     nfpackageid = models.CharField(db_column='NFPACKAGEID', max_length=200)
@@ -78,160 +57,6 @@ class VnfPackageFileModel(models.Model):
         db_table = 'NFVO_NFPACKAGEFILE'
 
 
-class FPInstModel(models.Model):
-    class Meta:
-        db_table = 'NFVO_FPINST'
-
-    fpid = models.CharField(db_column='FPID', max_length=255)
-    fpinstid = models.CharField(db_column='FPINSTID', max_length=255, primary_key=True)
-    fpname = models.CharField(db_column='FPNAME', max_length=255)
-    nsinstid = models.CharField(db_column='NSINSTID', max_length=255)
-    vnffginstid = models.CharField(db_column='VNFFGINSTID', max_length=255)
-    symmetric = models.IntegerField(db_column='SYMMETRIC', null=True)
-    policyinfo = models.TextField(db_column='POLICYINFO', max_length=65535)
-    forworderpaths = models.CharField(db_column='FORWORDERPATHS', max_length=255, null=True, blank=True)
-    status = models.CharField(db_column='STATUS', max_length=255)
-    sdncontrollerid = models.CharField(db_column='SDNCONTROLLERID', max_length=255)
-    sfcid = models.CharField(db_column='SFCID', max_length=255)
-    flowclassifiers = models.CharField(db_column='FLOWCLASSIFIERS', max_length=255)
-    portpairgroups = models.TextField(db_column='PORTPAIRGROUPS', max_length=65535)
-
-
-class VNFFGInstModel(models.Model):
-    class Meta:
-        db_table = 'NFVO_VNFFGINST'
-
-    vnffgdid = models.CharField(db_column='VNFFGDID', max_length=255)
-    vnffginstid = models.CharField(db_column='VNFFGINSTID', max_length=255, primary_key=True)
-    nsinstid = models.CharField(db_column='NSINSTID', max_length=255)
-    desc = models.CharField(db_column='DESC', max_length=255, blank=True, null=True)
-    vendor = models.CharField(db_column='VENDOR', max_length=255, blank=True, null=True)
-    version = models.CharField(db_column='VERSION', max_length=255, blank=True, null=True)
-    endpointnumber = models.IntegerField(db_column='ENDPOINTNUMBER')
-    vllist = models.CharField(db_column='VLLIST', max_length=1024)
-    cplist = models.CharField(db_column='CPLIST', max_length=1024)
-    vnflist = models.CharField(db_column='VNFLIST', max_length=1024)
-    fplist = models.CharField(db_column='FPLIST', max_length=1024)
-    status = models.CharField(db_column='STATUS', max_length=255)
-
-
-class NfInstModel(models.Model):
-    class Meta:
-        db_table = 'NFVO_NFINST'
-
-    nfinstid = models.CharField(db_column='NFINSTID', max_length=200, primary_key=True)
-    mnfinstid = models.CharField(db_column='M_NFINSTID', max_length=200, blank=True, null=True)
-    nf_name = models.CharField(db_column='NFNAME', max_length=100, blank=True, null=True)
-    template_id = models.CharField(db_column='TEMPLATEID', max_length=200, blank=True, null=True)
-    vnf_id = models.CharField(db_column='VNFID', max_length=200, blank=True, null=True)
-    package_id = models.CharField(db_column='PACKAGEID', max_length=200, blank=True, null=True)
-    vnfm_inst_id = models.CharField(db_column='VNFMINSTID', max_length=200, blank=True, null=True)
-    ns_inst_id = models.CharField(db_column='NSINSTID', 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)
-    vnf_level = models.CharField(db_column='VNFLEVEL', max_length=200, blank=True, null=True)
-    location = models.CharField(db_column='LOCATION', max_length=200, blank=True, null=True)
-    max_vm = models.IntegerField(db_column='MAXVM', null=True)
-    max_cpu = models.IntegerField(db_column='MAXCPU', null=True)
-    max_ram = models.IntegerField(db_column='MAXRAM', null=True)
-    max_hd = models.IntegerField(db_column='MAXHD', null=True)
-    max_shd = models.IntegerField(db_column='MAXSHD', null=True)
-    max_net = models.IntegerField(db_column='MAXNET', null=True)
-    version = models.CharField(db_column='VERSION', max_length=255, null=True)
-    vendor = models.CharField(db_column='VENDOR', max_length=255, null=True, blank=True)
-    vnfd_model = models.TextField(db_column='VNFDMODEL', max_length=20000, blank=True, null=True)
-    input_params = models.TextField(db_column='INPUTPARAMS', max_length=2000, blank=True, null=True)
-    scale_params = models.TextField(db_column='SCALEPARAMS', max_length=2000, null=True, blank=True)
-    create_time = models.CharField(db_column='CREATETIME', max_length=200, null=True, blank=True)
-    lastuptime = models.CharField(db_column='LASTUPTIME', max_length=200, blank=True, null=True)
-    extension = models.TextField(db_column='EXTENSION', max_length=65535, blank=True, null=True)
-
-
-class VmInstModel(models.Model):
-    class Meta:
-        db_table = 'NFVO_VMINST'
-
-    vmid = models.CharField(db_column='VMID', primary_key=True, max_length=255)
-    vimid = models.CharField(db_column='VIMID', max_length=255)
-    resouceid = models.CharField(db_column='RESOURCEID', max_length=255)
-    insttype = models.IntegerField(db_column='INSTTYPE', null=True)
-    instid = models.CharField(db_column='INSTID', max_length=255, null=True)
-    vmname = models.CharField(db_column='VMNAME', max_length=255)
-    operationalstate = models.IntegerField(db_column='OPERATIONALSTATE', default=1)
-    zoneid = models.CharField(db_column='ZONEID', max_length=255, null=True)
-    tenant = models.CharField(db_column='TENANT', max_length=255, null=True)
-    hostid = models.CharField(db_column='HOSTID', max_length=255)
-    detailinfo = models.CharField(db_column='DETAILINFO', max_length=255, null=True)
-
-
-class VNFCInstModel(models.Model):
-    class Meta:
-        db_table = 'NFVO_VNFCINST'
-
-    vnfcinstanceid = models.CharField(db_column='VNFCINSTANCEID', max_length=255, primary_key=True)
-    vduid = models.CharField(db_column='VDUID', max_length=255)
-    nfinstid = models.CharField(db_column='NFINSTID', max_length=255)
-    vmid = models.CharField(db_column='VMID', max_length=255)
-    status = models.CharField(db_column='STATUS', max_length=255)
-
-
-class CPInstModel(models.Model):
-    class Meta:
-        db_table = 'NFVO_CPINST'
-
-    cpinstanceid = models.CharField(db_column='CPINSTANCEID', max_length=255, primary_key=True)
-    cpdid = models.CharField(db_column='CPDID', max_length=255)
-    cpinstancename = models.CharField(db_column='CPINSTANCENAME', max_length=255)
-    ownertype = models.IntegerField(db_column='OWNERTYPE')
-    ownerid = models.CharField(db_column='OWNERID', max_length=255)
-    relatedtype = models.IntegerField(db_column='RELATEDTYPE')
-    relatedvl = models.CharField(db_column='RELATEDVL', max_length=255, blank=True, null=True)
-    relatedcp = models.CharField(db_column='RELATEDCP', max_length=255, blank=True, null=True)
-    relatedport = models.CharField(db_column='RELATEDPORT', max_length=255, blank=True, null=True)
-    status = models.CharField(db_column='STATUS', max_length=255)
-
-
-class VLInstModel(models.Model):
-    class Meta:
-        db_table = 'NFVO_VLINST'
-
-    vlinstanceid = models.CharField(db_column='VLINSTANCEID', max_length=255, primary_key=True)
-    vldid = models.CharField(db_column='VLDID', max_length=255)
-    vlinstancename = models.CharField(db_column='VLINSTANCENAME', max_length=255, blank=True, null=True)
-    ownertype = models.IntegerField(db_column='OWNERTYPE')
-    ownerid = models.CharField(db_column='OWNERID', max_length=255)
-    relatednetworkid = models.CharField(db_column='RELATEDNETWORKID', max_length=255, blank=True, null=True)
-    relatedsubnetworkid = models.CharField(db_column='RELATEDSUBNETWORKID', max_length=255, blank=True, null=True)
-    vltype = models.IntegerField(db_column='VLTYPE', default=0)
-    vimid = models.CharField(db_column='VIMID', max_length=255)
-    tenant = models.CharField(db_column='TENANT', max_length=255)
-    status = models.CharField(db_column='STATUS', max_length=255)
-
-
-class PortInstModel(models.Model):
-    class Meta:
-        db_table = 'NFVO_PORTINST'
-
-    portid = models.CharField(db_column='PORTID', max_length=255, primary_key=True)
-    networkid = models.CharField(db_column='NETWORKID', max_length=255)
-    subnetworkid = models.CharField(db_column='SUBNETWORKID', max_length=255)
-    vimid = models.CharField(db_column='VIMID', max_length=255)
-    resourceid = models.CharField(db_column='RESOURCEID', max_length=255)
-    name = models.CharField(db_column='NAME', max_length=255)
-    instid = models.CharField(db_column='INSTID', max_length=255)
-    cpinstanceid = models.CharField(db_column='CPINSTANCEID', max_length=255)
-    bandwidth = models.CharField(db_column='BANDWIDTH', max_length=255)
-    operationalstate = models.CharField(db_column='OPERATIONALSTATE', max_length=255)
-    ipaddress = models.CharField(db_column='IPADDRESS', max_length=255)
-    macaddress = models.CharField(db_column='MACADDRESS', max_length=255)
-    floatipaddress = models.CharField(db_column='FLOATIPADDRESS', max_length=255)
-    serviceipaddress = models.CharField(db_column='SERVICEIPADDRESS', max_length=255)
-    typevirtualnic = models.CharField(db_column='TYPEVIRTUALNIC', max_length=255)
-    sfcencapsulation = models.CharField(db_column='SFCENCAPSULATION', max_length=255)
-    direction = models.CharField(db_column='DIRECTION', max_length=255)
-    tenant = models.CharField(db_column='TENANT', max_length=255)
-
-
 class JobModel(models.Model):
     class Meta:
         db_table = 'NFVO_JOB'
@@ -269,46 +94,3 @@ class JobStatusModel(models.Model):
         import json
         return json.dumps(dict([(attr, getattr(self, attr)) for attr in [f.name for f in self._meta.fields]]))
 
-
-class DefPkgMappingModel(models.Model):
-    class Meta:
-        db_table = 't_lcm_defPackage_mapping'
-
-    service_id = models.CharField(db_column='serviceId', max_length=255, primary_key=True)
-    service_def_id = models.CharField(db_column='serviceDefId', max_length=255)
-    template_id = models.CharField(db_column='templateId', max_length=255)
-    template_name = models.CharField(db_column='templateName', max_length=255)
-
-
-class InputParamMappingModel(models.Model):
-    class Meta:
-        db_table = 't_lcm_inputParam_mapping'
-
-    service_id = models.CharField(db_column='serviceId', max_length=255)
-    input_key = models.CharField(db_column='inputKey', max_length=255)
-    input_value = models.CharField(db_column='inputValue', max_length=255, null=True, blank=True)
-
-
-class ServiceBaseInfoModel(models.Model):
-    class Meta:
-        db_table = 't_lcm_servicebaseinfo'
-
-    service_id = models.CharField(db_column='serviceId', max_length=255, primary_key=True)
-    service_name = models.CharField(db_column='serviceName', max_length=255)
-    service_type = models.CharField(db_column='serviceType', max_length=20)
-    description = models.CharField(db_column='description', max_length=255, null=True, blank=True)
-    active_status = models.CharField(db_column='activeStatus', max_length=20)
-    status = models.CharField(db_column='status', max_length=20)
-    creator = models.CharField(db_column='creator', max_length=50)
-    create_time = models.BigIntegerField(db_column='createTime', max_length=20)
-
-class WFPlanModel(models.Model):
-    class Meta:
-        db_table = 'NFVO_WF_PLAN'
-
-    deployed_id = models.CharField(db_column='DEPLOYEDID', max_length=255, primary_key=True)
-    process_id = models.CharField(db_column='PROCESSID', max_length=255)
-    status = models.CharField(db_column='STATUS', max_length=255)
-    message = models.CharField(db_column='MESSAGE', max_length=1024)
-    plan_name = models.CharField(db_column='PLANNAME', max_length=255)
-
diff --git a/catalog/pub/msapi/nfvolcm.py b/catalog/pub/msapi/nfvolcm.py
new file mode 100644 (file)
index 0000000..07665bf
--- /dev/null
@@ -0,0 +1,73 @@
+# Copyright 2017 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import json
+import logging
+from catalog.pub.exceptions import CatalogException
+from catalog.pub.utils import restcall
+from catalog.pub.config.config import NFVOLCM_BASE_URL,NFVOLCM_USER,NFVOLCM_PASSWD
+
+logger = logging.getLogger(__name__)
+
+ASSETTYPE_RESOURCES = "resources"
+ASSETTYPE_SERVICES = "services"
+
+
+def call_lcm(resource, method, content=''):
+    return restcall.call_req(base_url=NFVOLCM_BASE_URL,
+        user=NFVOLCM_USER,
+        passwd=NFVOLCM_PASSWD,
+        auth_type=restcall.rest_no_auth,
+        resource=resource,
+        method=method,
+        content=content)
+
+# Mock code because the REST API from nfvolcm to delete ns instance is not implemented
+def delete_ns_mock():
+    return [0,'success']
+
+# Mock code because the REST API from nfvolcm to delete nf instance is not implemented
+def delete_nf_mock():
+    return [0,'success']
+
+def delete_ns(asset_type):
+    resource = "/nfvolcm/v1/ns/"
+    resource = resource.format(assetType=asset_type)
+    ret = call_lcm(resource, "DELETE")
+    if ret[0] != 0:
+        logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
+        raise CatalogException("Failed to query artifacts(%s) from sdc." % asset_type)
+    return json.JSONDecoder().decode(ret[1])
+
+def getNsInsts_mock():
+    return [
+        {
+            "nsInstanceId":1,
+            "nsInstanceName":"vnf1"
+        },
+        {
+            "nsInstanceId": 2,
+            "nsInstanceName": "vnf2"
+        }]
+
+def getNfInsts_mock():
+    return [
+        {
+            "vnfInstanceId":1,
+            "vnfInstanceName":"vnf1"
+        },
+        {
+            "vnfInstanceId": 2,
+            "vnfInstanceName": "vnf2"
+        }]
\ No newline at end of file