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
21 from lcm.nf.const import GRANT_TYPE
23 logger = logging.getLogger(__name__)
26 def grant_resource(data, nf_inst_id, job_id, grant_type, vdus):
27 logger.info("Grant resource begin")
28 lifecycleOperration = grant_type
31 'vnfInstanceId': nf_inst_id,
32 'vnfDescriptorId': '',
33 'lifecycleOperation': lifecycleOperration,
34 'vnfLcmOpOccId': job_id,
36 'updateResources': [],
37 'removeResources': [],
38 'placementConstraints': [],
39 'additionalParams': {}
42 if grant_type == "Terminate":
47 'resDefId': str(res_index),
48 'resDesId': vdu.resouceid}
49 content_args['removeResources'].append(res_def)
51 content_args['additionalParams']['vimid'] = vdus[0].vimid
52 elif grant_type == "Instantiate":
53 vim_id = ignore_case_get(ignore_case_get(data, "additionalParams"), "vimId")
58 'resDefId': str(res_index),
59 'resDesId': ignore_case_get(vdu, "vdu_id")
61 content_args['addResources'].append(res_def)
63 content_args['additionalParams']['vimid'] = vim_id
64 elif grant_type == GRANT_TYPE.OPERATE:
69 'resDefId': str(res_index),
70 'resDesId': vdu.resouceid}
71 content_args['updateResources'].append(res_def)
73 content_args['additionalParams']['vimid'] = vdus[0].vimid
75 vnfInsts = NfInstModel.objects.filter(nfinstid=nf_inst_id)
76 content_args['additionalParams']['vnfmid'] = vnfInsts[0].vnfminstid
77 logger.info('Grant request data=%s' % content_args)
78 apply_result = apply_grant_to_nfvo(json.dumps(content_args))