Update cp table after create resource
authorying.yunlong <ying.yunlong@zte.com.cn>
Mon, 13 Feb 2017 02:24:23 +0000 (10:24 +0800)
committerying.yunlong <ying.yunlong@zte.com.cn>
Mon, 13 Feb 2017 02:24:23 +0000 (10:24 +0800)
Change-Id: I416dacca28321ae43174437b1272178a0eb193d0
Issue-Id: GVNFM-19
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
lcm/lcm/nf/vnfs/tests/test_vnf_create.py
lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
lcm/lcm/pub/database/models.py

index a1ed126..68a7781 100644 (file)
@@ -22,7 +22,7 @@ from rest_framework import status
 from lcm.nf.vnfs.vnf_create.create_vnf_identifier import CreateVnf
 from lcm.nf.vnfs.vnf_create.inst_vnf import InstVnf
 from lcm.pub.database.models import NfInstModel, JobStatusModel, NfvoRegInfoModel, VmInstModel, NetworkInstModel, \
-    SubNetworkInstModel
+    SubNetworkInstModel, PortInstModel
 from lcm.pub.utils import restcall
 from lcm.pub.utils.jobutil import JobUtil
 
@@ -85,6 +85,8 @@ class TestNsInstantiate(TestCase):
                                         tenant='admin', insttype=0, instid='1')
         SubNetworkInstModel.objects.create(subnetworkid='1', vimid='1', resouceid='1', networkid='1',
                                            name='sub_pnet',tenant='admin', insttype=0, instid='1')
+        PortInstModel.objects.create(portid='1', networkid='1', subnetworkid='1', vimid='1', resouceid='1',
+                                     name='aaa_pnet_cp', tenant='admin', insttype=0, instid='1')
 
     def tearDown(self):
         pass
index 025a1ca..669dfb0 100644 (file)
@@ -17,7 +17,7 @@ import traceback
 from threading import Thread
 
 from lcm.pub.database.models import NfInstModel, JobStatusModel, NfvoRegInfoModel, VmInstModel, VNFCInstModel, \
-    NetworkInstModel, SubNetworkInstModel, VLInstModel
+    NetworkInstModel, SubNetworkInstModel, VLInstModel, PortInstModel, CPInstModel
 from lcm.pub.exceptions import NFLCMException
 from lcm.pub.msapi.nfvolcm import vnfd_rawdata_get, apply_grant_to_nfvo, apply_res_to_nfvo
 from lcm.pub.utils.jobutil import JobUtil
@@ -57,9 +57,16 @@ class InstVnf(Thread):
                         'virtuallinkdescid': '',
                     }
                 ],
-                'affectedcp':{
+                'affectedcp':[{
+                    'status': 'success',
+                    'portresource':{'resourceid':'1'},
+                    'cpinstanceid':'2',
+                    'cpdid':'22',
+                    'ownertype':'222',
+                    'ownerid':'2222',
+                    'virtuallinkinstanceid':'22222',
 
-                }
+                }],
 
             }
         }
@@ -146,6 +153,7 @@ class InstVnf(Thread):
     def create_res(self):
         logger.info("[NF instantiation] create resource start")
         volumns = ignore_case_get(self.data, "volumn_storages")
+        #create_vim_res(data, do_notify, do_rollback)
         #create_volumns(volumns)
         JobUtil.add_job_status(self.job_id, 35, 'Nf instancing create resource(volumn_storages) finish')
 
@@ -196,21 +204,21 @@ class InstVnf(Thread):
                 ownerid=self.nf_inst_id,
                 relatednetworkid=networkinst.networkid,
                 relatedsubnetworkid=subnetinst.subnetworkid)
-        pass
         # # for vs in vss:
