aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lcm/ns_sfcs/biz/delete_sfcs.py6
-rw-r--r--lcm/ns_sfcs/tests/test_sfcdetailview.py5
-rw-r--r--lcm/ns_vls/biz/create_vls.py37
-rw-r--r--lcm/ns_vls/biz/delete_vls.py6
-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
-rw-r--r--lcm/pub/msapi/resmgr.py126
10 files changed, 60 insertions, 239 deletions
diff --git a/lcm/ns_sfcs/biz/delete_sfcs.py b/lcm/ns_sfcs/biz/delete_sfcs.py
index 34d6cf20..f531b4ae 100644
--- a/lcm/ns_sfcs/biz/delete_sfcs.py
+++ b/lcm/ns_sfcs/biz/delete_sfcs.py
@@ -18,7 +18,7 @@ import traceback
from lcm.pub.database.models import FPInstModel, VNFFGInstModel
from lcm.pub.exceptions import NSLCMException
-from lcm.pub.msapi import extsys, resmgr, sdncdriver
+from lcm.pub.msapi import extsys, sdncdriver
logger = logging.getLogger(__name__)
@@ -36,7 +36,6 @@ class DeleteSfcs(object):
return {"result": 0, "detail": "sfc is not exist or has been already deleted"}
self.ns_inst_id = sfc_inst_info[0].nsinstid
self.delete_sfc_from_driver(sfc_inst_info[0])
- # self.delete_sfc_from_resmgr()
self.delete_sfc_from_db(sfc_inst_info)
return {"result": 0, "detail": "delete sfc success"}
except NSLCMException as e:
@@ -78,9 +77,6 @@ class DeleteSfcs(object):
self.delete_sfc_inst_id_in_vnffg()
sfc_inst_info.delete()
- def delete_sfc_from_resmgr(self):
- resmgr.delete_sfc(self.sfc_inst_id)
-
def delete_sfc_inst_id_in_vnffg(self):
for vnffg_info in VNFFGInstModel.objects.filter(nsinstid=self.ns_inst_id):
new_sfc_id_list = ""
diff --git a/lcm/ns_sfcs/tests/test_sfcdetailview.py b/lcm/ns_sfcs/tests/test_sfcdetailview.py
index 8059007c..02d6db38 100644
--- a/lcm/ns_sfcs/tests/test_sfcdetailview.py
+++ b/lcm/ns_sfcs/tests/test_sfcdetailview.py
@@ -19,7 +19,6 @@ from django.test import TestCase, Client
from rest_framework import status
from lcm.pub.msapi import sdncdriver
from lcm.pub.database.models import FPInstModel
-from lcm.pub.msapi import resmgr
class TestSfcDetailViews(TestCase):
@@ -44,13 +43,11 @@ class TestSfcDetailViews(TestCase):
@mock.patch.object(sdncdriver, "delete_flow_classifier")
@mock.patch.object(sdncdriver, "delete_port_pair_group")
@mock.patch.object(sdncdriver, "delete_port_pair")
- @mock.patch.object(resmgr, "delete_sfc")
- def test_sfc_delete_success(self, mock_delete_sfc, mock_delete_port_pair, mock_delete_port_pair_group, mock_delete_flow_classifier, mock_delete_port_chain, mock_get_sdn_controller_by_id):
+ def test_sfc_delete_success(self, mock_delete_port_pair, mock_delete_port_pair_group, mock_delete_flow_classifier, mock_delete_port_chain, mock_get_sdn_controller_by_id):
mock_delete_port_chain.return_value = None
mock_delete_flow_classifier.return_value = None
mock_delete_port_pair_group.return_value = None
mock_delete_port_pair.return_value = None
- mock_delete_sfc.return_value = None
mock_get_sdn_controller_by_id.return_value = json.loads('{"test":"test_name","url":"url_add"}')
sfc_inst_id = "10"
diff --git a/lcm/ns_vls/biz/create_vls.py b/lcm/ns_vls/biz/create_vls.py
index 1a65d889..c06fe876 100644
--- a/lcm/ns_vls/biz/create_vls.py
+++ b/lcm/ns_vls/biz/create_vls.py
@@ -21,7 +21,7 @@ from lcm.ns.enum import OWNER_TYPE
from lcm.pub.config.config import REPORT_TO_AAI
from lcm.pub.database.models import VLInstModel, NSInstModel, VNFFGInstModel
from lcm.pub.exceptions import NSLCMException
-from lcm.pub.msapi import extsys, resmgr
+from lcm.pub.msapi import extsys
from lcm.pub.msapi.aai import create_network_aai, create_subnet_aai
from lcm.pub.nfvi.vim import const
from lcm.pub.nfvi.vim import vimadaptor
@@ -55,7 +55,6 @@ class CreateVls(object):
try:
self.get_data()
self.create_vl_to_vim()
- # self.create_vl_to_resmgr()
self.save_vl_to_db()
if REPORT_TO_AAI:
self.create_network_aai()
@@ -140,40 +139,6 @@ class CreateVls(object):
raise NSLCMException("Send post vl request to vim failed.")
return vl_ret[1]
- def create_vl_to_resmgr(self):
- self.vim_id = json.JSONDecoder().decode(self.vim_id) if isinstance(self.vim_id, str) else self.vim_id
- vim_id = self.vim_id['cloud_owner'] + self.vim_id['cloud_regionid']
- req_param = {
- "vlInstanceId": self.vl_inst_id,
- "name": self.vl_profile.get("networkName", ""),
- "backendId": str(self.related_network_id),
- "isPublic": "True",
- "dcName": "",
- "vimId": str(vim_id),
- "vimName": self.vim_name,
- "physicialNet": self.vl_profile.get("physicalNetwork", ""),
- "nsId": self.owner_id,
- "nsName": self.ns_name,
- "description": self.description,
- "networkType": self.vl_profile.get("networkType", ""),
- "segmentation": str(self.vl_profile.get("segmentationId", "")),
- "mtu": str(self.vl_profile.get("mtu", "")),
- "vlanTransparent": str(self.vl_profile.get("vlanTransparent", "")),
- "routerExternal": self.route_external,
- "resourceProviderType": "",
- "resourceProviderId": "",
- "subnet_list": [{
- "subnet_name": self.vl_profile.get("networkName", ""), # self.vl_profile.get("initiationParameters").get("name", ""),
- "cidr": self.vl_profile.get("cidr", "192.168.0.0/24"),
- "ip_version": self.vl_profile.get("ip_version", const.IPV4),
- "enable_dhcp": self.vl_profile.get("dhcpEnabled", False),
- "gateway_ip": self.vl_profile.get("gatewayIp", ""),
- "dns_nameservers": self.vl_profile.get("dns_nameservers", ""),
- "host_routes": self.vl_profile.get("host_routes", "")
- }]
- }
- resmgr.create_vl(req_param)
-
def create_vl_inst_id_in_vnffg(self):
if "vnffgs" in self.context:
for vnffg_info in self.context["vnffgs"]:
diff --git a/lcm/ns_vls/biz/delete_vls.py b/lcm/ns_vls/biz/delete_vls.py
index 6424d4de..d96a1b29 100644
--- a/lcm/ns_vls/biz/delete_vls.py
+++ b/lcm/ns_vls/biz/delete_vls.py
@@ -19,7 +19,7 @@ import traceback
from lcm.pub.config.config import REPORT_TO_AAI
from lcm.pub.database.models import VLInstModel, VNFFGInstModel
from lcm.pub.exceptions import NSLCMException
-from lcm.pub.msapi import resmgr, extsys
+from lcm.pub.msapi import extsys
from lcm.pub.msapi.aai import query_network_aai, delete_network_aai
from lcm.pub.nfvi.vim import vimadaptor
@@ -44,7 +44,6 @@ class DeleteVls(object):
subnetwork_id_list = vl_inst_info[0].relatedsubnetworkid.split(",")
network_id = vl_inst_info[0].relatednetworkid
self.delete_vl_from_vim(vim_id, subnetwork_id_list, network_id)
- # self.delete_vl_from_resmgr()
if REPORT_TO_AAI:
self.delete_network_and_subnet_in_aai()
self.delete_vl_from_db(vl_inst_info)
@@ -74,9 +73,6 @@ class DeleteVls(object):
vim_api.delete_subnet(subnet_id=subnetwork_id)
vim_api.delete_network(network_id=network_id)
- def delete_vl_from_resmgr(self):
- resmgr.delete_vl(self.vl_inst_id)
-
def delete_vl_inst_id_in_vnffg(self):
for vnffg_info in VNFFGInstModel.objects.filter(nsinstid=self.ns_inst_id):
new_vl_id_list = ""
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": {
diff --git a/lcm/pub/msapi/resmgr.py b/lcm/pub/msapi/resmgr.py
deleted file mode 100644
index db2c5e20..00000000
--- a/lcm/pub/msapi/resmgr.py
+++ /dev/null
@@ -1,126 +0,0 @@
-# Copyright 2016 ZTE Corporation.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import json
-import logging
-
-from lcm.pub.exceptions import NSLCMException
-from lcm.pub.utils.restcall import req_by_msb
-
-logger = logging.getLogger(__name__)
-
-
-def create_vl(req_param):
- ret = req_by_msb("/api/resmgr/v1/vl", "POST", json.JSONEncoder().encode(req_param))
- if ret[0] != 0:
- logger.error("Failed to create vl to resmgr. detail is %s.", ret[1])
- # raise NSLCMException('Failed to create vl to resmgr.')
- # return json.JSONDecoder().decode(ret[1])
-
-
-def delete_vl(vl_inst_id):
- ret = req_by_msb("/api/resmgr/v1/vl/%s" % vl_inst_id, "DELETE")
- if ret[0] != 0:
- logger.error("Failed to delete vl(%s) to resmgr. detail is %s.", vl_inst_id, ret[1])
- # raise NSLCMException("Failed to delete vl(%s) to resmgr." % vl_inst_id)
-
-
-def delete_sfc(sfc_inst_id):
- ret = req_by_msb("/api/resmgr/v1/sfc/%s" % sfc_inst_id, "DELETE")
- if ret[0] != 0:
- logger.error("Failed to delete sfc(%s) to resmgr. detail is %s.", sfc_inst_id, ret[1])
- # raise NSLCMException("Failed to delete sfc(%s) to resmgr." % sfc_inst_id)
-
-
-def grant_vnf(req_param):
- grant_data = json.JSONEncoder().encode(req_param)
- ret = req_by_msb("/api/resmgr/v1/resource/grant", "PUT", grant_data)
- if ret[0] != 0:
- logger.error("Failed to grant vnf to resmgr. detail is %s.", ret[1])
- # raise NSLCMException('Failed to grant vnf to resmgr.')
- 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"]
- grant_rsp = {
- "vim": {
- "vimId": vim_id,
- "accessInfo": {
- "tenant": vim["tenant"]
- }
- }
- }
- logger.debug("grant_rsp=%s" % grant_rsp)
- return grant_rsp
- except:
- raise NSLCMException('Failed to grant vnf to resmgr.')
- return json.JSONDecoder().decode(ret[1])
-
-
-def create_vnf(data):
- uri = '/api/resmgr/v1/vnf'
- req_param = json.JSONEncoder().encode({
- 'orchVnfInstanceId': data['nf_inst_id'],
- 'vnfInstanceId': data['vnfm_nf_inst_id'],
- 'vnfInstanceName': data['vnf_inst_name'],
- 'nsId': data['ns_inst_id'],
- 'nsName': data['ns_inst_name'],
- 'vnfmId': data['vnfm_inst_id'],
- 'vnfmName': data['vnfm_inst_name'],
- 'vnfPackageName': data['vnfd_name'],
- 'vnfDescriptorName': data['vnfd_id'],
- 'jobId': data['job_id'],
- 'vnfStatus': data['nf_inst_status'],
- 'vnfType': data['vnf_type'],
- 'onboardingId': data['nf_package_id'],
- 'onboardingName': data['vnfd_name']})
-
- ret = req_by_msb(uri, "POST", req_param)
- if ret[0] != 0:
- logger.error('Send create VNF request to resmgr failed.')
- # raise NSLCMException('Send create VNF request to resmgr failed.')
-
-
-def create_vnf_creation_info(data):
- uri = '/api/resmgr/v1/vnfinfo'
- req_param = json.JSONEncoder().encode({
- 'vnfInstanceId': data['nf_inst_id'],
- 'nsId': data['ns_inst_id'],
- 'vnfmId': data['vnfm_inst_id'],
- 'vms': data['vms']})
-
- ret = req_by_msb(uri, "POST", req_param)
- if ret[0] > 0:
- logger.error('Send write vnf creation information to resmgr failed.')
- # raise NSLCMException('Send write vnf creation information to resmgr failed.')
-
-
-def terminate_vnf(vnf_inst_id):
- uri = '/api/resmgr/v1/vnf/%s' % vnf_inst_id
- req_param = {}
- ret = req_by_msb(uri, "DELETE", json.dumps(req_param))
- if ret[0] > 0:
- logger.error('Send terminate VNF request to resmgr failed.')
- # raise NSLCMException('Send terminate VNF request to resmgr failed.')