summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lcm/lcm/nf/vnfs/tests/test_vnf_create.py8
-rw-r--r--lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py39
-rw-r--r--lcm/lcm/pub/msapi/nfvolcm.py5
3 files changed, 38 insertions, 14 deletions
diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
index 3819d0ca..9fc981c1 100644
--- a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
+++ b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
@@ -101,7 +101,8 @@ class TestNsInstantiate(TestCase):
context = json.loads(response.content)
self.assertTrue(NfInstModel.objects.filter(nfinstid=context['vnfInstanceId']).exists())
- def test_instantiate_vnf(self):
+ @mock.patch.object(InstVnf, 'run')
+ def test_instantiate_vnf(self, mock_run):
response = self.client.post("/gvnfmapi/lcm/v1/vnf_instances/12/instantiate", data={}, format='json')
self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
@@ -170,8 +171,9 @@ class TestNsInstantiate(TestCase):
nfvouser='root', nfvopassword='root123')
r1 = [0, json.JSONEncoder().encode(vnfd_model_dict), '200']
r2 = [0, json.JSONEncoder().encode(vnfd_model_dict), '200']
- r3 = [0, json.JSONEncoder().encode(''), '200']
- mock_call_req.side_effect = [r1, r2, r3]
+ r3 = [0, json.JSONEncoder().encode('Nf instancing apply grant'), '200']
+ r4 = [0, json.JSONEncoder().encode('Nf instancing apply resource'), '200']
+ mock_call_req.side_effect = [r1, r2, r3, r4]
create_data = {
"vnfdId": "111",
"vnfInstanceName": "vFW_01",
diff --git a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
index 9340a735..bcadce08 100644
--- a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
+++ b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
@@ -18,9 +18,10 @@ from threading import Thread
from lcm.pub.database.models import NfInstModel, JobStatusModel, NfvoRegInfoModel
from lcm.pub.exceptions import NFLCMException
-from lcm.pub.msapi.nfvolcm import vnfd_rawdata_get, apply_grant_to_nfvo
+from lcm.pub.msapi.nfvolcm import vnfd_rawdata_get, apply_grant_to_nfvo, apply_res_to_nfvo
from lcm.pub.utils.jobutil import JobUtil
from lcm.pub.utils.timeutil import now_time
+from lcm.pub.utils.values import ignore_case_get
logger = logging.getLogger(__name__)
@@ -38,7 +39,7 @@ class InstVnf(Thread):
try:
self.inst_pre()
self.apply_grant()
- # self.apply_res(args)
+ self.create_res()
# self.check_res_status(args)
# self.wait_inst_finish(args)
# self.lcm_notify(args)
@@ -75,6 +76,15 @@ class InstVnf(Thread):
JobUtil.add_job_status(self.job_id, 5, 'GET_NFVO_CONNECTION_INFO')
self.load_nfvo_config()
+ #update NfInstModel
+ NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(flavour_id=ignore_case_get(self.data, "flavourId"),
+ vnf_level=ignore_case_get(self.data, 'instantiationLevelId'),
+ input_params=ignore_case_get(self.data, 'additionalParams'),
+ extension=ignore_case_get(self.data, ''),
+ initallocatedata=self.vnfd_info,
+ localizationLanguage=ignore_case_get(self.data, 'localizationLanguage'),
+ lastuptime=now_time())
+
def apply_grant(self):
logger.info('[NF instantiation] send resource grand request to nfvo start')
#self.check_vm_capacity()
@@ -100,18 +110,24 @@ class InstVnf(Thread):
raise NFLCMException('Nf instancing apply grant exception')
#update_resources_table()
+ NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(instantiationState='INSTANTIATED', lastuptime=now_time())
JobUtil.add_job_status(self.job_id, 15, 'Nf instancing apply grant finish')
logger.info("Nf instancing apply grant finish")
- def apply_res(self, args):
- try:
- logger.info('apply_res, args=%s' % args)
- # ApplyResTask(args).do_biz()
- return {'result': '100', 'msg': 'Nf instancing apply resource finish', 'context': {}}
- except Exception as e:
- logger.error('Nf instancing apply resource exception=%s' % e.message)
- logger.error(traceback.format_exc())
- return {'result': '255', 'msg': 'Nf instancing apply resource exception', 'context': {}}
+ 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}
+ 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:
@@ -169,3 +185,4 @@ 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)
+
diff --git a/lcm/lcm/pub/msapi/nfvolcm.py b/lcm/lcm/pub/msapi/nfvolcm.py
index 9ea2eef8..0b2e6005 100644
--- a/lcm/lcm/pub/msapi/nfvolcm.py
+++ b/lcm/lcm/pub/msapi/nfvolcm.py
@@ -27,4 +27,9 @@ def apply_grant_to_nfvo(data):
#call gvnfm driver
def notify_lcm_to_nfvo(data, nf_inst_id):
ret = req_by_msb("openoapi/nslcm/v1/vnfs/%s/Notify"%nf_inst_id, "POST", data)
+ return ret
+
+#call gvnfm driver
+def apply_res_to_nfvo(data):
+ ret = req_by_msb("openoapi/nslcm/v1/res" , "POST", data)
return ret \ No newline at end of file