diff options
-rw-r--r-- | lcm/lcm/nf/biz/grant_vnf.py | 53 | ||||
-rw-r--r-- | lcm/lcm/nf/biz/instantiate_vnf.py | 20 | ||||
-rw-r--r-- | lcm/lcm/nf/biz/operate_vnf.py | 6 | ||||
-rw-r--r-- | lcm/lcm/nf/biz/query_vnf.py | 6 | ||||
-rw-r--r-- | lcm/lcm/nf/biz/terminate_vnf.py | 9 | ||||
-rw-r--r-- | lcm/lcm/nf/const.py | 13 | ||||
-rw-r--r-- | lcm/lcm/nf/tests/test_delete_vnf.py | 12 | ||||
-rw-r--r-- | lcm/lcm/nf/tests/test_operate_vnf.py | 16 | ||||
-rw-r--r-- | lcm/lcm/nf/tests/test_query_vnf.py | 4 | ||||
-rw-r--r-- | lcm/lcm/nf/tests/test_terminate_vnf.py | 12 | ||||
-rw-r--r-- | lcm/lcm/pub/database/models.py | 12 | ||||
-rw-r--r-- | lcm/lcm/pub/msapi/gvnfmdriver.py | 8 | ||||
-rw-r--r-- | lcm/lcm/pub/vimapi/adaptor.py | 48 | ||||
-rw-r--r-- | lcm/lcm/samples/tests.py | 39 |
14 files changed, 137 insertions, 121 deletions
diff --git a/lcm/lcm/nf/biz/grant_vnf.py b/lcm/lcm/nf/biz/grant_vnf.py index fe3cb530..a92f365e 100644 --- a/lcm/lcm/nf/biz/grant_vnf.py +++ b/lcm/lcm/nf/biz/grant_vnf.py @@ -25,38 +25,53 @@ logger = logging.getLogger(__name__) def grant_resource(data, nf_inst_id, job_id, grant_type, vdus): logger.info("Grant resource begin") - lifecycleOperration = grant_type content_args = { 'vnfInstanceId': nf_inst_id, - 'vnfDescriptorId': '', - 'lifecycleOperation': lifecycleOperration, 'vnfLcmOpOccId': job_id, + 'vnfdId': None, # TODO + 'flavourId': None, # TODO + 'operate': grant_type, + 'isAutomaticInvocation': True, # TODO + 'instantiationLevelId': None, # TODO 'addResources': [], + 'tmpResources': [], 'updateResources': [], 'removeResources': [], 'placementConstraints': [], - 'additionalParams': {} + 'vimConstraints': [], + 'additionalParams': {}, + '_links': None # TODO } - if grant_type == "Terminate": + if grant_type == GRANT_TYPE.TERMINATE: res_index = 1 for vdu in vdus: res_def = { - 'type': 'VDU', - 'resDefId': str(res_index), - 'resDesId': vdu.resouceid} + 'id': str(res_index), + 'type': 'COMPUTE', + 'vduId': None, + 'resourceTemplateId': None, + 'resource': { + 'vimConnectionId': None, + 'resourceProviderId': None, + 'resourceid': vdu.resourceid, + 'vimLevelResourceType': None + } + } content_args['removeResources'].append(res_def) res_index += 1 content_args['additionalParams']['vimid'] = vdus[0].vimid - elif grant_type == "Instantiate": + elif grant_type == GRANT_TYPE.INSTANTIATE: vim_id = ignore_case_get(ignore_case_get(data, "additionalParams"), "vimId") res_index = 1 for vdu in vdus: res_def = { - 'type': 'VDU', - 'resDefId': str(res_index), - 'resDesId': ignore_case_get(vdu, "vdu_id") + 'id': str(res_index), + 'type': 'COMPUTE', + 'vduId': None, + 'resourceTemplateId': None, # TODO: shall be present for the planned creation of new resources. + 'resource': None } content_args['addResources'].append(res_def) res_index += 1 @@ -65,9 +80,17 @@ def grant_resource(data, nf_inst_id, job_id, grant_type, vdus): res_index = 1 for vdu in vdus: res_def = { - 'type': 'VDU', - 'resDefId': str(res_index), - 'resDesId': vdu.resouceid} + 'id': str(res_index), + 'type': 'COMPUTE', + 'vduId': None, + 'resourceTemplateId': None, + 'resource': { + 'vimConnectionId': None, + 'resourceProviderId': None, + 'resourceid': vdu.resourceid, + 'vimLevelResourceType': None + } + } content_args['updateResources'].append(res_def) res_index += 1 content_args['additionalParams']['vimid'] = vdus[0].vimid diff --git a/lcm/lcm/nf/biz/instantiate_vnf.py b/lcm/lcm/nf/biz/instantiate_vnf.py index 161cd7d1..1c9a66bf 100644 --- a/lcm/lcm/nf/biz/instantiate_vnf.py +++ b/lcm/lcm/nf/biz/instantiate_vnf.py @@ -28,6 +28,7 @@ from lcm.pub.utils.timeutil import now_time from lcm.pub.utils.values import ignore_case_get, get_none, get_boolean, get_integer from lcm.pub.vimapi import adaptor from lcm.nf.biz.grant_vnf import grant_resource +from lcm.nf.const import GRANT_TYPE logger = logging.getLogger(__name__) @@ -39,7 +40,7 @@ class InstantiateVnf(Thread): self.nf_inst_id = nf_inst_id self.job_id = job_id self.vim_id = ignore_case_get(ignore_case_get(self.data, "additionalParams"), "vimId") - self.grant_type = "Instantiate" + self.grant_type = GRANT_TYPE.INSTANTIATE def run(self): try: @@ -73,8 +74,9 @@ class InstantiateVnf(Thread): inputs = json.loads(inputs) for key, val in inputs.items(): input_parameters.append({"key": key, "value": val}) - vnf_package_info = query_vnfpackage_by_id(self.vnfd_id) - self.vnfd_info = json.loads(ignore_case_get(ignore_case_get(vnf_package_info, "packageInfo"), "vnfdModel")) + vnf_package = query_vnfpackage_by_id(self.vnfd_id) + pkg_info = ignore_case_get(vnf_package, "packageInfo") + self.vnfd_info = json.loads(ignore_case_get(pkg_info, "vnfdModel")) self.update_cps() metadata = ignore_case_get(self.vnfd_info, "metadata") @@ -180,7 +182,7 @@ def volume_save(job_id, nf_inst_id, ret): StorageInstModel.objects.create( storageid=str(uuid.uuid4()), vimid=ignore_case_get(ret, "vimId"), - resouceid=ignore_case_get(ret, "id"), + resourceid=ignore_case_get(ret, "id"), name=ignore_case_get(ret, "name"), tenant=ignore_case_get(ret, "tenantId"), create_time=ignore_case_get(ret, "createTime"), @@ -198,7 +200,7 @@ def network_save(job_id, nf_inst_id, ret): networkid=str(uuid.uuid4()), name=ignore_case_get(ret, "name"), vimid=ignore_case_get(ret, "vimId"), - resouceid=ignore_case_get(ret, "id"), + resourceid=ignore_case_get(ret, "id"), tenant=ignore_case_get(ret, "tenantId"), segmentid=str(ignore_case_get(ret, "segmentationId")), network_type=ignore_case_get(ret, "networkType"), @@ -218,7 +220,7 @@ def subnet_save(job_id, nf_inst_id, ret): subnetworkid=str(uuid.uuid4()), name=ignore_case_get(ret, "name"), vimid=ignore_case_get(ret, "vimId"), - resouceid=ignore_case_get(ret, "id"), + resourceid=ignore_case_get(ret, "id"), tenant=ignore_case_get(ret, "tenantId"), networkid=ignore_case_get(ret, "networkId"), cidr=ignore_case_get(ret, "cidr"), @@ -241,7 +243,7 @@ def port_save(job_id, nf_inst_id, ret): subnetworkid=ignore_case_get(ret, "subnetId"), name=ignore_case_get(ret, "name"), vimid=ignore_case_get(ret, "vimId"), - resouceid=ignore_case_get(ret, "id"), + resourceid=ignore_case_get(ret, "id"), tenant=ignore_case_get(ret, "tenantId"), macaddress=ignore_case_get(ret, "macAddress"), ipaddress=ignore_case_get(ret, "ip"), @@ -259,7 +261,7 @@ def flavor_save(job_id, nf_inst_id, ret): flavourid=str(uuid.uuid4()), name=ignore_case_get(ret, "name"), vimid=ignore_case_get(ret, "vimId"), - resouceid=ignore_case_get(ret, "id"), + resourceid=ignore_case_get(ret, "id"), tenant=ignore_case_get(ret, "tenantId"), vcpu=get_integer(ignore_case_get(ret, "vcpu")), memory=get_integer(ignore_case_get(ret, "memory")), @@ -279,7 +281,7 @@ def vm_save(job_id, nf_inst_id, ret): vmid=vm_id, vmname=ignore_case_get(ret, "name"), vimid=ignore_case_get(ret, "vimId"), - resouceid=ignore_case_get(ret, "id"), + resourceid=ignore_case_get(ret, "id"), tenant=ignore_case_get(ret, "tenantId"), nic_array=ignore_case_get(ret, "nicArray"), metadata=ignore_case_get(ret, "metadata"), diff --git a/lcm/lcm/nf/biz/operate_vnf.py b/lcm/lcm/nf/biz/operate_vnf.py index 5f6499d6..99c1e6d9 100644 --- a/lcm/lcm/nf/biz/operate_vnf.py +++ b/lcm/lcm/nf/biz/operate_vnf.py @@ -70,7 +70,7 @@ class OperateVnf(Thread): resource_table = globals().get(resource_type + 'InstModel') resource_insts = resource_table.objects.filter(instid=self.nf_inst_id) for resource_inst in resource_insts: - if not resource_inst.resouceid: + if not resource_inst.resourceid: continue self.inst_resource[RESOURCE_MAP.get(resource_type)].append(self.get_resource(resource_inst)) logger.info('Query resource end, resource=%s' % self.inst_resource) @@ -79,7 +79,7 @@ class OperateVnf(Thread): return { "vim_id": resource.vimid, "tenant_id": resource.tenant, - "id": resource.resouceid + "id": resource.resourceid } def operate_resource(self): @@ -100,4 +100,4 @@ class OperateVnf(Thread): def do_notify_op(self, status, resid): logger.error('VNF resource %s updated to: %s' % (resid, status)) - VmInstModel.objects.filter(instid=self.nf_inst_id, resouceid=resid).update(operationalstate=status) + VmInstModel.objects.filter(instid=self.nf_inst_id, resourceid=resid).update(operationalstate=status) diff --git a/lcm/lcm/nf/biz/query_vnf.py b/lcm/lcm/nf/biz/query_vnf.py index 09fab6ca..380d455a 100644 --- a/lcm/lcm/nf/biz/query_vnf.py +++ b/lcm/lcm/nf/biz/query_vnf.py @@ -51,7 +51,7 @@ class QueryVnf: "id": s.storageid, "storageResource": { "vimConnectionId": s.vimid, - "resourceId": s.resouceid + "resourceId": s.resourceid } } arr.append(storage) @@ -67,7 +67,7 @@ class QueryVnf: "virtualLinkDescId": v.vldid, "networkResource": { "vimConnectionId": net[0].vimid, - "resourceId": net[0].resouceid + "resourceId": net[0].resourceid } } vl_arr.append(v_dic) @@ -87,7 +87,7 @@ class QueryVnf: "vduId": vnfc.vduid, "computeResource": { "vimConnectionId": vm[0].vimid, - "resourceId": vm[0].resouceid + "resourceId": vm[0].resourceid }, "storageResourceIds": [s.storageid for s in storage] } diff --git a/lcm/lcm/nf/biz/terminate_vnf.py b/lcm/lcm/nf/biz/terminate_vnf.py index d63cdfa9..5b299f20 100644 --- a/lcm/lcm/nf/biz/terminate_vnf.py +++ b/lcm/lcm/nf/biz/terminate_vnf.py @@ -30,6 +30,7 @@ from lcm.pub.utils.timeutil import now_time from lcm.pub.utils.values import ignore_case_get from lcm.pub.vimapi import adaptor from lcm.nf.biz.grant_vnf import grant_resource +from lcm.nf.const import GRANT_TYPE logger = logging.getLogger(__name__) @@ -43,7 +44,7 @@ class TerminateVnf(Thread): self.terminationType = ignore_case_get(self.data, "terminationType") self.gracefulTerminationTimeout = ignore_case_get(self.data, "gracefulTerminationTimeout") self.inst_resource = {'volumn': [], 'network': [], 'subnet': [], 'port': [], 'flavor': [], 'vm': []} - self.grant_type = "Terminate" + self.grant_type = GRANT_TYPE.TERMINATE def run(self): try: @@ -83,7 +84,7 @@ class TerminateVnf(Thread): resource_table = globals().get(resource_type + 'InstModel') resource_insts = resource_table.objects.filter(instid=self.nf_inst_id) for resource_inst in resource_insts: - if not resource_inst.resouceid: + if not resource_inst.resourceid: continue self.inst_resource[RESOURCE_MAP.get(resource_type)].append(self.get_resource(resource_inst)) logger.info('Query resource end, resource=%s' % self.inst_resource) @@ -92,7 +93,7 @@ class TerminateVnf(Thread): return { "vim_id": resource.vimid, "tenant_id": resource.tenant, - "res_id": resource.resouceid, + "res_id": resource.resourceid, "is_predefined": resource.is_predefined } @@ -114,7 +115,7 @@ class TerminateVnf(Thread): logger.error('Deleting [%s] resource, resourceid [%s]' % (res_type, res_id)) resource_type = RESOURCE_MAP.keys()[RESOURCE_MAP.values().index(res_type)] resource_table = globals().get(resource_type + 'InstModel') - resource_table.objects.filter(instid=self.nf_inst_id, resouceid=res_id).delete() + resource_table.objects.filter(instid=self.nf_inst_id, resourceid=res_id).delete() def lcm_notify(self): NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(status='NOT_INSTANTIATED', lastuptime=now_time()) diff --git a/lcm/lcm/nf/const.py b/lcm/lcm/nf/const.py index f45e9f68..15e27155 100644 --- a/lcm/lcm/nf/const.py +++ b/lcm/lcm/nf/const.py @@ -17,7 +17,7 @@ from lcm.pub.utils.jobutil import enum HEAL_ACTION_TYPE = enum(START="vmCreate", RESTART="vmReset") ACTION_TYPE = enum(START=1, STOP=2, REBOOT=3) -GRANT_TYPE = enum(INSTANTIATE="Instantiate", TERMINATE="Terminate", HEAL_CREATE="Heal Create", HEAL_RESTART="Heal Restart", OPERATE="Operate") +GRANT_TYPE = enum(INSTANTIATE="INSTANTIATE", TERMINATE="TERMINATE", HEAL_CREATE="Heal Create", HEAL_RESTART="Heal Restart", OPERATE="OPERATE") VNF_STATUS = enum(NULL='null', INSTANTIATING="instantiating", INACTIVE='inactive', ACTIVE="active", FAILED="failed", TERMINATING="terminating", SCALING="scaling", OPERATING="operating", UPDATING="updating", HEALING="healing") @@ -715,6 +715,17 @@ vnfdModel = { "vimid": "test", "tenant": "chinamobile", "availability_zone": "test", + "vnfId": "", + "vnfName": "", + "cloudOwner": "", + "cloudRegionId": "", + "vduInfo": [ + { + "vduName": "VDU_vbng_0", + "flavorName": "flavor_1", + "directive": "" + } + ] }, "name": "test", "inject_files": [], diff --git a/lcm/lcm/nf/tests/test_delete_vnf.py b/lcm/lcm/nf/tests/test_delete_vnf.py index 26679231..62ed0dfd 100644 --- a/lcm/lcm/nf/tests/test_delete_vnf.py +++ b/lcm/lcm/nf/tests/test_delete_vnf.py @@ -26,13 +26,13 @@ class TestNFTerminate(TestCase): self.client = Client() StorageInstModel.objects.create(storageid="1", vimid="1", - resouceid="11", + resourceid="11", insttype=0, instid="1111", is_predefined=1) NetworkInstModel.objects.create(networkid='1', vimid='1', - resouceid='1', + resourceid='1', name='pnet_network', is_predefined=1, tenant='admin', @@ -40,7 +40,7 @@ class TestNFTerminate(TestCase): instid='1111') SubNetworkInstModel.objects.create(subnetworkid='1', vimid='1', - resouceid='1', + resourceid='1', networkid='1', is_predefined=1, name='sub_pnet', @@ -51,7 +51,7 @@ class TestNFTerminate(TestCase): networkid='1', subnetworkid='1', vimid='1', - resouceid='1', + resourceid='1', is_predefined=1, name='aaa_pnet_cp', tenant='admin', @@ -59,12 +59,12 @@ class TestNFTerminate(TestCase): instid='1111') FlavourInstModel.objects.create(flavourid="1", vimid="1", - resouceid="11", + resourceid="11", instid="1111", is_predefined=1) VmInstModel.objects.create(vmid="1", vimid="1", - resouceid="11", + resourceid="11", insttype=0, instid="1111", vmname="test_01", diff --git a/lcm/lcm/nf/tests/test_operate_vnf.py b/lcm/lcm/nf/tests/test_operate_vnf.py index 2071472c..625d40a3 100644 --- a/lcm/lcm/nf/tests/test_operate_vnf.py +++ b/lcm/lcm/nf/tests/test_operate_vnf.py @@ -87,7 +87,7 @@ class TestNFOperate(TestCase): VmInstModel.objects.create(vmid="1",
vimid="1",
- resouceid="11",
+ resourceid="11",
insttype=0,
instid="1111",
vmname="test_01",
@@ -105,7 +105,7 @@ class TestNFOperate(TestCase): self.job_id = JobUtil.create_job('NF', 'OPERATE', self.nf_inst_id)
JobUtil.add_job_status(self.job_id, 0, "OPERATE_VNF_READY")
OperateVnf(req_data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
- vm = VmInstModel.objects.filter(vmid="1", vimid="1", resouceid="11")
+ vm = VmInstModel.objects.filter(vmid="1", vimid="1", resourceid="11")
self.assertEqual("ACTIVE", vm[0].operationalstate)
self.assert_job_result(self.job_id, 100, "Operate Vnf success.")
@@ -130,7 +130,7 @@ class TestNFOperate(TestCase): VmInstModel.objects.create(vmid="1",
vimid="1",
- resouceid="11",
+ resourceid="11",
insttype=0,
instid="1111",
vmname="test_01",
@@ -148,7 +148,7 @@ class TestNFOperate(TestCase): self.job_id = JobUtil.create_job('NF', 'OPERATE', self.nf_inst_id)
JobUtil.add_job_status(self.job_id, 0, "OPERATE_VNF_READY")
OperateVnf(req_data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
- vm = VmInstModel.objects.filter(vmid="1", vimid="1", resouceid="11")
+ vm = VmInstModel.objects.filter(vmid="1", vimid="1", resourceid="11")
self.assertEqual("INACTIVE", vm[0].operationalstate)
self.assert_job_result(self.job_id, 100, "Operate Vnf success.")
@@ -173,7 +173,7 @@ class TestNFOperate(TestCase): VmInstModel.objects.create(vmid="1",
vimid="1",
- resouceid="11",
+ resourceid="11",
insttype=0,
instid="1111",
vmname="test_01",
@@ -193,7 +193,7 @@ class TestNFOperate(TestCase): self.job_id = JobUtil.create_job('NF', 'OPERATE', self.nf_inst_id)
JobUtil.add_job_status(self.job_id, 0, "OPERATE_VNF_READY")
OperateVnf(req_data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
- vm = VmInstModel.objects.filter(vmid="1", vimid="1", resouceid="11")
+ vm = VmInstModel.objects.filter(vmid="1", vimid="1", resourceid="11")
self.assertEqual("INACTIVE", vm[0].operationalstate)
self.assert_job_result(self.job_id, 100, "Operate Vnf success.")
@@ -218,7 +218,7 @@ class TestNFOperate(TestCase): VmInstModel.objects.create(vmid="1",
vimid="1",
- resouceid="11",
+ resourceid="11",
insttype=0,
instid="1111",
vmname="test_01",
@@ -237,6 +237,6 @@ class TestNFOperate(TestCase): self.job_id = JobUtil.create_job('NF', 'OPERATE', self.nf_inst_id)
JobUtil.add_job_status(self.job_id, 0, "OPERATE_VNF_READY")
OperateVnf(req_data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run()
- vm = VmInstModel.objects.filter(vmid="1", vimid="1", resouceid="11")
+ vm = VmInstModel.objects.filter(vmid="1", vimid="1", resourceid="11")
self.assertEqual("INACTIVE", vm[0].operationalstate)
self.assert_job_result(self.job_id, 100, "Operate Vnf success.")
diff --git a/lcm/lcm/nf/tests/test_query_vnf.py b/lcm/lcm/nf/tests/test_query_vnf.py index 95f387b9..e0ecddb5 100644 --- a/lcm/lcm/nf/tests/test_query_vnf.py +++ b/lcm/lcm/nf/tests/test_query_vnf.py @@ -116,7 +116,7 @@ class ResourceTest(TestCase): NfInstModel(nfinstid=vnf_inst_id, nf_name='VNF1', status='INSTANTIATED').save() StorageInstModel(storageid='s02', vimid='vim01', - resouceid='resource01', + resourceid='resource01', insttype=1, instid=vnf_inst_id).save() response = self.client.get("/api/vnflcm/v1/vnf_instances/%s" % vnf_inst_id, format='json') @@ -161,7 +161,7 @@ class ResourceTest(TestCase): status='INSTANTIATED').save() StorageInstModel(storageid='s0%s' % i, vimid='vim0%s' % i, - resouceid='resource0%s' % i, + resourceid='resource0%s' % i, insttype=1, instid='%s' % i).save() response = self.client.get("/api/vnflcm/v1/vnf_instances", format='json') diff --git a/lcm/lcm/nf/tests/test_terminate_vnf.py b/lcm/lcm/nf/tests/test_terminate_vnf.py index 23b246d7..97330b6c 100644 --- a/lcm/lcm/nf/tests/test_terminate_vnf.py +++ b/lcm/lcm/nf/tests/test_terminate_vnf.py @@ -34,13 +34,13 @@ class TestNFTerminate(TestCase): self.client = Client()
StorageInstModel.objects.create(storageid="1",
vimid="1",
- resouceid="11",
+ resourceid="11",
insttype=0,
instid="1111",
is_predefined=1)
NetworkInstModel.objects.create(networkid='1',
vimid='1',
- resouceid='1',
+ resourceid='1',
name='pnet_network',
is_predefined=1,
tenant='admin',
@@ -48,7 +48,7 @@ class TestNFTerminate(TestCase): instid='1111')
SubNetworkInstModel.objects.create(subnetworkid='1',
vimid='1',
- resouceid='1',
+ resourceid='1',
networkid='1',
is_predefined=1,
name='sub_pnet',
@@ -59,7 +59,7 @@ class TestNFTerminate(TestCase): networkid='1',
subnetworkid='1',
vimid='1',
- resouceid='1',
+ resourceid='1',
is_predefined=1,
name='aaa_pnet_cp',
tenant='admin',
@@ -67,12 +67,12 @@ class TestNFTerminate(TestCase): instid='1111')
FlavourInstModel.objects.create(flavourid="1",
vimid="1",
- resouceid="11",
+ resourceid="11",
instid="1111",
is_predefined=1)
VmInstModel.objects.create(vmid="1",
vimid="1",
- resouceid="11",
+ resourceid="11",
insttype=0,
instid="1111",
vmname="test_01",
diff --git a/lcm/lcm/pub/database/models.py b/lcm/lcm/pub/database/models.py index cbdd85cc..47a22fdd 100644 --- a/lcm/lcm/pub/database/models.py +++ b/lcm/lcm/pub/database/models.py @@ -105,7 +105,7 @@ class StorageInstModel(models.Model): storageid = models.CharField(db_column='STORAGEID', primary_key=True, max_length=255) vimid = models.CharField(db_column='VIMID', max_length=255) - resouceid = models.CharField(db_column='RESOURCEID', max_length=255) + resourceid = models.CharField(db_column='RESOURCEID', max_length=255) insttype = models.IntegerField(db_column='INSTTYPE') instid = models.CharField(db_column='INSTID', max_length=255) name = models.CharField(db_column='NAME', max_length=255, null=True) @@ -130,7 +130,7 @@ class VmInstModel(models.Model): vmid = models.CharField(db_column='VMID', primary_key=True, max_length=255) vimid = models.CharField(db_column='VIMID', max_length=255) tenant = models.CharField(db_column='TENANT', max_length=255, null=True) - resouceid = models.CharField(db_column='RESOURCEID', max_length=255) + resourceid = models.CharField(db_column='RESOURCEID', max_length=255) vmname = models.CharField(db_column='VMNAME', max_length=255) nic_array = models.CharField(db_column='NICARRAY', max_length=255) metadata = models.CharField(db_column='METADATA', max_length=255) @@ -165,7 +165,7 @@ class FlavourInstModel(models.Model): flavourid = models.CharField(db_column='FLAVOURID', max_length=255, primary_key=True) vimid = models.CharField(db_column='VIMID', max_length=255) - resouceid = models.CharField(db_column='RESOURCEID', max_length=255) + resourceid = models.CharField(db_column='RESOURCEID', max_length=255) name = models.CharField(db_column='NAME', max_length=255) tenant = models.CharField(db_column='TENANT', max_length=255, null=True) vcpu = models.IntegerField(db_column='VCPU', null=True) @@ -186,7 +186,7 @@ class NetworkInstModel(models.Model): networkid = models.CharField(db_column='NETWORKID', primary_key=True, max_length=255) vimid = models.CharField(db_column='VIMID', max_length=255) - resouceid = models.CharField(db_column='RESOURCEID', max_length=255) + resourceid = models.CharField(db_column='RESOURCEID', max_length=255) insttype = models.IntegerField(db_column='INSTTYPE') instid = models.CharField(db_column='INSTID', max_length=255) name = models.CharField(db_column='NAME', max_length=255) @@ -213,7 +213,7 @@ class SubNetworkInstModel(models.Model): subnetworkid = models.CharField(db_column='SUBNETWORKID', primary_key=True, max_length=255) vimid = models.CharField(db_column='VIMID', max_length=255) - resouceid = models.CharField(db_column='RESOURCEID', max_length=255) + resourceid = models.CharField(db_column='RESOURCEID', max_length=255) networkid = models.CharField(db_column='NETWORKID', max_length=255) insttype = models.IntegerField(db_column='INSTTYPE') instid = models.CharField(db_column='INSTID', max_length=255) @@ -256,7 +256,7 @@ class PortInstModel(models.Model): 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) + resourceid = 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) diff --git a/lcm/lcm/pub/msapi/gvnfmdriver.py b/lcm/lcm/pub/msapi/gvnfmdriver.py index 4b2b304a..763b1974 100644 --- a/lcm/lcm/pub/msapi/gvnfmdriver.py +++ b/lcm/lcm/pub/msapi/gvnfmdriver.py @@ -60,7 +60,7 @@ def prepare_notification_data(nfinstid, jobid, changetype): if vm: vm_resource = { 'vimId': vm[0].vimid, - 'resourceId': vm[0].resouceid, + 'resourceId': vm[0].resourceid, 'resourceProviderId': vm[0].vmname, # TODO: is resourceName mapped to resourceProviderId? 'vimLevelResourceType': 'vm' } @@ -75,7 +75,7 @@ def prepare_notification_data(nfinstid, jobid, changetype): for network in networks: network_resource = { 'vimConnectionId': network.vimid, - 'resourceId': network.resouceid, + 'resourceId': network.resourceid, 'resourceProviderId': network.name, # TODO: is resourceName mapped to resourceProviderId? 'vimLevelResourceType': 'network' } @@ -92,7 +92,7 @@ def prepare_notification_data(nfinstid, jobid, changetype): 'id': port.portid, # TODO: port.portid or port.nodeid? 'resourceHandle': { 'vimConnectionId': port.vimid, - 'resourceId': port.resouceid, + 'resourceId': port.resourceid, 'resourceProviderId': port.name, # TODO: is resourceName mapped to resourceProviderId? 'vimLevelResourceType': 'port' }, @@ -107,7 +107,7 @@ def prepare_notification_data(nfinstid, jobid, changetype): 'changeType': changetype, 'storageResource': { 'vimConnectionId': vs.vimid, - 'resourceId': vs.resouceid, + 'resourceId': vs.resourceid, 'resourceProviderId': vs.name, # TODO: is resourceName mapped to resourceProviderId? 'vimLevelResourceType': 'volume' } diff --git a/lcm/lcm/pub/vimapi/adaptor.py b/lcm/lcm/pub/vimapi/adaptor.py index bbc91098..f47c3370 100644 --- a/lcm/lcm/pub/vimapi/adaptor.py +++ b/lcm/lcm/pub/vimapi/adaptor.py @@ -14,7 +14,6 @@ import logging import time -import ast import json from lcm.pub.utils.values import ignore_case_get, set_opt_val @@ -277,29 +276,16 @@ def parse_unit(val, base_unit): return int(num) * unit_rate_map[unit.upper()] / unit_rate_map[base_unit.upper()] -def search_flavor_aai(vim_id, memory_page_size, memory_page_unit): +def search_flavor_aai(vim_id, flavor_name): aai_flavors = get_flavor_info(vim_id) if not aai_flavors: return None - logger.debug("aai_flavors:%s" % aai_flavors) aai_flavor = aai_flavors["flavor"] for one_aai_flavor in aai_flavor: - if one_aai_flavor["flavor-name"].find("onap.") == -1: - continue - hpa_capabilities = one_aai_flavor["hpa-capabilities"]["hpa-capability"] - logger.debug("hpa_capabilities=%s", hpa_capabilities) - for one_hpa_capa in hpa_capabilities: - logger.debug("one_hpa_capa=%s", one_hpa_capa) - hpa_feature_attr = one_hpa_capa["hpa-feature-attributes"] - for one_hpa_attr in hpa_feature_attr: - hpa_key = one_hpa_attr["hpa-attribute-key"] - hpa_attr_value = ast.literal_eval(one_hpa_attr["hpa-attribute-value"]) - mem_size = ignore_case_get(hpa_attr_value, 'value') - mem_unit = ignore_case_get(hpa_attr_value, 'unit') - value = mem_size + " " + mem_unit - hpa_mem_size = parse_unit(value, memory_page_unit) - if hpa_key == "memoryPageSize" and hpa_mem_size == memory_page_size: - return one_aai_flavor + if one_aai_flavor["flavor-name"].find(flavor_name) == -1: + return one_aai_flavor + + return None def create_flavor(vim_cache, res_cache, data, flavor, do_notify, res_type): @@ -316,24 +302,19 @@ def create_flavor(vim_cache, res_cache, data, flavor, do_notify, res_type): "isPublic": True } - # just do memory huge page - flavor_extra_specs = "" - vdu_memory_requirements = ignore_case_get(virtual_memory, "vdu_memory_requirements") - if "memoryPageSize" in vdu_memory_requirements: - memory_page_size = int(vdu_memory_requirements["memoryPageSize"].replace('MB', '').strip()) - flavor_extra_specs = {"hw": memory_page_size, } # TODO - logger.debug("flavor_extra_specs:%s" % flavor_extra_specs) - - # FIXME: search aai flavor - aai_flavor = search_flavor_aai(vim_id, memory_page_size, "MB") + # Using flavor name returned by OOF to search falvor + vdu_id = ignore_case_get(flavor, "vdu_id") + for one_vdu in location_info["vduInfo"]: + if one_vdu["vduName"] == vdu_id: + break + aai_flavor = search_flavor_aai(vim_id, one_vdu["flavorName"]) - # add aai flavor + # Add aai flavor if aai_flavor: ret = aai_flavor do_notify(res_type, ret) set_res_cache(res_cache, res_type, flavor["vdu_id"], ret["flavor-id"]) else: - extra_specs = [] disk_type = ignore_case_get(virtual_storage, "type_of_storage") disk_size = int(ignore_case_get(virtual_storage, "size_of_storage").replace('GB', '').strip()) if disk_type == "root": @@ -343,13 +324,10 @@ def create_flavor(vim_cache, res_cache, data, flavor, do_notify, res_type): elif disk_type == "swap": param["swap"] = disk_size - for es in flavor_extra_specs: - extra_specs.append({"keyName": es, "value": flavor_extra_specs[es]}) - - set_opt_val(param, "extraSpecs", extra_specs) tenant_id = get_tenant_id(vim_cache, vim_id, tenant_name) logger.debug("param:%s" % param) ret = api.create_flavor(vim_id, tenant_id, param) + logger.debug("hhb ret:%s" % ret) do_notify(res_type, ret) set_res_cache(res_cache, res_type, flavor["vdu_id"], ret["id"]) diff --git a/lcm/lcm/samples/tests.py b/lcm/lcm/samples/tests.py index 42d96b01..a1d13be4 100644 --- a/lcm/lcm/samples/tests.py +++ b/lcm/lcm/samples/tests.py @@ -87,7 +87,18 @@ inst_res_data = { "vimid": "f1e33529-4a88-4155-9d7a-893cf2c80527", "tenant": "vnfm", "availability_zone": "zone1", - "host": "host1" + "host": "host1", + "vnfId": "", + "vnfName": "", + "cloudOwner": "", + "cloudRegionId": "", + "vduInfo": [ + { + "vduName": "VDU_vbng_0", + "flavorName": "flavor_1", + "directive": "", + }, + ] }, "descrption": "the virtual machine of vNat", "boot_order": [ @@ -304,28 +315,17 @@ c4_data_create_port = { "nodeId": "", "id": "456" } +c5_data_create_flavor = { + "vimId": "f1e33529-4a88-4155-9d7a-893cf2c80527", + "nodeId": "", + "id": "6456", +} c5_data_get_flavor = { "flavor": [ { "flavor-id": "111111", - "flavor-name": "onap.large", - "hpa-capabilities": - { - "hpa-capability": - [ - { - "hpa-capability-id": "1243", - "hpa-feature-attributes": - [ - { - "hpa-attribute-key": "memoryPageSize", - "hpa-attribute-value": '{"value": "2", "unit": "MB"}' - } - ] - } - ] - } + "flavor-name": "flavor_1", } ] } @@ -373,6 +373,7 @@ class SampleViewTest(unittest.TestCase): r3_data_create_subnet = [0, json.JSONEncoder().encode(c3_data_create_subnet), '200'] r4_data_create_port = [0, json.JSONEncoder().encode(c4_data_create_port), '200'] r5_data_get_flavor = [0, json.JSONEncoder().encode(c5_data_get_flavor), '200'] + r5_data_create_flavor = [0, json.JSONEncoder().encode(c5_data_create_flavor), '200'] r6_data_list_image = [0, json.JSONEncoder().encode(c6_data_list_image), '200'] r6_data_create_vm = [0, json.JSONEncoder().encode(c6_data_create_vm), '200'] r6_data_get_vm = [0, json.JSONEncoder().encode(c6_data_get_vm), '200'] @@ -382,7 +383,7 @@ class SampleViewTest(unittest.TestCase): r2_data_create_network, r3_data_create_subnet, r4_data_create_port, - r5_data_get_flavor, + r5_data_get_flavor, r5_data_create_flavor, r6_data_list_image, r6_data_create_vm, r6_data_get_vm] resp = self.client.post(inst_res_url, data=json.dumps(inst_res_data), content_type='application/json') self.failUnlessEqual(status.HTTP_204_NO_CONTENT, resp.status_code) |