summaryrefslogtreecommitdiffstats
path: root/lcm
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2017-02-11 15:11:30 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2017-02-11 15:11:30 +0800
commitc924900b1293c84e6565fc59258eb2eecf05e5b0 (patch)
tree19a127581984604e392b2652d555400898e8e7e6 /lcm
parent5e4748fe92313710820ff14f7fbc031538e90908 (diff)
VNF Deployment
Change-Id: I5a4c4510f020252578f97b1d191b4ba13eac4e3a Issue-Id: GVNFM-1 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.py7
-rw-r--r--lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py116
-rw-r--r--lcm/lcm/pub/database/models.py29
3 files changed, 128 insertions, 24 deletions
diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
index 00e3aa1d..f4d3a5ed 100644
--- a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
+++ b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
@@ -21,7 +21,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
+from lcm.pub.database.models import NfInstModel, JobStatusModel, NfvoRegInfoModel, VmInstModel
from lcm.pub.utils import restcall
from lcm.pub.utils.jobutil import JobUtil
@@ -76,7 +76,10 @@ inst_req_data = {
class TestNsInstantiate(TestCase):
def setUp(self):
self.client = Client()
- self.nsd_id = str(uuid.uuid4())
+ VmInstModel.objects.create(vmid="1", vimid="1", resouceid="11", insttype=0, instid="1", vmname="test_01",
+ operationalstate=1)
+ VmInstModel.objects.create(vmid="2", vimid="2", resouceid="22", insttype=0, instid="2", vmname="test_02",
+ operationalstate=1)
def tearDown(self):
pass
diff --git a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
index 601ec6b4..289eadd5 100644
--- a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
+++ b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
@@ -16,7 +16,7 @@ import logging
import traceback
from threading import Thread
-from lcm.pub.database.models import NfInstModel, JobStatusModel, NfvoRegInfoModel
+from lcm.pub.database.models import NfInstModel, JobStatusModel, NfvoRegInfoModel, VmInstModel, VNFCInstModel
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
@@ -34,13 +34,42 @@ class InstVnf(Thread):
self.job_id = job_id
self.nfvo_inst_id = ''
self.vnfm_inst_id = ''
+ self.create_res_result = {
+ 'jobid': 'res_001',
+ 'resourceResult': [{'name': 'vm01'}, {'name': 'vm02'}],
+ 'resource_result':{
+ 'affectedvnfc':[
+ {
+ 'status':'success',
+ 'vnfcinstanceid':'1',
+ 'computeresource':{'resourceid':'11'},
+ 'vduid':'111',
+ 'vdutype':'1111'
+ },
+ {
+ 'status': 'success',
+ 'vnfcinstanceid': '2',
+ 'computeresource': {'resourceid':'22'},
+ 'vduid': '222',
+ 'vdutype': '2222'
+ }
+ ],
+ 'affectedvirtuallink':{
+
+ },
+ 'affectedcp':{
+
+ }
+
+ }
+ }
def run(self):
try:
self.inst_pre()
self.apply_grant()
self.create_res()
- # self.check_res_status(args)
+ self.check_res_status()
# self.wait_inst_finish(args)
# self.lcm_notify(args)
JobUtil.add_job_status(self.job_id, 100, "Instantiate Vnf success.")
@@ -115,29 +144,74 @@ class InstVnf(Thread):
logger.info("Nf instancing apply grant finish")
def create_res(self):
- logger.info("[NF instantiation] send resource apply request start")
- content_args = {'nfvoInstanceId': self.nfvo_inst_id, 'vnfmInstanceId': self.vnfm_inst_id,
- 'nfInstanceId': self.nf_inst_id, 'nfDescriptorId': '',
- 'lifecycleOperation': 'Instantiate', 'jobId': '',
- 'allocateData': self.vnfd_info}
+ logger.info("[NF instantiation] create resource start")
volumns = ignore_case_get(self.data, "volumn_storages")
- #call vim driver api
#create_volumns(volumns)
JobUtil.add_job_status(self.job_id, 35, 'Nf instancing create resource(volumn_storages) finish')
- # create_networks(self.vnfd_info)
- JobUtil.add_job_status(self.job_id, 45, 'Nf instancing create resource(networks) finish')
- # create_vdus(self.vnfd_info)
- JobUtil.add_job_status(self.job_id, 65, 'Nf instancing create resource(vms) finish')
- def check_res_status(self, args):
- try:
- logger.info('check_res_status, args=%s' % args)
- # CheckResStatusTask(args).do_biz()
- return {'result': '100', 'msg': 'Nf instancing check resource status finish', 'context': {}}
- except Exception as e:
- logger.error('Nf instancing check resource status exception=%s' % e.message)
- logger.error(traceback.format_exc())
- return {'result': '255', 'msg': 'Nf instancing check resource status exception', 'context': {}}
+ vls = ignore_case_get(self.data, "vls")
+ # create_networks(vls)
+ JobUtil.add_job_status(self.job_id, 55, 'Nf instancing create resource(networks) finish')
+
+ vdus = ignore_case_get(self.data, "vdus")
+ # create_vdus(vdus)
+ JobUtil.add_job_status(self.job_id, 75, 'Nf instancing create resource(vms) finish')
+
+ logger.info("[NF instantiation] create resource end")
+
+ def check_res_status(self):
+ logger.info("[NF instantiation] confirm all vms are active start")
+ vnfcs = self.create_res_result['resource_result']['affectedvnfc']
+ for vnfc in vnfcs:
+ if 'success' != vnfc['status']:
+ logger.error("VNFC_STATUS_IS_NOT_ACTIVE[vduid=%s]" % vnfc['vduId'])
+ raise NFLCMException(msgid="VNFC_STATUS_IS_NOT_ACTIVE[vduid=%s]", args=vnfc['vduId'])
+
+ JobUtil.add_job_status(self.job_id, 80, 'SAVE_VNFC_TO_DB')
+ vls = self.create_res_result['resource_result']['affectedvirtuallink']
+ cps = self.create_res_result['resource_result']['affectedcp']
+
+ for vnfc in vnfcs:
+ if 'failed' == vnfc['status']:
+ continue
+ compute_resource = vnfc['computeresource']
+ vminst = VmInstModel.objects.filter(resouceid=compute_resource['resourceid']).first()
+ VNFCInstModel.objects.create(
+ vnfcinstanceid=vnfc['vnfcinstanceid'],
+ vduid=vnfc['vduid'],
+ vdutype=vnfc['vdutype'],
+ nfinstid=self.nf_inst_id,
+ vmid=vminst.vmid)
+ # for vl in vls:
+ # if 'failed' == vl['status']:
+ # continue
+ # network_resource = vl['networkresource']
+ # subnet_resource = vl['subnetworkresource']
+ # networkinst = NetworkInstModel.objects.filter(resouceid=network_resource['resourceid']).first()
+ # subnetinst = SubNetworkInstModel.objects.filter(resouceid=subnet_resource['resourceid']).first()
+ # VLInstModel.objects.create(
+ # vlinstanceid=vl['virtuallinkinstanceid'],
+ # vldid=vl['virtuallinkdescid'],
+ # ownertype='0', # VNF
+ # ownerid=self.nf_inst_id,
+ # relatednetworkid=networkinst.networkid,
+ # relatedsubnetworkid=subnetinst.subnetworkid)
+ # # 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'])
+ # self.add_job(43, 'INST_DPLY_VM_PRGS')
+ logger.info("[NF instantiation] confirm all vms are active end")
def wait_inst_finish(self, args):
try:
diff --git a/lcm/lcm/pub/database/models.py b/lcm/lcm/pub/database/models.py
index d4348406..24dcdf33 100644
--- a/lcm/lcm/pub/database/models.py
+++ b/lcm/lcm/pub/database/models.py
@@ -91,7 +91,7 @@ class JobStatusModel(models.Model):
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)
+ descp = models.TextField(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)
@@ -112,3 +112,30 @@ class NfvoRegInfoModel(models.Model):
clientcert = models.CharField(max_length=255, db_column='CLIENTCERT', null=True)
servercert = models.CharField(max_length=255, db_column='SERVERCERT', null=True)
regtime = models.CharField(max_length=255, db_column='REGTIME')
+
+class VmInstModel(models.Model):
+ class Meta:
+ db_table = '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')
+ instid = models.CharField(db_column='INSTID', max_length=255)
+ vmname = models.CharField(db_column='VMNAME', max_length=255)
+ operationalstate = models.IntegerField(db_column='OPERATIONALSTATE', null=True)
+ 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, null=True)
+ detailinfo = models.TextField(db_column='DETAILINFO', max_length=8192, null=True)
+ is_predefined = models.IntegerField(db_column='ISPREDEFINED', default=0, null=True)
+
+class VNFCInstModel(models.Model):
+ class Meta:
+ db_table = 'VNFCINST'
+
+ vnfcinstanceid = models.CharField(db_column='VNFCINSTANCEID', max_length=255, primary_key=True)
+ vduid = models.CharField(db_column='VDUID', max_length=255)
+ vdutype = models.CharField(db_column='VDUTYPE', max_length=255)
+ nfinstid = models.CharField(db_column='NFINSTID', max_length=255)
+ vmid = models.CharField(db_column='VMID', max_length=255)