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, VmInstModel
19 from lcm.pub.msapi.gvnfmdriver import apply_grant_to_nfvo
21 logger = logging.getLogger(__name__)
24 def grant_resource(nf_inst_id, job_id):
25 logger.info("Grant resource begin")
27 'vnfInstanceId': nf_inst_id,
28 'vnfDescriptorId': '',
29 'lifecycleOperation': 'Terminate',
30 'vnfLcmOpOccId': job_id,
33 'placementConstraint': [],
37 vdus = VmInstModel.objects.filter(instid=nf_inst_id, is_predefined=1)
42 'resDefId': str(res_index),
43 'resDesId': vdu.resouceid}
44 content_args['removeResource'].append(res_def)
47 vnfInsts = NfInstModel.objects.filter(nfinstid=nf_inst_id)
48 content_args['additionalParam']['vnfmid'] = vnfInsts[0].vnfminstid
49 content_args['additionalParam']['vimid'] = vdus[0].vimid
50 logger.info('Grant request data=%s' % content_args)
51 apply_result = apply_grant_to_nfvo(json.dumps(content_args))
52 logger.info("Grant resource end, response: %s" % apply_result)