summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfujinhua <fu.jinhua@zte.com.cn>2019-04-23 16:15:47 +0800
committerfujinhua <fu.jinhua@zte.com.cn>2019-04-23 16:15:47 +0800
commit15c26e4666248b86df8116d532187260acf1b887 (patch)
treef12b52582db93dc397822fd0ddd9d40ca37aea36
parentc43fcb791d0b1f2de826e3e997b9680d6e2edca7 (diff)
Refactor codes for query vnf
Change-Id: I9f2d1986cc8eb5ce98a6c37e30ac8f6c35c1c720 Issue-ID: VFC-1306 Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r--lcm/lcm/nf/biz/query_vnf.py22
1 files changed, 10 insertions, 12 deletions
diff --git a/lcm/lcm/nf/biz/query_vnf.py b/lcm/lcm/nf/biz/query_vnf.py
index d460c03b..caada8f4 100644
--- a/lcm/lcm/nf/biz/query_vnf.py
+++ b/lcm/lcm/nf/biz/query_vnf.py
@@ -14,8 +14,12 @@
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__)
@@ -30,18 +34,11 @@ class QueryVnf:
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
+ 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 = []
- if vnf_insts:
- 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')
@@ -56,6 +53,7 @@ class QueryVnf:
}
}
arr.append(storage)
+
logger.info('Get networks')
vl_inst = VLInstModel.objects.filter(ownerid=vnf.nfinstid)
vl_arr = []
@@ -72,6 +70,7 @@ class QueryVnf:
}
}
vl_arr.append(v_dic)
+
logger.info('Get vnfcs')
vnfc_insts = VNFCInstModel.objects.filter(instid=vnf.nfinstid)
vnfc_arr = []
@@ -93,7 +92,6 @@ class QueryVnf:
"storageResourceIds": [s.storageid for s in storage]
}
vnfc_arr.append(vnfc_dic)
- logger.info('Get vms')
resp_data = {
"id": vnf.nfinstid,