Implementation VNF instantiation interface
authorying.yunlong <ying.yunlong@zte.com.cn>
Wed, 8 Feb 2017 05:34:56 +0000 (13:34 +0800)
committerying.yunlong <ying.yunlong@zte.com.cn>
Wed, 8 Feb 2017 05:34:56 +0000 (13:34 +0800)
Change-Id: Ie9150755373fc3a80e9a3c25a1cbb6de0a7597e7
Issue-Id:GVNFM-16
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
lcm/lcm/nf/vnfs/tests/test_vnf_create.py
lcm/lcm/nf/vnfs/urls.py
lcm/lcm/nf/vnfs/views.py
lcm/lcm/pub/database/models.py

index 13e579f..c514e10 100644 (file)
@@ -38,3 +38,53 @@ class TestNsInstantiate(TestCase):
         self.failUnlessEqual(status.HTTP_201_CREATED, response.status_code)
         context = json.loads(response.content)
         self.assertTrue(VnfInstModel.objects.filter(id=context['vnfInstanceId']).exists())
+
+    def test_instantiate_vnf(self):
+        data = {
+            "flavourId": "flavour_1",
+            "instantiationLevelId": "instantiationLevel_1",
+            "extVirtualLinks": [
+                {
+                    "vlInstanceId": "1",
+                    "vim": {
+                        "vimInfoId": "1",
+                        "vimId": "1",
+                        "interfaceInfo": {
+                            "vimType": "vim",
+                            "apiVersion": "v2",
+                            "protocolType": "http"
+                        },
+                        "accessInfo": {
+                            "tenant": "tenant_vCPE",
+                            "username": "vCPE",
+                            "password": "vCPE_321"
+                        },
+                        "interfaceEndpoint": "http://10.43.21.105:80/"
+                    },
+                    "resourceId": "1246",
+                    "extCps": [
+                        {
+                            "cpdId": "11",
+                            "addresses": [
+                                {
+                                    "addressType": "MAC",
+                                    "l2AddressData": "00:f3:43:20:a2:a3"
+                                },
+                                {
+                                    "addressType": "IP",
+                                    "l3AddressData": {
+                                        "iPAddressType": "IPv4",
+                                        "iPAddress": "192.168.104.2"
+                                    }
+                                }
+                            ],
+                            "numDynamicAddresses": 0
+                        }
+                    ]
+                }
+            ],
+            "localizationLanguage": "en_US",
+            "additionalParams": {}
+        }
+        response = self.client.post("/gvnfmapi/lcm/v1/vnf_instances/12/instantiate", data=data, format='json')
+        self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
index 16b7fd8..1afc60e 100644 (file)
 from django.conf.urls import patterns, url
 from rest_framework.urlpatterns import format_suffix_patterns
 
-from lcm.nf.vnfs.views import CreateVnfIdentifier
+from lcm.nf.vnfs.views import CreateVnfIdentifier, InstantiateVnf
 
 urlpatterns = patterns('',
                        url(r'^gvnfmapi/lcm/v1/vnf_instances$', CreateVnfIdentifier.as_view()),
+                       url(r'^gvnfmapi/lcm/v1/vnf_instances/(?P<instanceId>[0-9a-zA-Z_-]+)/instantiate$',
+                           InstantiateVnf.as_view()),
                        )
 
 urlpatterns = format_suffix_patterns(urlpatterns)
\ No newline at end of file
index 02f35cb..b584670 100644 (file)
@@ -20,6 +20,7 @@ from rest_framework.response import Response
 from rest_framework.views import APIView
 
 from lcm.pub.database.models import VnfInstModel
+from lcm.pub.utils.jobutil import JobUtil
 from lcm.pub.utils.timeutil import now_time
 from lcm.pub.utils.values import ignore_case_get
 
@@ -39,4 +40,21 @@ class CreateVnfIdentifier(APIView):
         logger.debug('id is [%s],name is [%s],vnfd_id is [%s],description is [%s],create_time is [%s],lastuptime is [%s],' %
                      (vnf_inst.id, vnf_inst.name, vnf_inst.vnfd_id, vnf_inst.description, vnf_inst.create_time, vnf_inst.lastuptime))
         rsp = {"vnfInstanceId": self.nf_inst_id}
-        return Response(data=rsp, status=status.HTTP_201_CREATED)
\ No newline at end of file
+        return Response(data=rsp, status=status.HTTP_201_CREATED)
+
+
+class InstantiateVnf(APIView):
+    def post(self, request, instanceId):
+        logger.debug("InstantiateVnf--post::> %s" % request.data)
+        data = {'flavourId': ignore_case_get(request.data, 'flavourId'),
+                'instantiationLevelId': ignore_case_get(request.data, 'instantiationLevelId'),
+                'extVirtualLinks': ignore_case_get(request.data, 'extVirtualLinks'),
+                'localizationLanguage': ignore_case_get(request.data, 'localizationLanguage'),
+                'additionalParams': ignore_case_get(request.data, 'additionalParams')}
+        nf_inst_id = instanceId
+        job_id = JobUtil.create_job('NF', 'CREATE', nf_inst_id)
+        JobUtil.add_job_status(job_id, 0, "INST_VNF_READY")
+
+        # CreateVnfs(data, nf_inst_id, job_id).start()
+        rsp = {"jobId": job_id}
+        return Response(data=rsp, status=status.HTTP_202_ACCEPTED)
\ No newline at end of file
index 200387b..898bc53 100644 (file)
@@ -26,4 +26,42 @@ class VnfInstModel(models.Model):
     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 JobModel(models.Model):
+    class Meta:
+        db_table = 'JOB'
+
+    _database = 'job'
+
+    jobid = models.CharField(db_column='JOBID', primary_key=True, max_length=255)
+    jobtype = models.CharField(db_column='JOBTYPE', max_length=255)
+    jobaction = models.CharField(db_column='JOBACTION', max_length=255)
+    resid = models.CharField(db_column='RESID', max_length=255)
+    status = models.IntegerField(db_column='STATUS', null=True, blank=True)
+    starttime = models.CharField(db_column='STARTTIME', max_length=255, null=True, blank=True)
+    endtime = models.CharField(db_column='ENDTIME', max_length=255, null=True, blank=True)
+    progress = models.IntegerField(db_column='PROGRESS', null=True, blank=True)
+    user = models.CharField(db_column='USER', max_length=255, null=True, blank=True)
+    parentjobid = models.CharField(db_column='PARENTJOBID', max_length=255, null=True, blank=True)
+    resname = models.CharField(db_column='RESNAME', max_length=255, null=True, blank=True)
+
+    def toJSON(self):
+        import json
+        return json.dumps(dict([(attr, getattr(self, attr)) for attr in [f.name for f in self._meta.fields]]))
+
+class JobStatusModel(models.Model):
+    class Meta:
+        db_table = 'JOB_STATUS'
+
+    _database = 'job'
+
+    indexid = models.IntegerField(db_column='INDEXID')
+    jobid = models.CharField(db_column='JOBID', max_length=255)
+    status = models.CharField(db_column='STATUS', max_length=255)
+    progress = models.IntegerField(db_column='PROGRESS', null=True, blank=True)
+    descp = models.CharField(db_column='DESCP', max_length=1024)
+    errcode = models.CharField(db_column='ERRCODE', max_length=255, null=True, blank=True)
+    addtime = models.CharField(db_column='ADDTIME', max_length=255, null=True, blank=True)
 
+    def toJSON(self):
+        import json
+        return json.dumps(dict([(attr, getattr(self, attr)) for attr in [f.name for f in self._meta.fields]]))