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, StorageInstModel, VLInstModel, NetworkInstModel, VNFCInstModel, \
19 from lcm.pub.exceptions import NFLCMException
21 logger = logging.getLogger(__name__)
25 def __init__(self, data, instanceid=''):
26 self.vnf_inst_id = instanceid
29 def query_single_vnf(self):
30 vnf_inst = NfInstModel.objects.filter(nfinstid=self.vnf_inst_id)
31 if not vnf_inst.exists():
32 raise NFLCMException('VnfInst(%s) does not exist' % self.vnf_inst_id)
33 resp_data = self.fill_resp_data(vnf_inst[0])
36 def query_multi_vnf(self):
37 vnf_insts = NfInstModel.objects.all()
39 raise NFLCMException('VnfInsts does not exist')
41 for vnf_inst in vnf_insts:
42 resp_data.append(self.fill_resp_data(vnf_inst))
45 def fill_resp_data(self, vnf):
46 logger.info('Get the list of vloumes')
47 storage_inst = StorageInstModel.objects.filter(instid=vnf.nfinstid)
49 for s in storage_inst:
51 "virtualStorageInstanceId": s.storageid,
54 "resourceId": s.resouceid
58 logger.info('Get the VLInstModel of list.')
59 vl_inst = VLInstModel.objects.filter(ownerid=vnf.nfinstid)
62 net = NetworkInstModel.objects.filter(networkid=v.relatednetworkid)
64 raise NFLCMException('NetworkInst(%s) does not exist.' % v.relatednetworkid)
66 "virtualLinkInstanceId": v.vlinstanceid,
67 "virtualLinkDescId": v.vldid,
69 "vimId": net[0].vimid,
70 "resourceId": net[0].resouceid
74 logger.info('Get VNFCInstModel of list.')
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 storage = StorageInstModel.objects.filter(ownerid=vm[0].vmid)
83 raise NFLCMException('StorageInst(%s) does not exist.' % vm[0].vmid)
85 "vnfcInstanceId": vnfc.vnfcinstanceid,
89 "resourceId": vm[0].resouceid
91 "storageResourceIds": [s.storageid for s in storage]
93 vnfc_arr.append(vnfc_dic)
94 logger.info('Get the VimInstModel of list.')
95 vms = VmInstModel.objects.filter(instid=vnf.nfinstid)
102 "resouceid": vm.resouceid,
104 "nic_array": vm.nic_array,
105 "metadata": vm.metadata,
106 "volume_array": vm.volume_array,
107 "server_group": vm.server_group,
108 "availability_zone": vm.availability_zone,
109 "flavor_id": vm.flavor_id,
110 "security_groups": vm.security_groups,
111 "operationalstate": vm.operationalstate,
112 "insttype": vm.insttype,
113 "is_predefined": vm.is_predefined,
114 "create_time": vm.create_time,
118 vm_arr.append(vm_dic)
121 "vnfInstanceId": vnf.nfinstid,
122 "vnfInstanceName": vnf.nf_name,
123 "onboardedVnfPkgInfoId": vnf.package_id,
124 "vnfdVersion": vnf.version,
125 "vnfProvider": vnf.vendor,
126 "instantiatedVnfInfo": {
127 "flavourId": vnf.flavour_id,
128 "vnfState": vnf.status,
131 "extVirtualLink": [],
132 "monitoringParameters": {},
134 "vnfcResourceInfo": vnfc_arr,
135 "virtualLinkResourceInfo": vl_arr,
136 "virtualStorageResourceInfo": arr