Ejemplo n.º 1
0
    def post(self, request):
        logger.debug("Enter CreateNS: %s", request.data)
        req_serializer = _CreateNsReqSerializer(data=request.data)
        if not req_serializer.is_valid():
            raise BadRequestException(req_serializer.errors)

        if ignore_case_get(request.data, 'test') == "test":
            return Response(data={'nsInstanceId': "test"},
                            status=status.HTTP_201_CREATED)
        csar_id = ignore_case_get(request.data, 'csarId')
        ns_name = ignore_case_get(request.data, 'nsName')
        description = ignore_case_get(request.data, 'description')
        context = ignore_case_get(request.data, 'context')
        ns_inst_id = CreateNSService(csar_id, ns_name, description,
                                     context).do_biz()

        logger.debug("CreateNSView::post::ret={'nsInstanceId':%s}", ns_inst_id)
        ret = {
            'nsInstanceId': ns_inst_id,
            'nsInstanceName': 'nsInstanceName',
            'nsInstanceDescription': 'nsInstanceDescription',
            'nsdId': 123,
            'nsdInfoId': 456,
            'nsState': 'NOT_INSTANTIATED',
            '_links': {
                'self': {
                    'href': 'href'
                }
            }
        }
        resp_serializer = _CreateNsRespSerializer(data=ret)
        if not resp_serializer.is_valid():
            raise NSLCMException(resp_serializer.errors)
        return Response(data=ret, status=status.HTTP_201_CREATED)
Ejemplo n.º 2
0
 def post(self, request, vnfinstid):
     logger.debug("NfScaleView--post::> %s" % request.data)
     try:
         req_serializer = ScaleVnfReqSerializer(data=request.data)
         if not req_serializer.is_valid():
             raise BadRequestException(req_serializer.errors)
         NFManualScaleService(vnfinstid, request.data).start()
         return Response(data={}, status=status.HTTP_202_ACCEPTED)
     except Exception as e:
         logger.error(e.args[0])
         return Response(data={'error': '%s' % e.args[0]}, status=status.HTTP_409_CONFLICT)
Ejemplo n.º 3
0
    def post(self, request, ns_instance_id):
        logger.debug("Enter NSInstView::post::ns_instance_id=%s",
                     ns_instance_id)
        logger.debug("request.data=%s", request.data)
        req_serializer = _InstantNsReqSerializer(data=request.data)
        if not req_serializer.is_valid():
            logger.debug("request.data is not valid,error: %s" %
                         req_serializer.errors)
            raise BadRequestException(req_serializer.errors)

        ack = InstantNSService(ns_instance_id, request.data).do_biz()
        logger.debug("Leave NSInstView::post::ack=%s", ack)
        return Response(data=ack['data'], status=ack['status'])
