summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFu Jinhua <fu.jinhua@zte.com.cn>2018-08-16 02:37:53 +0000
committerGerrit Code Review <gerrit@onap.org>2018-08-16 02:37:53 +0000
commit158a6e301d83cc24511cb7c55d8d87d45b734c03 (patch)
tree9f4c47f523b48657026dde41834c3e0cbc24910e
parentbd2d965471ca2a5a05c9b61fc4379e63c2a43547 (diff)
parent92409cd57ac408d82d77e4e9b7a5be9dd0765754 (diff)
Merge "Change in terminate"
-rw-r--r--lcm/lcm/nf/biz/grant_vnf.py50
-rw-r--r--lcm/lcm/nf/biz/terminate_vnf.py6
2 files changed, 39 insertions, 17 deletions
diff --git a/lcm/lcm/nf/biz/grant_vnf.py b/lcm/lcm/nf/biz/grant_vnf.py
index cbfa88b0..268e8e4f 100644
--- a/lcm/lcm/nf/biz/grant_vnf.py
+++ b/lcm/lcm/nf/biz/grant_vnf.py
@@ -15,38 +15,56 @@
import json
import logging
-from lcm.pub.database.models import NfInstModel, VmInstModel
+from lcm.pub.database.models import NfInstModel
from lcm.pub.msapi.gvnfmdriver import apply_grant_to_nfvo
+from lcm.pub.utils.values import ignore_case_get
logger = logging.getLogger(__name__)
-def grant_resource(nf_inst_id, job_id):
+def grant_resource(data, nf_inst_id, job_id, grant_type, vdus):
logger.info("Grant resource begin")
+ if grant_type == "Terminate":
+ lifecycleOperration = "Terminate"
+ elif grant_type == "instantiate":
+ lifecycleOperration = "Instantiate"
+
content_args = {
'vnfInstanceId': nf_inst_id,
'vnfDescriptorId': '',
- 'lifecycleOperation': 'Terminate',
+ 'lifecycleOperation': lifecycleOperration,
'vnfLcmOpOccId': job_id,
- 'addResource': [],
- 'removeResource': [],
+ 'addResources': [],
+ 'removeResources': [],
'placementConstraint': [],
'additionalParam': {}
}
- vdus = VmInstModel.objects.filter(instid=nf_inst_id, is_predefined=1)
- res_index = 1
- for vdu in vdus:
- res_def = {
- 'type': 'VDU',
- 'resDefId': str(res_index),
- 'resDesId': vdu.resouceid}
- content_args['removeResource'].append(res_def)
- res_index += 1
+ if grant_type == "Terminate":
+ res_index = 1
+ for vdu in vdus:
+ res_def = {
+ 'type': 'VDU',
+ 'resDefId': str(res_index),
+ 'resDesId': vdu.resouceid}
+ content_args['removeResources'].append(res_def)
+ res_index += 1
+ content_args['additionalParam']['vimid'] = vdus[0].vimid
+ elif 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")
+ }
+ content_args['addResources'].append(res_def)
+ res_index += 1
+ content_args['additionalParam']['vimid'] = vim_id
vnfInsts = NfInstModel.objects.filter(nfinstid=nf_inst_id)
content_args['additionalParam']['vnfmid'] = vnfInsts[0].vnfminstid
- content_args['additionalParam']['vimid'] = vdus[0].vimid
logger.info('Grant request data=%s' % content_args)
apply_result = apply_grant_to_nfvo(json.dumps(content_args))
- logger.info("Grant resource end, response: %s" % apply_result)
+ return apply_result
diff --git a/lcm/lcm/nf/biz/terminate_vnf.py b/lcm/lcm/nf/biz/terminate_vnf.py
index 3327660e..5081422f 100644
--- a/lcm/lcm/nf/biz/terminate_vnf.py
+++ b/lcm/lcm/nf/biz/terminate_vnf.py
@@ -40,11 +40,15 @@ 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"
def run(self):
try:
if self.term_pre():
- grant_resource(nf_inst_id=self.nf_inst_id, job_id=self.job_id)
+ vdus = VmInstModel.objects.filter(instid=self.nf_inst_id, is_predefined=1)
+ apply_result = grant_resource(data=self.data, nf_inst_id=self.nf_inst_id, job_id=self.job_id,
+ grant_type=self.grant_type, vdus=vdus)
+ logger.info("Grant resource end, response: %s" % apply_result)
JobUtil.add_job_status(self.job_id, 20, 'Nf terminating grant_resource finish')
self.query_inst_resource()
self.query_notify_data()