1 # Copyright 2018 ZTE Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 from lcm.pub.database.models import NfInstModel
19 from lcm.pub.msapi.gvnfmdriver import apply_grant_to_nfvo
20 from lcm.pub.utils.values import ignore_case_get
22 logger = logging.getLogger(__name__)
25 def grant_resource(data, nf_inst_id, job_id, grant_type, vdus):
26 logger.info("Grant resource begin")
27 if grant_type == "Terminate":
28 lifecycleOperration = "Terminate"
29 elif grant_type == "Instantiate":
30 lifecycleOperration = "Instantiate"
33 'vnfInstanceId': nf_inst_id,
34 'vnfDescriptorId': '',
35 'lifecycleOperation': lifecycleOperration,
36 'vnfLcmOpOccId': job_id,
38 'removeResources': [],
39 'placementConstraints': [],
40 'additionalParams': {}
43 if grant_type == "Terminate":
48 'resDefId': str(res_index),
49 'resDesId': vdu.resouceid}
50 content_args['removeResources'].append(res_def)
52 content_args['additionalParams']['vimid'] = vdus[0].vimid
53 elif grant_type == "Instantiate":
54 vim_id = ignore_case_get(ignore_case_get(data, "additionalParams"), "vimId")
59 'resDefId': str(res_index),
60 'resDesId': ignore_case_get(vdu, "vdu_id")
62 content_args['addResources'].append(res_def)
64 content_args['additionalParams']['vimid'] = vim_id
66 vnfInsts = NfInstModel.objects.filter(nfinstid=nf_inst_id)
67 content_args['additionalParams']['vnfmid'] = vnfInsts[0].vnfminstid
68 logger.info('Grant request data=%s' % content_args)
69 apply_result = apply_grant_to_nfvo(json.dumps(content_args))