import logging
-from lcm.pub.database.models import NfInstModel, StorageInstModel, VLInstModel, NetworkInstModel, VNFCInstModel, \
- VmInstModel
+from lcm.pub.database.models import NfInstModel
+from lcm.pub.database.models import StorageInstModel
+from lcm.pub.database.models import VLInstModel
+from lcm.pub.database.models import NetworkInstModel
+from lcm.pub.database.models import VNFCInstModel
+from lcm.pub.database.models import VmInstModel
from lcm.pub.exceptions import NFLCMException
logger = logging.getLogger(__name__)
def query_single_vnf(self):
vnf_inst = NfInstModel.objects.filter(nfinstid=self.vnf_inst_id)
if not vnf_inst.exists():
- raise NFLCMException('VnfInst(%s) does not exist' % self.vnf_inst_id)
- resp_data = self.fill_resp_data(vnf_inst[0])
- return resp_data
+ raise NFLCMException('VnfInst(%s) does not exist.' % self.vnf_inst_id)
+ return self.fill_resp_data(vnf_inst[0])
def query_multi_vnf(self):
vnf_insts = NfInstModel.objects.all()
- if not vnf_insts:
- raise NFLCMException('VnfInsts does not exist')
- resp_data = []
- for vnf_inst in vnf_insts:
- resp_data.append(self.fill_resp_data(vnf_inst))
- return resp_data
+ return [self.fill_resp_data(vnf_inst) for vnf_inst in vnf_insts]
def fill_resp_data(self, vnf):
logger.info('Get storages')
"id": s.storageid,
"storageResource": {
"vimConnectionId": s.vimid,
- "resourceId": s.resouceid
+ "resourceId": s.resourceid
}
}
arr.append(storage)
+
logger.info('Get networks')
vl_inst = VLInstModel.objects.filter(ownerid=vnf.nfinstid)
vl_arr = []
"virtualLinkDescId": v.vldid,
"networkResource": {
"vimConnectionId": net[0].vimid,
- "resourceId": net[0].resouceid
+ "resourceId": net[0].resourceid
}
}
vl_arr.append(v_dic)
+
logger.info('Get vnfcs')
vnfc_insts = VNFCInstModel.objects.filter(instid=vnf.nfinstid)
vnfc_arr = []
vm = VmInstModel.objects.filter(vmid=vnfc.vmid)
if not vm:
raise NFLCMException('VmInst(%s) does not exist.' % vnfc.vmid)
- storage = StorageInstModel.objects.filter(ownerid=vm[0].vmid)
- if not storage:
- raise NFLCMException('StorageInst(%s) does not exist.' % vm[0].vmid)
+ if vm[0].volume_array:
+ storage = StorageInstModel.objects.filter(resourceid__in=vm[0].volume_array)
+ else:
+ storage = []
vnfc_dic = {
"id": vnfc.vnfcinstanceid,
"vduId": vnfc.vduid,
"computeResource": {
"vimConnectionId": vm[0].vimid,
- "resourceId": vm[0].resouceid
+ "resourceId": vm[0].resourceid
},
"storageResourceIds": [s.storageid for s in storage]
}
vnfc_arr.append(vnfc_dic)
- logger.info('Get vms')
resp_data = {
"id": vnf.nfinstid,
"vnfInstanceName": vnf.nf_name,
- "vnfPkgId": vnf.package_id,
- "vnfdVersion": vnf.version,
+ "vnfInstanceDescription": vnf.nf_desc,
+ "vnfdId": vnf.vnfdid,
"vnfProvider": vnf.vendor,
+ "vnfProductName": vnf.netype,
+ "vnfSoftwareVersion": vnf.vnfSoftwareVersion,
+ "vnfdVersion": vnf.version,
+ "vnfPkgId": vnf.package_id,
"instantiationState": vnf.status,
"instantiatedVnfInfo": {
"flavourId": vnf.flavour_id,
"scaleStatus": [],
"extCpInfo": [],
"extVirtualLinkInfo": [],
- "monitoringParameters": {},
+ "monitoringParameters": [],
"vnfcResourceInfo": vnfc_arr,
"vnfVirtualLinkResourceInfo": vl_arr,
"virtualStorageResourceInfo": arr
}
}
+ logger.debug("vnf instance: %s", resp_data)
return resp_data