summaryrefslogtreecommitdiffstats
path: root/lcm
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2017-02-08 13:34:56 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2017-02-08 13:34:56 +0800
commit749c0cde0decf866fc3ec7ab6c66f009432e36f2 (patch)
treeebad2ffeb5b38f3be38003d707c6761d340e4bb9 /lcm
parent1f2b48f4362e59e9c364b811906c86b77608b737 (diff)
Implementation VNF instantiation interface
Change-Id: Ie9150755373fc3a80e9a3c25a1cbb6de0a7597e7 Issue-Id:GVNFM-16 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'lcm')
-rw-r--r--lcm/lcm/nf/vnfs/tests/test_vnf_create.py50
-rw-r--r--lcm/lcm/nf/vnfs/urls.py4
-rw-r--r--lcm/lcm/nf/vnfs/views.py20
-rw-r--r--lcm/lcm/pub/database/models.py38
4 files changed, 110 insertions, 2 deletions
diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
index 13e579fe..c514e102 100644
--- a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
+++ b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
@@ -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)
diff --git a/lcm/lcm/nf/vnfs/urls.py b/lcm/lcm/nf/vnfs/urls.py
index 16b7fd89..1afc60eb 100644
--- a/lcm/lcm/nf/vnfs/urls.py
+++ b/lcm/lcm/nf/vnfs/urls.py
@@ -15,10 +15,12 @@
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
diff --git a/lcm/lcm/nf/vnfs/views.py b/lcm/lcm/nf/vnfs/views.py
index 02f35cb2..b5846709 100644
--- a/lcm/lcm/nf/vnfs/views.py
+++ b/lcm/lcm/nf/vnfs/views.py
@@ -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
diff --git a/lcm/lcm/pub/database/models.py b/lcm/lcm/pub/database/models.py
index 200387b7..898bc53b 100644
--- a/lcm/lcm/pub/database/models.py
+++ b/lcm/lcm/pub/database/models.py
@@ -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]]))