1 # Copyright 2017 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.
17 from lcm.pub.database.models import NfInstModel
18 from lcm.pub.database.models import StorageInstModel
19 from lcm.pub.database.models import VLInstModel
20 from lcm.pub.database.models import NetworkInstModel
21 from lcm.pub.database.models import VNFCInstModel
22 from lcm.pub.database.models import VmInstModel
23 from lcm.pub.exceptions import NFLCMException
25 logger = logging.getLogger(__name__)
29 def __init__(self, data, instanceid=''):
30 self.vnf_inst_id = instanceid
33 def query_single_vnf(self):
34 vnf_inst = NfInstModel.objects.filter(nfinstid=self.vnf_inst_id)
35 if not vnf_inst.exists():
36 raise NFLCMException('VnfInst(%s) does not exist.' % self.vnf_inst_id)
37 return self.fill_resp_data(vnf_inst[0])
39 def query_multi_vnf(self):
40 vnf_insts = NfInstModel.objects.all()
41 return [self.fill_resp_data(vnf_inst) for vnf_inst in vnf_insts]
43 def fill_resp_data(self, vnf):
44 logger.info('Get storages')
45 storage_inst = StorageInstModel.objects.filter(instid=vnf.nfinstid)
47 for s in storage_inst:
51 "vimConnectionId": s.vimid,
52 "resourceId": s.resourceid
57 logger.info('Get networks')
58 vl_inst = VLInstModel.objects.filter(ownerid=vnf.nfinstid)
61 net = NetworkInstModel.objects.filter(networkid=v.relatednetworkid)
63 raise NFLCMException('NetworkInst(%s) does not exist.' % v.relatednetworkid)
66 "virtualLinkDescId": v.vldid,
68 "vimConnectionId": net[0].vimid,
69 "resourceId": net[0].resourceid
74 logger.info('Get vnfcs')
75 vnfc_insts = VNFCInstModel.objects.filter(instid=vnf.nfinstid)
77 for vnfc in vnfc_insts:
78 vm = VmInstModel.objects.filter(vmid=vnfc.vmid)
80 raise NFLCMException('VmInst(%s) does not exist.' % vnfc.vmid)
81 if vm[0].volume_array:
82 storage = StorageInstModel.objects.filter(resourceid__in=vm[0].volume_array)
86 "id": vnfc.vnfcinstanceid,
89 "vimConnectionId": vm[0].vimid,
90 "resourceId": vm[0].resourceid
92 "storageResourceIds": [s.storageid for s in storage]
94 vnfc_arr.append(vnfc_dic)
98 "vnfInstanceName": vnf.nf_name,
99 "vnfInstanceDescription": vnf.nf_desc,
100 "vnfdId": vnf.vnfdid,
101 "vnfProvider": vnf.vendor,
102 "vnfProductName": vnf.netype,
103 "vnfSoftwareVersion": vnf.vnfSoftwareVersion,
104 "vnfdVersion": vnf.version,
105 "vnfPkgId": vnf.package_id,
106 "instantiationState": vnf.status,
107 "instantiatedVnfInfo": {
108 "flavourId": vnf.flavour_id,
109 "vnfState": "STARTED",
112 "extVirtualLinkInfo": [],
113 "monitoringParameters": [],
114 "vnfcResourceInfo": vnfc_arr,
115 "vnfVirtualLinkResourceInfo": vl_arr,
116 "virtualStorageResourceInfo": arr
119 logger.debug("vnf instance: %s", resp_data)