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.')
42 for vnf_inst in vnf_insts:
43 resp_data.append(self.fill_resp_data(vnf_inst))
46 def fill_resp_data(self, vnf):
47 logger.info('Get storages')
48 storage_inst = StorageInstModel.objects.filter(instid=vnf.nfinstid)
50 for s in storage_inst:
54 "vimConnectionId": s.vimid,
55 "resourceId": s.resourceid
59 logger.info('Get networks')
60 vl_inst = VLInstModel.objects.filter(ownerid=vnf.nfinstid)
63 net = NetworkInstModel.objects.filter(networkid=v.relatednetworkid)
65 raise NFLCMException('NetworkInst(%s) does not exist.' % v.relatednetworkid)
68 "virtualLinkDescId": v.vldid,
70 "vimConnectionId": net[0].vimid,
71 "resourceId": net[0].resourceid
75 logger.info('Get vnfcs')
76 vnfc_insts = VNFCInstModel.objects.filter(instid=vnf.nfinstid)
78 for vnfc in vnfc_insts:
79 vm = VmInstModel.objects.filter(vmid=vnfc.vmid)
81 raise NFLCMException('VmInst(%s) does not exist.' % vnfc.vmid)
82 if vm[0].volume_array:
83 storage = StorageInstModel.objects.filter(resourceid__in=vm[0].volume_array)
87 "id": vnfc.vnfcinstanceid,
90 "vimConnectionId": vm[0].vimid,
91 "resourceId": vm[0].resourceid
93 "storageResourceIds": [s.storageid for s in storage]
95 vnfc_arr.append(vnfc_dic)
96 logger.info('Get vms')
100 "vnfInstanceName": vnf.nf_name,
101 "vnfInstanceDescription": vnf.nf_desc,
102 "vnfdId": vnf.vnfdid,
103 "vnfProvider": vnf.vendor,
104 "vnfProductName": vnf.netype,
105 "vnfSoftwareVersion": vnf.vnfSoftwareVersion,
106 "vnfdVersion": vnf.version,
107 "vnfPkgId": vnf.package_id,
108 "instantiationState": vnf.status,
109 "instantiatedVnfInfo": {
110 "flavourId": vnf.flavour_id,
111 "vnfState": "STARTED",
114 "extVirtualLinkInfo": [],
115 "monitoringParameters": [],
116 "vnfcResourceInfo": vnfc_arr,
117 "vnfVirtualLinkResourceInfo": vl_arr,
118 "virtualStorageResourceInfo": arr
121 logger.debug("vnf instance: %s", resp_data)