diff options
author | Fu Jinhua <fu.jinhua@zte.com.cn> | 2019-03-25 01:06:29 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-03-25 01:06:29 +0000 |
commit | 836cd28dbf538568e4e6e8c0ad2ef4c0ec7c6f88 (patch) | |
tree | 9cc762b344594c1aa4a16d67ce54183fa411ae2a | |
parent | d0d8419dae9fd772117102833ac5d918876c8d0d (diff) | |
parent | e5882b40abfb595499b31a1cc57884094dc072b0 (diff) |
Merge "get ns instance"
-rw-r--r-- | lcm/ns/biz/ns_get.py | 67 | ||||
-rw-r--r-- | lcm/ns/serializers/sol/ns_instance.py | 1 | ||||
-rw-r--r-- | lcm/ns/views/sol/instantiate_ns_views.py | 6 | ||||
-rw-r--r-- | lcm/ns/views/sol/ns_instances_views.py | 44 |
4 files changed, 91 insertions, 27 deletions
diff --git a/lcm/ns/biz/ns_get.py b/lcm/ns/biz/ns_get.py index 1d6bbb11..42ab9535 100644 --- a/lcm/ns/biz/ns_get.py +++ b/lcm/ns/biz/ns_get.py @@ -25,39 +25,86 @@ class GetNSInfoService(object): def __init__(self, ns_filter=None): self.ns_filter = ns_filter - def get_ns_info(self): + def get_ns_info(self, is_sol=False): ns_insts = None if self.ns_filter and "ns_inst_id" in self.ns_filter: ns_inst_id = self.ns_filter["ns_inst_id"] ns_insts = NSInstModel.objects.filter(id=ns_inst_id) else: ns_insts = NSInstModel.objects.all() + return [self.get_single_ns_info(ns_inst, is_sol) for ns_inst in ns_insts] - return [self.get_single_ns_info(ns_inst) for ns_inst in ns_insts] - - def get_single_ns_info(self, ns_inst): + def get_single_ns_info(self, ns_inst, is_sol=False): + if is_sol: + return { + 'id': ns_inst.id, + 'nsInstanceName': ns_inst.name, + 'nsInstanceDescription': ns_inst.description, + 'nsdId': ns_inst.nsd_id, + 'nsdInvariantId': ns_inst.nsd_invariant_id, + 'nsdInfoId': ns_inst.nspackage_id, + 'flavourId': ns_inst.flavour_id, + 'nsState': ns_inst.status, + # todo 'nsScaleStatus':{} + # todo 'additionalAffinityOrAntiAffinityRule':{} + 'vnfInstance': self.get_vnf_infos(ns_inst.id, is_sol), + # todo 'pnfInfo': self.get_pnf_infos(ns_inst.id,is_sol), + 'virtualLinkInfo': self.get_vl_infos(ns_inst.id, is_sol), + # todo 'vnffgInfo': self.get_vnffg_infos(ns_inst.id, ns_inst.nsd_model), + # todo 'sapInfo':{}, + # todo nestedNsInstanceId + } return { 'nsInstanceId': ns_inst.id, 'nsName': ns_inst.name, 'description': ns_inst.description, 'nsdId': ns_inst.nsd_id, 'nsdInvariantId': ns_inst.nsd_invariant_id, - 'vnfInfo': self.get_vnf_infos(ns_inst.id), + 'vnfInfo': self.get_vnf_infos(ns_inst.id, is_sol), 'pnfInfo': self.get_pnf_infos(ns_inst.id), - 'vlInfo': self.get_vl_infos(ns_inst.id), - 'vnffgInfo': self.get_vnffg_infos(ns_inst.id, ns_inst.nsd_model), + 'vlInfo': self.get_vl_infos(ns_inst.id, is_sol), + 'vnffgInfo': self.get_vnffg_infos(ns_inst.id, ns_inst.nsd_model, is_sol), 'nsState': ns_inst.status} @staticmethod - def get_vnf_infos(ns_inst_id): + def get_vnf_infos(ns_inst_id, is_sol): vnfs = NfInstModel.objects.filter(ns_inst_id=ns_inst_id) + if is_sol: + return [{ + 'id': vnf.nfinstid, + 'vnfInstanceName': vnf.nf_name, + 'vnfdId': vnf.template_id, + 'vnfProvider': vnf.vendor, + 'vnfSoftwareVersion': vnf.version, + 'vnfProductName': vnf.nf_name, # todo + 'vnfdVersion': vnf.version, # todo + 'vnfPkgId': vnf.package_id, + 'instantiationState': vnf.status + } for vnf in vnfs] return [{ 'vnfInstanceId': vnf.nfinstid, 'vnfInstanceName': vnf.nf_name, 'vnfProfileId': vnf.vnf_id} for vnf in vnfs] - def get_vl_infos(self, ns_inst_id): + def get_vl_infos(self, ns_inst_id, is_sol): vls = VLInstModel.objects.filter(ownertype=OWNER_TYPE.NS, ownerid=ns_inst_id) + if is_sol: + return [ + { + 'id': vl.vlinstanceid, + 'nsVirtualLinkDescId': vl.vldid, + 'nsVirtualLinkProfileId': vl.vldid, + 'vlInstanceName': vl.vlinstancename, + 'resourceHandle': { + 'vimId': vl.vimId, + 'resourceId': vl.relatednetworkid, + 'vimLevelResourceType': vl.vltype + }, + # todo 'linkPort': self.get_cp_infos(vl.vlinstanceid,is_sol), + 'networkId': vl.relatednetworkid, + 'subNetworkid': vl.relatedsubnetworkid + } for vl in vls] + return [{ 'vlInstanceId': vl.vlinstanceid, 'vlInstanceName': vl.vlinstancename, @@ -72,7 +119,7 @@ class GetNSInfoService(object): 'cpInstanceName': cp.cpname, 'cpdId': cp.cpdid} for cp in cps] - def get_vnffg_infos(self, ns_inst_id, nsd_model): + def get_vnffg_infos(self, ns_inst_id, nsd_model, is_sol): vnffgs = VNFFGInstModel.objects.filter(nsinstid=ns_inst_id) return [{ 'vnffgInstanceId': vnffg.vnffginstid, diff --git a/lcm/ns/serializers/sol/ns_instance.py b/lcm/ns/serializers/sol/ns_instance.py index 73340bf5..6140654e 100644 --- a/lcm/ns/serializers/sol/ns_instance.py +++ b/lcm/ns/serializers/sol/ns_instance.py @@ -641,6 +641,7 @@ class NsInstanceSerializer(serializers.Serializer): nsScaleStatus = NsScaleInfoSerializer( help_text="Status of each NS scaling aspect declared in the applicable DF.", required=False, + allow_null=True, many=True) additionalAffinityOrAntiAffinityRule = AffinityOrAntiAffinityRuleSerializer( many=True, diff --git a/lcm/ns/views/sol/instantiate_ns_views.py b/lcm/ns/views/sol/instantiate_ns_views.py index ed43b94c..c19becea 100644 --- a/lcm/ns/views/sol/instantiate_ns_views.py +++ b/lcm/ns/views/sol/instantiate_ns_views.py @@ -22,9 +22,3 @@ class InstantiateNsView(APIView): def post(self, request, ns_instance_id): # todo return - - -class TerminateNsView(APIView): - def post(self, request, ns_instance_id): - # todo - return diff --git a/lcm/ns/views/sol/ns_instances_views.py b/lcm/ns/views/sol/ns_instances_views.py index 310ff098..cc832439 100644 --- a/lcm/ns/views/sol/ns_instances_views.py +++ b/lcm/ns/views/sol/ns_instances_views.py @@ -26,6 +26,7 @@ from lcm.pub.exceptions import BadRequestException, NSLCMException from lcm.pub.utils.values import ignore_case_get from lcm.ns.biz.ns_create import CreateNSService from lcm.ns.biz.ns_get import GetNSInfoService +from lcm.ns.biz.ns_delete import DeleteNsService logger = logging.getLogger(__name__) @@ -42,7 +43,7 @@ class NSInstancesView(APIView): logger.debug(request.query_params) try: logger.debug("CreateNSView::get") - ret = GetNSInfoService().get_ns_info() # todo + ret = GetNSInfoService().get_ns_info(is_sol=True) # todo logger.debug("CreateNSView::get::ret=%s", ret) resp_serializer = NsInstanceSerializer(data=ret, many=True) if not resp_serializer.is_valid(): @@ -51,7 +52,8 @@ class NSInstancesView(APIView): except Exception as e: logger.error(traceback.format_exc()) logger.error("Exception in GetNS: %s", e.message) - return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + data = {'status': status.HTTP_500_INTERNAL_SERVER_ERROR, 'detail': e.message} + return Response(data=data, status=status.HTTP_500_INTERNAL_SERVER_ERROR) @swagger_auto_schema( request_body=CreateNsRequestSerializer(), @@ -63,7 +65,7 @@ class NSInstancesView(APIView): def post(self, request): logger.debug("Enter NSInstancesView::POST ns_instances: Header:%s, Body: %s" % (request.META, request.data)) try: - globalCustomerId = request.META.get("HTTP_GLOBALCUSTOMERID ", None) + globalCustomerId = request.META.get("HTTP_GLOBALCUSTOMERID", None) if not globalCustomerId: raise BadRequestException("Not found globalCustomerId in header") req_serializer = CreateNsRequestSerializer(data=request.data) @@ -82,7 +84,7 @@ class NSInstancesView(APIView): ns_inst_id = CreateNSService(csar_id, ns_name, description, context).do_biz() logger.debug("CreateNSView::post::ret={'nsInstanceId':%s}", ns_inst_id) ns_filter = {"ns_inst_id": ns_inst_id} - nsInstance = GetNSInfoService(ns_filter).get_ns_info()[0] # todo + nsInstance = GetNSInfoService(ns_filter).get_ns_info(is_sol=True)[0] # todo resp_serializer = NsInstanceSerializer(data=nsInstance) if not resp_serializer.is_valid(): raise NSLCMException(resp_serializer.errors) @@ -101,14 +103,28 @@ class IndividualNsInstanceView(APIView): @swagger_auto_schema( request_body=None, responses={ - status.HTTP_200_OK: NsInstanceSerializer(help_text="NS instances", many=True), + status.HTTP_200_OK: NsInstanceSerializer(help_text="NS instances", many=False), status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error" } ) def get(self, request, ns_instance_id): - logger.debug("Enter IndividualNsInstanceView::get ns(%s)", ns_instance_id) - # todo - return Response(data={}, status=status.HTTP_200_OK) + try: + logger.debug("Enter NSDetailView::get ns(%s)", ns_instance_id) + ns_filter = {"ns_inst_id": ns_instance_id} + ret = GetNSInfoService(ns_filter).get_ns_info(is_sol=True) + if not ret: + data = {'status': status.HTTP_404_NOT_FOUND, 'detail': "NS Instance ID(%s) is not founded" % ns_instance_id} + return Response(data=data, status=status.HTTP_404_NOT_FOUND) + logger.debug("Leave NSDetailView::get::ret=%s", ret) + resp_serializer = NsInstanceSerializer(data=ret[0]) + if not resp_serializer.is_valid(): + raise NSLCMException(resp_serializer.errors) + return Response(data=resp_serializer.data, status=status.HTTP_200_OK) + except Exception as e: + logger.error(traceback.format_exc()) + logger.error("Exception in GetNSDetail: %s", e.message) + data = {'status': status.HTTP_500_INTERNAL_SERVER_ERROR, 'detail': e.message} + return Response(data=data, status=status.HTTP_500_INTERNAL_SERVER_ERROR) @swagger_auto_schema( request_body=None, @@ -117,6 +133,12 @@ class IndividualNsInstanceView(APIView): } ) def delete(self, request, ns_instance_id): - logger.debug("Enter IndividualNsInstanceView::DELETE ns_instance(%s)", ns_instance_id) - # todo - return Response(data={}, status=status.HTTP_204_NO_CONTENT) + try: + logger.debug("Enter NSDetailView::delete ns(%s)", ns_instance_id) + DeleteNsService(ns_instance_id).do_biz() + return Response(data={}, status=status.HTTP_204_NO_CONTENT) + except Exception as e: + logger.error(traceback.format_exc()) + logger.error("Exception in delete NS: %s", e.message) + data = {'status': status.HTTP_500_INTERNAL_SERVER_ERROR, 'detail': e.message} + return Response(data=data, status=status.HTTP_500_INTERNAL_SERVER_ERROR) |