Ejemplo n.º 4
0
    def post(self, request, job_id):
        try:
            logger.debug("Enter JobView:post, job_id=%s, request=%s", job_id,
                         request.data)
            req_serializer = JobUpdReqSerializer(data=request.data)
            if not req_serializer.is_valid():
                raise BadRequestException(req_serializer.errors)

            jobs = JobUtil.query_job_status(job_id)
            if not jobs:
                raise BadRequestException("Job(%s) does not exist." % job_id)

            if jobs[-1].errcode != JOB_ERROR_CODE.ERROR:
                job_up_req = JobUpdReq(**request.data)
                desc = job_up_req.desc
                no_err_list = ('true', 'active', '0')
                err_code = JOB_ERROR_CODE.NO_ERROR if job_up_req.errcode in no_err_list else JOB_ERROR_CODE.ERROR
                logger.debug("errcode=%s", err_code)
                JobUtil.add_job_status(job_id,
                                       job_up_req.progress,
                                       desc,
                                       error_code=err_code)
            job_update_resp = JobUpdResp('ok')
            resp_serializer = JobUpdRespSerializer(job_update_resp)
            logger.debug("Leave JobView::post, response=%s", job_update_resp)
            return Response(data=resp_serializer.data,
                            status=status.HTTP_202_ACCEPTED)
        except BadRequestException as e:
            job_update_resp = JobUpdResp('error', e.args[0])
            resp_serializer = JobUpdRespSerializer(job_update_resp)
            return Response(data=resp_serializer.data,
                            status=status.HTTP_400_BAD_REQUEST)
        except Exception as e:
            job_update_resp = JobUpdResp('error', e.args[0])
            resp_serializer = JobUpdRespSerializer(job_update_resp)
            return Response(data=resp_serializer.data,
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Ejemplo n.º 5
0
    def post(self, request, ns_instance_id):
        logger.debug("Enter UpdateNSView::post %s, %s", request.data, ns_instance_id)
        req_serializer = UpdateNsReqSerializer(data=request.data)
        if not req_serializer.is_valid():
            raise BadRequestException(req_serializer.errors)

        job_id = JobUtil.create_job(JOB_TYPE.NS, JOB_ACTION.UPDATE, ns_instance_id)
        NSUpdateService(ns_instance_id, request.data, job_id).start()

        resp_serializer = _NsOperateJobSerializer(data={'jobId': job_id})
        if not resp_serializer.is_valid():
            raise NSLCMException(resp_serializer.errors)

        logger.debug("Leave UpdateNSView::post ret=%s", {'jobId': job_id})
        return Response(data={'jobId': job_id}, status=status.HTTP_202_ACCEPTED)
Ejemplo n.º 6
0
    def post(self, request):
        logger.debug(
            "Enter NSInstancesView::POST ns_instances: Header:%s, Body: %s" %
            (request.META, request.data))

        globalCustomerId = request.META.get("HTTP_GLOBALCUSTOMERID", None)
        if not globalCustomerId:
            raise BadRequestException("Not found globalCustomerId in header")
        serviceType = request.META.get("HTTP_SERVICETYPE", None)
        if not serviceType:
            serviceType = "NetworkService"
        req_serializer = CreateNsRequestSerializer(data=request.data)
        if not req_serializer.is_valid():
            raise BadRequestException(req_serializer.errors)
        if ignore_case_get(request.data, 'test') == "test":
            return Response(data={'nsInstanceId': "test"},
                            status=status.HTTP_201_CREATED)
        csar_id = ignore_case_get(request.data, 'nsdId')
        ns_name = ignore_case_get(request.data, 'nsName')
        description = ignore_case_get(request.data, 'nsDescription')
        context = {
            "globalCustomerId": globalCustomerId,
            "serviceType": serviceType
        }
        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(is_sol=True)[0]
        logger.debug("nsInstance: %s" % nsInstance)
        resp_serializer = NsInstanceSerializer(data=nsInstance)
        if not resp_serializer.is_valid():
            raise NSLCMException(resp_serializer.errors)
        response = Response(data=nsInstance, status=status.HTTP_201_CREATED)
        response["Location"] = NS_INSTANCE_BASE_URI % nsInstance['id']
        return response
Ejemplo n.º 7
0
    def post(self, request):
        job_id = "VNFSDK_" + str(uuid.uuid4())
        logger.debug("NfVerifyView--post::%s> %s", job_id, request.data)
        try:
            req_serializer = VerifyVnfReqSerializer(data=request.data)
            if not req_serializer.is_valid():
                raise BadRequestException(req_serializer.errors)

            VerifyVnfs(request.data, job_id).start()

            rsp = {"jobId": job_id}
            resp_serializer = VerifyVnfRespSerializer(data=rsp)
            if not resp_serializer.is_valid():
                raise Exception(resp_serializer.errors)

            return Response(data=rsp, status=status.HTTP_202_ACCEPTED)
        except Exception as e:
            logger.error(e.args[0])
            return Response(data={'error': '%s' % e.args[0]}, status=status.HTTP_409_CONFLICT)
Ejemplo n.º 8
0
    def post(self, request, ns_instance_id):
        job_id = JobUtil.create_job(JOB_TYPE.NS, JOB_ACTION.UPDATE,
                                    ns_instance_id)

        logger.debug("Enter UpdateNSView::post %s, %s", request.data,
                     ns_instance_id)
        req_serializer = UpdateNsReqSerializer(data=request.data)
        if not req_serializer.is_valid():
            logger.debug("request.data is not valid,error: %s" %
                         req_serializer.errors)
            raise BadRequestException(req_serializer.errors)
        ns_update_service = NSUpdateService(ns_instance_id, request.data,
                                            job_id)
        ns_update_service.start()
        response = Response(data={}, status=status.HTTP_202_ACCEPTED)
        logger.debug("Location: %s" % ns_update_service.occ_id)
        response["Location"] = NS_OCC_BASE_URI % ns_update_service.occ_id
        logger.debug("Leave UpdateNSView")
        return response
Ejemplo n.º 9
0
    def post(self, request, ns_instance_id):
        logger.debug(
            "Enter HealNSView::post nsInstanceId:%s, request.data:%s" %
            (ns_instance_id, request.data))
        req_serializer = HealNsReqSerializer(data=request.data)
        if not req_serializer.is_valid():
            logger.error("request.data is not valid,error: %s" %
                         req_serializer.errors)
            raise BadRequestException(req_serializer.errors)

        job_id = JobUtil.create_job(JOB_TYPE.NS, JOB_ACTION.HEAL,
                                    ns_instance_id)
        ns_heal_service = NSHealService(ns_instance_id, request.data, job_id)
        ns_heal_service.start()
        response = Response(data={}, status=status.HTTP_202_ACCEPTED)
        logger.debug("Location: %s" % ns_heal_service.occ_id)
        response["Location"] = NS_OCC_BASE_URI % ns_heal_service.occ_id
        logger.debug("Leave NSHealView")
        return response
Ejemplo n.º 10
0
    def post(self, request, ns_instance_id):
        logger.debug("Enter ScaleNSView::post %s, %s", request.data,
                     ns_instance_id)

        req_serializer = ScaleNsRequestSerializer(data=request.data)
        if not req_serializer.is_valid():
            raise BadRequestException(req_serializer.errors)

        job_id = JobUtil.create_job(JOB_TYPE.NS, JOB_ACTION.MANUAL_SCALE,
                                    ns_instance_id)

        nsManualScaleService = NSManualScaleService(ns_instance_id,
                                                    request.data, job_id)
        nsManualScaleService.start()
        response = Response(data={}, status=status.HTTP_202_ACCEPTED)
        logger.debug("Location: %s" % nsManualScaleService.occ_id)
        response["Location"] = NS_OCC_BASE_URI % nsManualScaleService.occ_id
        logger.debug("Leave ScaleNSView")
        return response
Ejemplo n.º 11
0
    def post(self, request):
        try:
            logger.info("Create Service Function Chain start")
            logger.info("service_function_chain_request: %s" % json.dumps(request.data))
            logger.info("service_function_chain_context  : %s" % json.dumps(request.data['context']))
            logger.info("service_function_chain_context  : %s" % request.data['context'])
            logger.info("service_function_chain_instanceid : %s" % ignorcase_get(request.data, 'nsInstanceId'))
            logger.info("service_function_chain_sdncontrollerid : %s" % ignorcase_get(request.data, 'sdnControllerId'))
            logger.info("service_function_chain_fpindex : %s" % ignorcase_get(request.data, 'fpindex'))

            req_serializer = CreateSfcReqSerializer(data=request.data)
            if not req_serializer.is_valid():
                raise BadRequestException(req_serializer.errors)
        except Exception as e:
            logger.error("Exception occurs: %s", e.args[0])
            logger.error(traceback.format_exc())
        ns_model_data = json.loads(request.data['context'])
        data = {
            'nsinstid': ignorcase_get(request.data, 'nsInstanceId'),
            "ns_model_data": ns_model_data,
            'fpindex': get_fp_id(ignorcase_get(request.data, 'fpindex'), ns_model_data),
            'fpinstid': str(uuid.uuid4()),
            'sdncontrollerid': ignorcase_get(request.data, 'sdnControllerId')
        }
        logger.info("Save FPInstModel start: ")
        SfcInstance(data).do_biz()
        logger.info("Save FPInstModel end: ")
        worker = CreateSfcWorker(data)
        job_id = worker.init_data()
        worker.start()
        logger.info("Service Function Chain Thread Sleep start : %s" % time.ctime())
        time.sleep(2)
        logger.info("Service Function Chain Thread Sleep end: %s" % time.ctime())
        logger.info("Create Service Function Chain end")

        resp_serializer = CreateSfcRespSerializer(data={"jobId": job_id, "sfcInstId": data["fpinstid"]})
        if not resp_serializer.is_valid():
            logger.error(resp_serializer.errors)

        return Response(data={"jobId": job_id, "sfcInstId": data["fpinstid"]}, status=status.HTTP_200_OK)
Ejemplo n.º 12
0
 def post(self, request, ns_instance_id):
     logger.debug("Enter NSInstPostDealView::post %s, %s", request.data,
                  ns_instance_id)
     ns_post_status = ignore_case_get(request.data, 'status')
     ns_status = NS_INST_STATUS.ACTIVE if ns_post_status == 'true' else NS_INST_STATUS.FAILED
     ns_opr_status = 'success' if ns_post_status == 'true' else 'failed'
     try:
         req_serializer = _InstNsPostDealReqSerializer(data=request.data)
         if not req_serializer.is_valid():
             raise BadRequestException(req_serializer.errors)
         NSInstModel.objects.filter(id=ns_instance_id).update(
             status=ns_status)
         ServiceBaseInfoModel.objects.filter(
             service_id=ns_instance_id).update(active_status=ns_status,
                                               status=ns_opr_status)
         nsd_info = NSInstModel.objects.filter(id=ns_instance_id)
         nsd_id = nsd_info[0].nsd_id
         nsd_model = json.loads(nsd_info[0].nsd_model)
         if "policies" in nsd_model and nsd_model["policies"]:
             policy = nsd_model["policies"][0]
             if "properties" in policy and policy["properties"]:
                 file_url = ignore_case_get(policy["properties"][0],
                                            "drl_file_url")
             else:
                 file_url = ""
             self.send_policy_request(ns_instance_id, nsd_id, file_url)
     except:
         logger.error(traceback.format_exc())
         return Response(data={
             'error':
             'Failed to update status of NS(%s)' % ns_instance_id
         },
                         status=status.HTTP_500_INTERNAL_SERVER_ERROR)
     logger.debug("*****NS INST %s, %s******", ns_status, ns_opr_status)
     return Response(data={
         'success':
         'Update status of NS(%s) to %s' % (ns_instance_id, ns_status)
     },
                     status=status.HTTP_202_ACCEPTED)
Ejemplo n.º 13
0
    def post(self, request):
        try:
            req_serializer = CreateSfcInstReqSerializer(data=request.data)
            if not req_serializer.is_valid():
                raise BadRequestException(req_serializer.errors)

            data = {
                'nsinstid': request.data['nsInstanceId'],
                "ns_model_data": json.loads(request.data['context']),
                'fpindex': request.data['fpindex'],
                'fpinstid': str(uuid.uuid4()),
                'sdncontrollerid': request.data["sdnControllerId"]}
            rsp = SfcInstance(data).do_biz()

            resp_serializer = CreateSfcInstRespSerializer(data=rsp)
            if not resp_serializer.is_valid():
                raise NSLCMException(resp_serializer.errors)

            return Response(data=rsp, status=status.HTTP_200_OK)
        except Exception as e:
            logger.error(traceback.format_exc())
            return Response(data={'error': e.args[0]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Ejemplo n.º 14
0
    def post(self, request, ns_instance_id):
        job_id = JobUtil.create_job(JOB_TYPE.NS, JOB_ACTION.TERMINATE,
                                    ns_instance_id)

        logger.debug("Enter TerminateNSView::post %s", request.data)
        req_serializer = TerminateNsReqSerializer(data=request.data)
        if not req_serializer.is_valid():
            logger.debug("request.data is not valid,error: %s" %
                         req_serializer.errors)
            raise BadRequestException(req_serializer.errors)
        termination_time = ignore_case_get(request.data, 'terminationTime')
        logger.debug("terminationTime is %s" % termination_time)
        # todo terminationTime
        terminate_ns_service = TerminateNsService(ns_instance_id, job_id,
                                                  request.data)
        terminate_ns_service.start()
        logger.debug("Location: %s" % terminate_ns_service.occ_id)
        response = Response(data={'jobId': job_id},
                            status=status.HTTP_202_ACCEPTED)
        response["Location"] = NS_OCC_BASE_URI % terminate_ns_service.occ_id
        logger.debug("Leave TerminateNSView")
        return response
Ejemplo n.º 15
0
    def post(self, request):
        logger.debug("SubscribeNotification--post::> %s" % request.data)

        lccn_subscription_request_serializer = LccnSubscriptionRequestSerializer(
            data=request.data)
        if not lccn_subscription_request_serializer.is_valid():
            raise BadRequestException(
                lccn_subscription_request_serializer.errors)
        subscription = CreateSubscription(
            lccn_subscription_request_serializer.data).do_biz()
        lccn_notifications_filter = {
            "notificationTypes":
            ast.literal_eval(subscription.notification_types),
            "operationTypes":
            ast.literal_eval(subscription.operation_types),
            "operationStates":
            ast.literal_eval(subscription.operation_states),
            "nsInstanceSubscriptionFilter":
            json.loads(subscription.ns_instance_filter),
            "nsComponentTypes":
            ast.literal_eval(subscription.ns_component_types),
            "lcmOpNameImpactingNsComponent":
            ast.literal_eval(subscription.lcm_opname_impacting_nscomponent),
            "lcmOpOccStatusImpactingNsComponent":
            ast.literal_eval(
                subscription.lcm_opoccstatus_impacting_nscomponent)
        }
        subscription_data = {
            "id": subscription.subscription_id,
            "callbackUri": subscription.callback_uri,
            "_links": json.loads(subscription.links),
            "filter": lccn_notifications_filter
        }
        sub_resp_serializer = LccnSubscriptionSerializer(
            data=subscription_data)
        if not sub_resp_serializer.is_valid():
            raise NSLCMException(sub_resp_serializer.errors)
        return Response(data=subscription_data, status=status.HTTP_201_CREATED)
Ejemplo n.º 16
0
    def post(self, request, ns_instance_id):
        logger.debug("Enter NSManualScaleView::post %s, %s", request.data,
                     ns_instance_id)
        req_serializer = _ManualScaleNsReqSerializer(data=request.data)
        if not req_serializer.is_valid():
            raise BadRequestException(req_serializer.errors)

        req = request.data
        scale_data = {}
        scale_data['scaleType'] = req['scaleType']
        scaleNsData = req['scaleNsData'][0]
        scale_data['scaleNsData'] = {
            "scaleNsByStepsData": scaleNsData['scaleNsByStepsData'][0]
        }
        job_id = JobUtil.create_job(JOB_TYPE.NS, JOB_ACTION.MANUAL_SCALE,
                                    ns_instance_id)
        NSManualScaleService(ns_instance_id, scale_data, job_id).start()

        resp_serializer = _NsOperateJobSerializer(data={'jobId': job_id})
        if not resp_serializer.is_valid():
            raise NSLCMException(resp_serializer.errors)

        return Response(data={'jobId': job_id},
                        status=status.HTTP_202_ACCEPTED)