summaryrefslogtreecommitdiffstats
path: root/lcm/ns_vnfs
diff options
context:
space:
mode:
Diffstat (limited to 'lcm/ns_vnfs')
-rw-r--r--lcm/ns_vnfs/biz/create_vnfs.py39
-rw-r--r--lcm/ns_vnfs/biz/grant_vnf.py48
-rw-r--r--lcm/ns_vnfs/biz/grant_vnfs.py7
-rw-r--r--lcm/ns_vnfs/biz/terminate_nfs.py5
-rw-r--r--lcm/ns_vnfs/tests/tests.py20
5 files changed, 56 insertions, 63 deletions
diff --git a/lcm/ns_vnfs/biz/create_vnfs.py b/lcm/ns_vnfs/biz/create_vnfs.py
index ca7ca572..6989805f 100644
--- a/lcm/ns_vnfs/biz/create_vnfs.py
+++ b/lcm/ns_vnfs/biz/create_vnfs.py
@@ -22,16 +22,15 @@ from lcm.ns.enum import OWNER_TYPE
from lcm.ns_vnfs.const import NFVO_VNF_INST_TIMEOUT_SECOND
from lcm.ns_vnfs.biz.subscribe import SubscriptionCreation
from lcm.ns_vnfs.biz.wait_job import wait_job_finish
-from lcm.ns_vnfs.enum import VNF_STATUS, INST_TYPE
+from lcm.ns_vnfs.enum import VNF_STATUS
from lcm.pub.config.config import REPORT_TO_AAI
from lcm.pub.config.config import REG_TO_MSB_REG_PARAM, OOF_BASE_URL, OOF_PASSWD, OOF_USER
from lcm.pub.config.config import CUST_NAME, CUST_LAT, CUST_LONG
-from lcm.pub.database.models import NfInstModel, NSInstModel, VmInstModel, VNFFGInstModel, VLInstModel, OOFDataModel
+from lcm.pub.database.models import NfInstModel, NSInstModel, VNFFGInstModel, VLInstModel, OOFDataModel
from lcm.jobs.enum import JOB_MODEL_STATUS, JOB_ACTION, JOB_PROGRESS, JOB_ERROR_CODE, JOB_TYPE
from lcm.pub.exceptions import NSLCMException
from lcm.pub.msapi.aai import create_vnf_aai
from lcm.pub.msapi.extsys import get_vnfm_by_id
-from lcm.pub.msapi.resmgr import create_vnf, create_vnf_creation_info
from lcm.pub.msapi.sdc_run_catalog import query_vnfpackage_by_id
from lcm.pub.msapi.vnfmdriver import send_nf_init_request
from lcm.pub.utils import restcall
@@ -89,10 +88,8 @@ class CreateVnfs(Thread):
self.send_nf_init_request_to_vnfm()
self.send_homing_request_to_OOF()
self.send_get_vnfm_request_to_extsys()
- # self.send_create_vnf_request_to_resmgr()
self.wait_vnfm_job_finish()
self.subscribe()
- # self.write_vnf_creation_info()
self.save_info_to_db()
JobUtil.add_job_status(self.job_id, JOB_PROGRESS.FINISHED, 'vnf instantiation success', JOB_ERROR_CODE.NO_ERROR)
except NSLCMException as e:
@@ -363,26 +360,6 @@ class CreateVnfs(Thread):
resp_body = get_vnfm_by_id(self.vnfm_inst_id)
self.vnfm_inst_name = ignore_case_get(resp_body, 'name')
- def send_create_vnf_request_to_resmgr(self):
- pkg_vnfd = self.vnfd_model
- data = {
- 'nf_inst_id': self.nf_inst_id,
- 'vnfm_nf_inst_id': self.vnfm_nf_inst_id,
- 'vnf_inst_name': self.vnf_inst_name,
- 'ns_inst_id': self.ns_inst_id,
- 'ns_inst_name': self.ns_inst_name,
- 'nf_inst_name': self.vnf_inst_name,
- 'vnfm_inst_id': self.vnfm_inst_id,
- 'vnfm_inst_name': self.vnfm_inst_name,
- 'vnfd_name': pkg_vnfd['metadata'].get('name', 'undefined'),
- 'vnfd_id': self.vnfd_id,
- 'job_id': self.job_id,
- 'nf_inst_status': VNF_STATUS.INSTANTIATING,
- 'vnf_type': pkg_vnfd['metadata'].get('vnf_type', 'undefined'),
- 'nf_package_id': ignore_case_get(self.nf_package_info, "vnfPackageId")
- }
- create_vnf(data)
-
def wait_vnfm_job_finish(self):
ret = wait_job_finish(
vnfm_id=self.vnfm_inst_id,
@@ -406,18 +383,6 @@ class CreateVnfs(Thread):
except Exception as e:
logger.error("subscribe failed: %s", e.args[0])
- def write_vnf_creation_info(self):
- logger.debug("write_vnf_creation_info start")
- vm_inst_infos = VmInstModel.objects.filter(insttype=INST_TYPE.VNF, instid=self.nf_inst_id)
- data = {
- 'nf_inst_id': self.nf_inst_id,
- 'ns_inst_id': self.ns_inst_id,
- 'vnfm_inst_id': self.vnfm_inst_id,
- 'vms': [{'vmId': vm_inst_info.resouceid, 'vmName': vm_inst_info.vmname, 'vmStatus': 'ACTIVE'} for vm_inst_info in vm_inst_infos]
- }
- create_vnf_creation_info(data)
- logger.debug("write_vnf_creation_info end")
-
def save_info_to_db(self):
logger.debug("save_info_to_db start")
# do_biz_with_share_lock("set-vnflist-in-vnffginst-%s" % self.ns_inst_id, self.save_vnf_inst_id_in_vnffg)
diff --git a/lcm/ns_vnfs/biz/grant_vnf.py b/lcm/ns_vnfs/biz/grant_vnf.py
index 882edd52..26175207 100644
--- a/lcm/ns_vnfs/biz/grant_vnf.py
+++ b/lcm/ns_vnfs/biz/grant_vnf.py
@@ -18,7 +18,6 @@ import uuid
import time
from lcm.pub.database.models import NfInstModel, OOFDataModel
from lcm.pub.exceptions import NSLCMException
-from lcm.pub.msapi import resmgr
from lcm.pub.msapi.sdc_run_catalog import query_vnfpackage_by_id
from lcm.pub.utils.values import ignore_case_get
from lcm.ns_vnfs.const import SCALAR_UNIT_DICT
@@ -90,18 +89,19 @@ class GrantVnf(object):
break
req_param[grant_type].append(grant_res)
self.data = req_param
- tmp = resmgr.grant_vnf(self.data)
+ res = vim_connections_get(self.data)
vimConnections.append(
{
- "id": tmp["vim"]["vimId"],
- "vimId": tmp["vim"]["vimId"],
+ "id": res["vim"]["vimId"],
+ "vimId": res["vim"]["vimId"],
"vimType": None,
"interfaceInfo": None,
- "accessInfo": tmp["vim"]["accessInfo"],
+ "accessInfo": {
+ "tenant": res["vim"]["accessInfo"]["tenant"]
+ },
"extra": None
}
)
-
grant_resp = {
"id": str(uuid.uuid4()),
"vnfInstanceId": ignore_case_get(self.data, 'vnfInstanceId'),
@@ -112,7 +112,8 @@ class GrantVnf(object):
logger.debug("action_type=%s" % action_type)
if action_type == 'INSTANTIATE':
for i in range(18):
- offs = OOFDataModel.objects.filter(service_resource_id=ignore_case_get(self.data, "vnfInstanceId"))
+ offs = OOFDataModel.objects.filter(
+ service_resource_id=ignore_case_get(self.data, "vnfInstanceId"))
if not (offs.exists() and offs[0].vdu_info):
logger.debug("Cannot find oof data, retry%s" % (i + 1))
time.sleep(5)
@@ -145,7 +146,8 @@ class GrantVnf(object):
"numVirtualCpu": int(vdu["virtual_compute"]["virtual_cpu"]["num_virtual_cpu"])
},
"virtualMemory": {
- "virtualMemSize": parse_unit(vdu["virtual_compute"]["virtual_memory"]["virtual_mem_size"], "MB")
+ "virtualMemSize": parse_unit(
+ vdu["virtual_compute"]["virtual_memory"]["virtual_mem_size"], "MB")
}
},
"virtualStorageDescriptor": {
@@ -172,3 +174,33 @@ def parse_unit(val, base_unit):
return val.strip()
num, unit = num_unit[0], num_unit[1]
return int(num) * SCALAR_UNIT_DICT[unit.upper()] / SCALAR_UNIT_DICT[base_unit.upper()]
+
+
+def vim_connections_get(req_param):
+ vim_id = ""
+ if "vimId" in req_param:
+ vim_id = req_param["vimId"]
+ elif "additionalparam" in req_param and "vimid" in req_param["additionalparam"]:
+ vim_id = req_param["additionalparam"]["vimid"]
+ elif "additionalParams" in req_param and "vimid" in req_param["additionalParams"]:
+ vim_id = req_param["additionalParams"]["vimid"]
+ try:
+ from lcm.pub.msapi import extsys
+ vim = extsys.get_vim_by_id(vim_id)
+ if isinstance(vim, list):
+ vim = vim[0]
+ vim_id = vim["vimId"]
+ if "vimId" in vim:
+ vim_id = vim["vimId"]
+ rsp = {
+ "vim": {
+ "vimId": vim_id,
+ "accessInfo": {
+ "tenant": vim["tenant"]
+ }
+ }
+ }
+ logger.debug("rsp=%s" % rsp)
+ return rsp
+ except:
+ raise NSLCMException('Failed to get vimConnections info')
diff --git a/lcm/ns_vnfs/biz/grant_vnfs.py b/lcm/ns_vnfs/biz/grant_vnfs.py
index fac73439..421b383d 100644
--- a/lcm/ns_vnfs/biz/grant_vnfs.py
+++ b/lcm/ns_vnfs/biz/grant_vnfs.py
@@ -13,13 +13,16 @@
# limitations under the License.
import json
+
import logging
+from lcm.ns_vnfs.biz.grant_vnf import vim_connections_get
from lcm.pub.database.models import NfInstModel
from lcm.pub.exceptions import NSLCMException
-from lcm.pub.msapi import resmgr
+
from lcm.pub.msapi.sdc_run_catalog import query_vnfpackage_by_id
from lcm.pub.utils.values import ignore_case_get
+
from lcm.ns_vnfs.const import SCALAR_UNIT_DICT
logger = logging.getLogger(__name__)
@@ -88,7 +91,7 @@ class GrantVnfs(object):
break
req_param[grant_type].append(grant_res)
self.data = req_param
- return resmgr.grant_vnf(self.data)
+ return vim_connections_get(self.data)
def get_res_tpl(self, vdu, vnfd):
storage_size = 0
diff --git a/lcm/ns_vnfs/biz/terminate_nfs.py b/lcm/ns_vnfs/biz/terminate_nfs.py
index c663669b..8d648791 100644
--- a/lcm/ns_vnfs/biz/terminate_nfs.py
+++ b/lcm/ns_vnfs/biz/terminate_nfs.py
@@ -20,7 +20,6 @@ import traceback
from lcm.pub.config.config import REPORT_TO_AAI
from lcm.pub.database.models import NfInstModel, VmInstModel, OOFDataModel, PortInstModel
from lcm.pub.exceptions import NSLCMException
-from lcm.pub.msapi import resmgr
from lcm.pub.msapi.aai import query_vnf_aai, delete_vnf_aai, query_vserver_aai, delete_vserver_aai
from lcm.pub.msapi.extsys import split_vim_to_owner_region, get_vim_by_id
from lcm.pub.msapi.vnfmdriver import send_nf_terminate_request
@@ -57,7 +56,6 @@ class TerminateVnfs(threading.Thread):
self.check_nf_valid()
self.send_nf_terminate_to_vnfmDriver()
self.wait_vnfm_job_finish()
- # self.send_terminate_vnf_to_resMgr()
if REPORT_TO_AAI:
self.delete_vserver_in_aai()
self.delete_vnf_in_aai()
@@ -121,9 +119,6 @@ class TerminateVnfs(threading.Thread):
rsp = send_nf_terminate_request(self.vnfm_inst_id, self.vnf_uuid, req_param)
self.vnfm_job_id = ignore_case_get(rsp, 'jobId')
- def send_terminate_vnf_to_resMgr(self):
- resmgr.terminate_vnf(self.vnf_inst_id)
-
def wait_vnfm_job_finish(self):
if not self.vnfm_job_id:
logger.warn("No Job, need not wait")
diff --git a/lcm/ns_vnfs/tests/tests.py b/lcm/ns_vnfs/tests/tests.py
index e67c0d5e..a88e05dd 100644
--- a/lcm/ns_vnfs/tests/tests.py
+++ b/lcm/ns_vnfs/tests/tests.py
@@ -19,6 +19,7 @@ import mock
from django.test import TestCase, Client
from rest_framework import status
+from lcm.ns_vnfs.biz.grant_vnfs import GrantVnfs
from lcm.pub.database.models import VLInstModel, NfInstModel, JobModel, NSInstModel, VmInstModel, \
OOFDataModel, VNFCInstModel, PortInstModel, CPInstModel, SubscriptionModel
from lcm.pub.exceptions import NSLCMException
@@ -35,12 +36,10 @@ from lcm.ns_vnfs.biz.terminate_nfs import TerminateVnfs
from lcm.ns_vnfs.enum import VNF_STATUS, LIFE_CYCLE_OPERATION, RESOURCE_CHANGE_TYPE, VNFC_CHANGE_TYPE, \
INST_TYPE, NETWORK_RESOURCE_TYPE
from lcm.ns_vnfs.biz.place_vnfs import PlaceVnfs
-from lcm.pub.msapi import resmgr
from lcm.ns_vnfs.tests.test_data import vnfm_info, vim_info, vnf_place_request
from lcm.ns_vnfs.tests.test_data import nf_package_info, nsd_model_dict, subscription_response_data
from lcm.ns_vnfs.biz.create_vnfs import CreateVnfs
-from lcm.ns_vnfs.biz import create_vnfs
-from lcm.ns_vnfs.biz.grant_vnfs import GrantVnfs
+from lcm.ns_vnfs.biz import create_vnfs, grant_vnf
from lcm.ns_vnfs.biz.update_vnfs import NFOperateService
from lcm.ns_vnfs.biz.verify_vnfs import VerifyVnfs
from lcm.ns.enum import OWNER_TYPE
@@ -866,7 +865,6 @@ class TestGrantVnfsViews(TestCase):
# }
# response = self.client.post(self.url, data=data)
# self.assertEqual(response.status_code, status.HTTP_201_CREATED)
-
@mock.patch.object(restcall, "call_req")
def test_nf_grant_view_when_add_resource(self, mock_call_req):
mock_vals = {
@@ -930,7 +928,7 @@ class TestGrantVnfViews(TestCase):
OOFDataModel.objects.all().delete()
NfInstModel.objects.all().delete()
- @mock.patch.object(resmgr, "grant_vnf")
+ @mock.patch.object(grant_vnf, "vim_connections_get")
def test_vnf_grant_view(self, mock_grant):
resmgr_grant_resp = {
"vim": {
@@ -949,7 +947,7 @@ class TestGrantVnfViews(TestCase):
self.assertEqual(response.data["vimAssets"]["computeResourceFlavours"][0]["vimFlavourId"], "flavor_id_001")
@mock.patch.object(restcall, "call_req")
- @mock.patch.object(resmgr, "grant_vnf")
+ @mock.patch.object(grant_vnf, "vim_connections_get")
def test_exec_grant_when_add_resources_success(self, mock_grant, mock_call_req):
mock_vals = {
"/api/catalog/v1/vnfpackages/package_id_001":
@@ -986,7 +984,7 @@ class TestGrantVnfViews(TestCase):
@mock.patch.object(time, "sleep")
@mock.patch.object(restcall, "call_req")
- @mock.patch.object(resmgr, "grant_vnf")
+ @mock.patch.object(grant_vnf, "vim_connections_get")
def test_exec_grant_when_add_resources_but_no_off(self, mock_grant, mock_call_req, mock_sleep):
NfInstModel(mnfinstid="add_resources_but_no_off", nfinstid="vnf_inst_id_002",
package_id="package_id_002").save()
@@ -1023,7 +1021,7 @@ class TestGrantVnfViews(TestCase):
}]
self.assertEqual(resp["vimConnections"], vimConnections)
- @mock.patch.object(resmgr, "grant_vnf")
+ @mock.patch.object(grant_vnf, "vim_connections_get")
def test_exec_grant_when_resource_template_in_add_resources(self, mock_grant):
resmgr_grant_resp = {
"vim": {
@@ -1041,7 +1039,7 @@ class TestGrantVnfViews(TestCase):
self.assertEqual(resp["vimAssets"]["computeResourceFlavours"][0]["vimFlavourId"], "flavor_id_001")
@mock.patch.object(restcall, "call_req")
- @mock.patch.object(resmgr, "grant_vnf")
+ @mock.patch.object(grant_vnf, "vim_connections_get")
def test_exec_grant_when_remove_resources_success(self, mock_grant, mock_call_req):
mock_vals = {
"/api/catalog/v1/vnfpackages/package_id_001":
@@ -1083,7 +1081,7 @@ class TestGrantVnfViews(TestCase):
@mock.patch.object(time, "sleep")
@mock.patch.object(restcall, "call_req")
- @mock.patch.object(resmgr, "grant_vnf")
+ @mock.patch.object(grant_vnf, "vim_connections_get")
def test_exec_grant_when_remove_resources_but_no_off(self, mock_grant, mock_call_req, mock_sleep):
NfInstModel(mnfinstid="remove_resources_but_no_off", nfinstid="vnf_inst_id_002", package_id="package_id_002",
vnfm_inst_id="vnfm_id_002").save()
@@ -1123,7 +1121,7 @@ class TestGrantVnfViews(TestCase):
}]
self.assertEqual(resp["vimConnections"], vimConnections)
- @mock.patch.object(resmgr, "grant_vnf")
+ @mock.patch.object(grant_vnf, "vim_connections_get")
def test_exec_grant_when_resource_template_in_remove_resources(self, mock_grant):
resmgr_grant_resp = {
"vim": {