-        # for cp in cps:
-        #     if 'failed' == cp['status']:
-        #         continue
-        #     port_resource = cp['portresource']
-        #     portinst = PortInstModel.objects.filter(resouceid=port_resource['resourceid']).first()
-        #     CPInstModel.objects.create(
-        #         cpinstanceid=cp['cpinstanceid'],
-        #         cpdid=cp['cpdid'],
-        #         relatedtype='2',  # port
-        #         relatedport=portinst.portid,
-        #         ownertype=cp['ownertype'],
-        #         ownerid=cp['ownerid'],
-        #         vlinstanceid=cp['virtuallinkinstanceid'])
+        for cp in cps:
+            if 'failed' == cp['status']:
+                continue
+            port_resource = cp['portresource']
+            portinst = PortInstModel.objects.filter(resouceid=port_resource['resourceid']).first()
+            ttt = portinst.portid
+            CPInstModel.objects.create(
+                cpinstanceid=cp['cpinstanceid'],
+                cpdid=cp['cpdid'],
+                relatedtype='2',
+                relatedport=portinst.portid,
+                ownertype=cp['ownertype'],
+                ownerid=cp['ownerid'],
+                vlinstanceid=cp['virtuallinkinstanceid'])
         # self.add_job(43, 'INST_DPLY_VM_PRGS')
         logger.info("[NF instantiation] confirm all vms are active end")
 
@@ -260,4 +268,8 @@ class InstVnf(Thread):
         JobUtil.add_job_status(self.job_id, 255, error_msg)
         # JobUtil.add_job_status(self.job_id, 255, 'VNF instantiation failed, detail message: %s' % error_msg, 0)
 
+    def add_job_and_update_table(self, progress, msgid, args_=None):
+        logger.info('add job, progress=%s, msgid=%s, args=%s' % (progress, msgid, args_))
+        JobUtil.add_job_status(self.job_id, 90, '')
+
 
index 8820945..2337668 100644 (file)
@@ -196,4 +196,46 @@ class VLInstModel(models.Model):
     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=50)
\ No newline at end of file
+    tenant = models.CharField(db_column='TENANT', max_length=50)
+
+class PortInstModel(models.Model):
+    class Meta:
+        db_table = 'PORTINST'
+
+    portid = models.CharField(db_column='PORTID', primary_key=True, max_length=255)
+    networkid = models.CharField(db_column='NETWORKID', max_length=255)
+    subnetworkid = models.CharField(db_column='SUBNETWORKID', max_length=255, null=True)
+    vimid = models.CharField(db_column='VIMID', max_length=255)
+    resouceid = models.CharField(db_column='RESOURCEID', max_length=255)
+    name = models.CharField(db_column='NAME', max_length=255, null=True)
+    insttype = models.IntegerField(db_column='INSTTYPE')
+    instid = models.CharField(db_column='INSTID', max_length=255)
+    cpinstanceid = models.CharField(db_column='CPINSTANCEID', max_length=255, null=True)
+    bandwidth = models.CharField(db_column='BANDWIDTH', max_length=255, null=True)
+    operationalstate = models.CharField(db_column='OPERATIONALSTATE', max_length=255, null=True)
+    ipaddress = models.CharField(db_column='IPADDRESS', max_length=255)
+    macaddress = models.CharField(db_column='MACADDRESS', max_length=255)
+    nicorder = models.CharField(db_column='NICORDER', max_length=255)
+    floatipaddress = models.CharField(db_column='FLOATIPADDRESS', max_length=255, null=True)
+    serviceipaddress = models.CharField(db_column='SERVICEIPADDRESS', max_length=255, null=True)
+    typevirtualnic = models.CharField(db_column='TYPEVIRTUALNIC', max_length=255, null=True)
+    sfcencapsulation = models.CharField(db_column='SFCENCAPSULATION', max_length=255, null=True)
+    direction = models.CharField(db_column='DIRECTION', max_length=255, null=True)
+    tenant = models.CharField(db_column='TENANT', max_length=255, null=True)
+    interfacename = models.CharField(db_column='INTERFACENAME', max_length=255, blank=True, null=True)
+    vmid = models.CharField(db_column='VMID', max_length=255, blank=True, null=True)
+
+class CPInstModel(models.Model):
+    class Meta:
+        db_table = '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)
+    vlinstanceid = models.CharField(db_column='VLINSTANCEID', 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)
\ No newline at end of file