summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRuoyu <ruoyu.ying@intel.com>2018-11-22 01:52:07 +0000
committerRuoyu <ruoyu.ying@intel.com>2018-11-22 02:55:41 +0000
commitf25a9803a90847ba67c1cd984803512e2726e5da (patch)
tree2ee4edc58669ed522fe43fa57368127ed675a002
parentb34a2f798243bf8e008672fed3fe1a15de8d683b (diff)
Refine code for OOF-VFC interaction
* Changed data send inside homing request * Delete data while terminating vnf * Add conditions while granting vnf * Add customer information inside config * Changed primary key of NFVO_OOF_DATA table Change-Id: Id07386e1d24b3cda08812773b0ca041c3f60ab7e Issue-ID: VFC-941 Signed-off-by: Ruoyu <ruoyu.ying@intel.com>
-rw-r--r--lcm/ns_vnfs/biz/create_vnfs.py21
-rw-r--r--lcm/ns_vnfs/biz/grant_vnf.py33
-rw-r--r--lcm/ns_vnfs/biz/place_vnfs.py29
-rw-r--r--lcm/ns_vnfs/biz/terminate_nfs.py4
-rw-r--r--lcm/ns_vnfs/serializers/serializers.py2
-rw-r--r--lcm/ns_vnfs/tests/tests.py3
-rw-r--r--lcm/pub/config/config.py7
7 files changed, 58 insertions, 41 deletions
diff --git a/lcm/ns_vnfs/biz/create_vnfs.py b/lcm/ns_vnfs/biz/create_vnfs.py
index b1caa393..04cb3b8b 100644
--- a/lcm/ns_vnfs/biz/create_vnfs.py
+++ b/lcm/ns_vnfs/biz/create_vnfs.py
@@ -35,6 +35,7 @@ from lcm.pub.utils import restcall
from lcm.ns_vnfs.const import VNF_STATUS, NFVO_VNF_INST_TIMEOUT_SECOND, INST_TYPE, INST_TYPE_NAME
from lcm.ns_vnfs.biz.wait_job import wait_job_finish
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.ns_vnfs.biz.subscribe import SubscriptionCreation
logger = logging.getLogger(__name__)
@@ -231,7 +232,7 @@ class CreateVnfs(Thread):
def build_homing_request(self):
id = str(uuid.uuid4())
- callback_uri = " {vfcBaseUrl}/api/nslcm/v1/ns/placevnf"
+ callback_uri = "http://{vfcBaseUrl}/api/nslcm/v1/ns/placevnf"
IP = REG_TO_MSB_REG_PARAM["nodes"][0]["ip"]
PORT = REG_TO_MSB_REG_PARAM["nodes"][0]["port"]
vfcBaseUrl = IP + ':' + PORT
@@ -240,7 +241,7 @@ class CreateVnfs(Thread):
modelVersionId = "no-resourceModelVersionId"
nsInfo = NSInstModel.objects.filter(id=self.ns_inst_id)
placementDemand = {
- "resourceModuleName": self.vnf_inst_name,
+ "resourceModuleName": self.vnf_id,
"serviceResourceId": self.vnfm_nf_inst_id,
"resourceModelInfo": {
"modelInvariantId": modelInvariantId,
@@ -259,6 +260,16 @@ class CreateVnfs(Thread):
"timeout": 600
},
"placementInfo": {
+ "requestParameters": {
+ "customerLatitude": CUST_LAT,
+ "customerLongitude": CUST_LONG,
+ "customerName": CUST_NAME
+ },
+ "subscriberInfo": {
+ "globalSubscriberId": "",
+ "subscriberName": "",
+ "subscriberCommonSiteId": "",
+ },
"placementDemands": []
},
"serviceInfo": {
@@ -276,8 +287,8 @@ class CreateVnfs(Thread):
request_id=id,
transaction_id=id,
request_status="init",
- request_module_name=self.vnfm_nf_inst_id,
- service_resource_id=self.vnf_inst_name,
+ request_module_name=self.vnf_id,
+ service_resource_id=self.vnfm_nf_inst_id,
vim_id="",
cloud_owner="",
cloud_region_id="",
@@ -291,7 +302,7 @@ class CreateVnfs(Thread):
resources = "/api/oof/v1/placement"
resp = restcall.call_req(base_url=base_url, user=OOF_USER, passwd=OOF_PASSWD,
auth_type=restcall.rest_oneway_auth, resource=resources,
- method="POST", content=req_body, additional_headers="")
+ method="POST", content=json.dumps(req_body), additional_headers="")
resp_body = resp[-2]
resp_status = resp[-1]
if resp_body:
diff --git a/lcm/ns_vnfs/biz/grant_vnf.py b/lcm/ns_vnfs/biz/grant_vnf.py
index 0923eb15..f16382e7 100644
--- a/lcm/ns_vnfs/biz/grant_vnf.py
+++ b/lcm/ns_vnfs/biz/grant_vnf.py
@@ -15,6 +15,7 @@
import json
import logging
import uuid
+import time
from lcm.pub.database.models import NfInstModel, OOFDataModel
from lcm.pub.exceptions import NSLCMException
from lcm.pub.msapi.sdc_run_catalog import query_vnfpackage_by_id
@@ -34,6 +35,7 @@ class GrantVnf(object):
self.data = json.JSONDecoder().decode(self.data)
has_res_tpl = False
grant_type = None
+ action_type = ignore_case_get(self.data, "operation")
vimConnections = []
if ignore_case_get(self.data, "addResources"):
grant_type = "addResources"
@@ -106,18 +108,25 @@ class GrantVnf(object):
"vimConnections": vimConnections
}
- offs = OOFDataModel.objects.filter(service_resource_id=ignore_case_get(self.data, "vnfInstanceId"))
- if offs.exists():
- vdu_info = json.loads(offs[0].vdu_info)
- grant_resp['vimAssets'] = {'computeResourceFlavours': []}
- for vdu in vdu_info:
- grant_resp['vimAssets']['computeResourceFlavours'].append({
- 'vimConnectionId': offs[0].vim_id,
- 'resourceProviderId': vdu.get("vduName"),
- 'vnfdVirtualComputeDescId': None, # TODO: required
- 'vimFlavourId': vdu.get("flavorName")
- })
- # grant_resp['additionalparams'][off.vim_id] = off.directive
+ 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"))
+ if not (offs.exists() and offs[0].vdu_info):
+ logger.debug("Cannot find oof data, retry%s" % (i + 1))
+ time.sleep(5)
+ continue
+ vdu_info = json.loads(offs[0].vdu_info)
+ grant_resp['vimAssets'] = {'computeResourceFlavours': []}
+ for vdu in vdu_info:
+ grant_resp['vimAssets']['computeResourceFlavours'].append({
+ 'vimConnectionId': offs[0].vim_id,
+ 'resourceProviderId': vdu.get("vduName"),
+ 'vnfdVirtualComputeDescId': None, # TODO: required
+ 'vimFlavourId': vdu.get("flavorName")
+ })
+ # grant_resp['additionalparams'][off.vim_id] = off.directive
+ break
logger.debug("grant_resp=%s", grant_resp)
return grant_resp
diff --git a/lcm/ns_vnfs/biz/place_vnfs.py b/lcm/ns_vnfs/biz/place_vnfs.py
index e288f9dd..6f858127 100644
--- a/lcm/ns_vnfs/biz/place_vnfs.py
+++ b/lcm/ns_vnfs/biz/place_vnfs.py
@@ -26,14 +26,12 @@ class PlaceVnfs(object):
self.data = data
self.placements = ""
self.request_id = data.get("requestId")
- self.transaction_id = data.get("transactionId")
def validateCallbackResponse(self):
if self.data == "":
logger.error("Error occurred in Homing: OOF Async Callback Response is empty")
return False
- if self.data.get('requestStatus') == "completed" and self.data.get("requestId") \
- and self.data.get("transactionId"):
+ if self.data.get('requestStatus') == "completed" and self.data.get("requestId"):
if self.data.get("solutions").get("placementSolutions") is not None:
self.placements = self.data.get("solutions").get("placementSolutions")
logger.debug("Got placement solutions in OOF Async Callback response")
@@ -58,19 +56,17 @@ class PlaceVnfs(object):
vim_info = {}
if not self.validateCallbackResponse():
logger.error("OOF request Failed")
- self.update_response_to_db(self.request_id, self.transaction_id,
- self.data.get("requestStatus"), "none", "none", "none", "none")
+ self.update_response_to_db(self.request_id, self.data.get("requestStatus"), "none", "none",
+ "none", "none")
return
if self.placements == [] or self.placements == [[]]:
logger.debug("No solution found for request %s " % self.request_id)
- self.update_response_to_db(self.request_id, self.transaction_id,
- self.data.get("requestStatus"), "none", "none",
+ self.update_response_to_db(self.request_id, self.data.get("requestStatus"), "none", "none",
"none", "none")
return
for item in self.placements:
if not isinstance(item, list):
- self.update_response_to_db(self.request_id, self.transaction_id,
- self.data.get("requestStatus"), "none", "none",
+ self.update_response_to_db(self.request_id, self.data.get("requestStatus"), "none", "none",
"none", "none")
continue
for placement in item:
@@ -79,10 +75,8 @@ class PlaceVnfs(object):
logger.debug(
"No assignment info/Solution inside Homing response for request %s"
% self.request_id)
- self.update_response_to_db(self.request_id,
- self.transaction_id,
- self.data.get("requestStatus"), "none", "none", "none",
- "none")
+ self.update_response_to_db(self.request_id, self.data.get("requestStatus"), "none", "none",
+ "none", "none")
continue
for info in assignmentInfo:
if info.get("key") in params:
@@ -90,7 +84,6 @@ class PlaceVnfs(object):
if not vim_info.get("oof_directives"):
logger.warn("Missing flavor info as no directive found in response")
self.update_response_to_db(self.request_id,
- self.transaction_id,
self.data.get("requestStatus"), "none", "none",
"none", "none")
continue
@@ -98,7 +91,6 @@ class PlaceVnfs(object):
vim_info['oof_directives'])
if not vduinfo:
self.update_response_to_db(self.request_id,
- self.transaction_id,
self.data.get("requestStatus"), "none", "none",
"none", "none")
return
@@ -109,14 +101,12 @@ class PlaceVnfs(object):
location_id = vim_info.get("locationId")
if not cloud_owner or not location_id:
self.update_response_to_db(self.request_id,
- self.transaction_id,
self.data.get("requestStatus"), "none", "none",
"none", "none")
return
vim_id = vim_info['vimId'] if vim_info.get('vimId') \
else cloud_owner + "_" + location_id
self.update_response_to_db(requestId=self.request_id,
- transactionId=self.transaction_id,
requestStatus=self.data.get("requestStatus"),
vimId=vim_id,
cloudOwner=cloud_owner,
@@ -153,10 +143,9 @@ class PlaceVnfs(object):
logger.warn("No OOF directive for VDU")
return None
- def update_response_to_db(self, requestId, transactionId, requestStatus, vimId, cloudOwner,
+ def update_response_to_db(self, requestId, requestStatus, vimId, cloudOwner,
cloudRegionId, vduInfo):
- OOFDataModel.objects.filter(request_id=requestId,
- transaction_id=transactionId).update(
+ OOFDataModel.objects.filter(request_id=requestId).update(
request_status=requestStatus,
vim_id=vimId,
cloud_owner=cloudOwner,
diff --git a/lcm/ns_vnfs/biz/terminate_nfs.py b/lcm/ns_vnfs/biz/terminate_nfs.py
index 7cdea1c8..073f2562 100644
--- a/lcm/ns_vnfs/biz/terminate_nfs.py
+++ b/lcm/ns_vnfs/biz/terminate_nfs.py
@@ -18,7 +18,7 @@ import threading
import traceback
from lcm.pub.config.config import REPORT_TO_AAI
-from lcm.pub.database.models import NfInstModel, VmInstModel
+from lcm.pub.database.models import NfInstModel, VmInstModel, OOFDataModel
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
@@ -140,6 +140,8 @@ class TerminateVnfs(threading.Thread):
def delete_data_from_db(self):
NfInstModel.objects.filter(nfinstid=self.vnf_inst_id).delete()
+ VmInstModel.objects.filter(instid=self.vnf_inst_id).delete()
+ OOFDataModel.objects.filter(service_resource_id=self.vnf_inst_id).delete()
JobUtil.add_job_status(self.job_id, 100, 'vnf terminate success', 0)
def delete_vnf_in_aai(self):
diff --git a/lcm/ns_vnfs/serializers/serializers.py b/lcm/ns_vnfs/serializers/serializers.py
index d9d6fa06..b588cf1e 100644
--- a/lcm/ns_vnfs/serializers/serializers.py
+++ b/lcm/ns_vnfs/serializers/serializers.py
@@ -301,7 +301,7 @@ class SolutionSerializer(serializers.Serializer):
allow_empty=True,
many=True)
licenseSolutions = LicenseSolutionSerializer(help_text="A list of License Solutions",
- required=True, many=True)
+ required=False, many=True)
class PlaceVnfReqSerializer(serializers.Serializer):
diff --git a/lcm/ns_vnfs/tests/tests.py b/lcm/ns_vnfs/tests/tests.py
index 422182ad..02fa2f82 100644
--- a/lcm/ns_vnfs/tests/tests.py
+++ b/lcm/ns_vnfs/tests/tests.py
@@ -943,7 +943,8 @@ class TestGrantVnfViews(TestCase):
self.vnf_inst_id = str(uuid.uuid4())
self.data = {
"vnfInstanceId": self.vnf_inst_id,
- "vnfLcmOpOccId": "1234"
+ "vnfLcmOpOccId": "1234",
+ "operation": "INSTANTIATE"
}
vdu_info_dict = [{"vduName": "vg", "flavorName": "flavor_1", "directive": []}]
OOFDataModel(request_id='1234', transaction_id='1234', request_status='done', request_module_name='vg',
diff --git a/lcm/pub/config/config.py b/lcm/pub/config/config.py
index 5ba41e98..3e64583f 100644
--- a/lcm/pub/config/config.py
+++ b/lcm/pub/config/config.py
@@ -70,6 +70,11 @@ DEPLOY_WORKFLOW_WHEN_START = False
WORKFLOW_OPTION = "buildin"
# [OOF config]
-OOF_BASE_URL = "http://oof.api.simpledemo.onap.org:8698"
+OOF_BASE_URL = "http://oof-osdf.onap.org:8698"
OOF_USER = "vfc_test"
OOF_PASSWD = "vfc_testpwd"
+
+# [Customer information]
+CUST_NAME = "some_company"
+CUST_LAT = "32.897480"
+CUST_LONG = "97.040443"