Пример #1
0
class QueryMultiNsLcmOpOccs(APIView):
    @swagger_auto_schema(
        responses={
            status.HTTP_200_OK: NSLCMOpOccsSerializer(),
            status.HTTP_400_BAD_REQUEST: ProblemDetailsSerializer(),
            status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()
        }
    )
    @view_safe_call_with_log(logger=logger)
    def get(self, request):
        logger.debug("QueryMultiNsLcmOpOccs--get::> %s" % request.query_params)

        if request.query_params and not set(request.query_params).issubset(set(VALID_FILTERS)):
            problem_details_serializer = get_problem_details_serializer(status.HTTP_400_BAD_REQUEST, "Not a valid filter")
            return Response(data=problem_details_serializer.data, status=status.HTTP_400_BAD_REQUEST)
        resp_data = QueryNsLcmOpOcc(request.query_params).query_multi_ns_lcm_op_occ()
        if len(resp_data) == 0:
            return Response(data=[], status=status.HTTP_200_OK)

        ns_lcm_op_occs_serializer = NSLCMOpOccsSerializer(data=resp_data)
        if not ns_lcm_op_occs_serializer.is_valid():
            raise NSLCMException(ns_lcm_op_occs_serializer.errors)

        logger.debug("QueryMultiNsLcmOpOccs--get::> Remove default fields if exclude_default is specified")
        if 'exclude_default' in list(request.query_params.keys()):
            for field in EXCLUDE_DEFAULT:
                for lcm_op in resp_data:
                    del lcm_op[field]
        return Response(data=resp_data, status=status.HTTP_200_OK)
Пример #2
0
def get_problem_details_serializer(status_code, error_message):
    problem_details = {
        "status": status_code,
        "detail": error_message
    }
    problem_details_serializer = ProblemDetailsSerializer(data=problem_details)
    problem_details_serializer.is_valid()
    return problem_details_serializer
Пример #3
0
class UpdateNSView(APIView):
    @swagger_auto_schema(request_body=UpdateNsReqSerializer(),
                         responses={
                             status.HTTP_202_ACCEPTED:
                             "HTTP_202_ACCEPTED",
                             status.HTTP_500_INTERNAL_SERVER_ERROR:
                             ProblemDetailsSerializer()
                         })
    @view_safe_call_with_log(logger=logger)
    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
Пример #4
0
class TerminateNsView(APIView):
    @swagger_auto_schema(request_body=TerminateNsReqSerializer(),
                         responses={
                             status.HTTP_202_ACCEPTED:
                             "HTTP_202_ACCEPTED",
                             status.HTTP_500_INTERNAL_SERVER_ERROR:
                             ProblemDetailsSerializer()
                         })
    @view_safe_call_with_log(logger=logger)
    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
Пример #5
0
class QuerySingleNsLcmOpOcc(APIView):
    @swagger_auto_schema(
        responses={
            status.HTTP_200_OK: NSLCMOpOccSerializer(),
            status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()
        }
    )
    @view_safe_call_with_log(logger=logger)
    def get(self, request, lcmopoccid):
        logger.debug("QuerySingleNsLcmOpOcc--get::> %s" % request.query_params)

        resp_data = QueryNsLcmOpOcc(request.query_params,
                                    lcm_op_occ_id=lcmopoccid).query_single_ns_lcm_op_occ()

        ns_lcm_op_occ_serializer = NSLCMOpOccSerializer(data=resp_data)
        if not ns_lcm_op_occ_serializer.is_valid():
            raise NSLCMException(ns_lcm_op_occ_serializer.errors)

        return Response(data=resp_data, status=status.HTTP_200_OK)
Пример #6
0
class NSLCMOpOccSerializer(serializers.Serializer):
    id = serializers.CharField(
        help_text=
        "Identifier of this NS lifecycle management operation occurrence,",
        max_length=255,
        required=True,
        allow_null=False)
    operationState = serializers.ChoiceField(
        help_text="The state of the VNF LCM operation occurrence. ",
        required=True,
        choices=enum_to_list(OPERATION_STATE_TYPE))
    stateEnteredTime = serializers.CharField(
        help_text="Date-time when the current state was entered.",
        max_length=50)
    startTime = serializers.CharField(
        help_text="Date-time of the start of the operation.", max_length=50)
    nsInstanceId = serializers.UUIDField(
        help_text="Identifier of the ns instance to which the operation applies"
    )
    operation = serializers.ChoiceField(
        help_text="The lifecycle management operation",
        required=True,
        choices=enum_to_list(OPERATION_TYPE))
    isAutomaticInvocation = serializers.BooleanField(
        help_text=
        "Set to true if this NS LCM operation occurrence has been automatically triggered by the NFVO.",
        default=False)
    operationParams = serializers.DictField(
        help_text=
        "Input parameters of the LCM operation. This attribute shall be formatted according to the request "
        "data type of the related LCM operation. The following mapping between operationType and the data "
        "type of this attribute shall apply: "
        "1. INSTANTIATE: InstantiateVnfRequest "
        "2. SCALE: ScaleVnfRequest "
        "3. CHANGE_FLAVOUR: ChangeVnfFlavourRequest"
        "4. HEAL: HealVnfRequest "
        "5. TERMINATE: TerminateVnfRequest ",
        required=True,
        allow_null=False)
    isCancelPending = serializers.BooleanField(
        help_text=
        "If the NS LCM operation occurrence is in 'STARTING' or 'PROCESSING' or 'ROLLING_BACK' state and "
        "the operation is being cancelled, this attribute shall be set to True. Otherwise, it shall be set "
        "to False.",
        required=True)
    cancelMode = serializers.CharField(
        help_text=
        "The mode of an ongoing cancellation. Shall be present when isCancelPending=true, and shall be None "
        "otherwise.",
        allow_null=True,
        required=False)
    error = ProblemDetailsSerializer(
        help_text=
        "If 'operationState' is 'FAILED_TEMP' or 'FAILED' or PROCESSING' or 'ROLLING_BACK' and previous "
        "value of 'operationState' was 'FAILED_TEMP'  this attribute shall be present ",
        allow_null=True,
        required=False)
    resourceChanges = ResourceChangesSerializer(
        help_text=
        "It contains information about the cumulative changes to virtualised resources that were performed "
        "so far by the LCM operation since its start, if applicable.",
        required=False,
        allow_null=True)
    _links = LcmOpLinkSerializer(
        help_text="Links to resources related to this resource.",
        required=True)
Пример #7
0
class VnfLcmOperationOccurrenceNotificationSerializer(serializers.Serializer):
    id = serializers.CharField(help_text="Identifier of this notification.",
                               required=True)
    notificationType = serializers.ChoiceField(
        help_text="Discriminator for the different notification types.",
        choices=enum_to_list(VNF_NOTIFICATION_TYPE),
        required=True)
    subscriptionId = serializers.CharField(
        help_text=
        "Identifier of the subscription that this notification relates to.",
        required=True)
    timeStamp = serializers.CharField(
        help_text="Date-time of the generation of the notification.",
        required=True)
    notificationStatus = serializers.ChoiceField(
        help_text=
        "Indicates whether this notification reports about the start of a lifecycle operation or the result of a lifecycle operation.",
        choices=enum_to_list(LCM_NOTIFICATION_STATUS),
        required=True)
    operationState = serializers.ChoiceField(
        help_text="The state of the VNF LCM operation occurrence.",
        choices=enum_to_list(OPERATION_STATE_TYPE),
        required=True)
    vnfInstanceId = serializers.CharField(
        help_text="The identifier of the VNF instance affected.",
        required=True)
    operation = serializers.ChoiceField(
        help_text="The lifecycle management operation.",
        choices=enum_to_list(GRANT_OPERATION),
        required=True)
    isAutomaticInvocation = serializers.BooleanField(
        help_text=
        "Set to true if this VNF LCM operation occurrence has been triggered by an automated procedure inside the VNFM.",
        required=True)
    vnfLcmOpOccId = serializers.CharField(
        help_text=
        "The identifier of the VNF lifecycle management operation occurrence associated to the notification.",
        required=True)
    affectedVnfcs = AffectedVnfcSerializer(
        help_text=
        "Information about VNFC instances that were affected during the lifecycle operation.",
        many=True,
        required=False)
    affectedVirtualLinks = AffectedVirtualLinkSerializer(
        help_text=
        "Information about VL instances that were affected during the lifecycle operation.",
        many=True,
        required=False)
    affectedVirtualStorages = AffectedVirtualStorageSerializer(
        help_text=
        "Information about virtualised storage instances that were affected during the lifecycle operation.",
        many=True,
        required=False)
    changedInfo = VnfInfoModificationsSerializer(
        help_text=
        "Information about the changed VNF instance information, including changed VNF configurable properties.",
        required=False,
        allow_null=True)
    changedExtConnectivity = ExtVirtualLinkInfoSerializer(
        help_text="Information about changed external connectivity.",
        many=True,
        required=False)
    error = ProblemDetailsSerializer(
        help_text=
        "Details of the latest error, if one has occurred during executing the LCM operation",
        required=False,
        allow_null=True)
    _links = LccnLinksSerializer(
        help_text="Links to resources related to this notification.",
        required=False,
        allow_null=True)
Пример #8
0
class SubscriptionsView(APIView):
    @swagger_auto_schema(request_body=LccnSubscriptionRequestSerializer(),
                         responses={
                             status.HTTP_201_CREATED:
                             LccnSubscriptionSerializer(),
                             status.HTTP_303_SEE_OTHER:
                             ProblemDetailsSerializer(),
                             status.HTTP_500_INTERNAL_SERVER_ERROR:
                             ProblemDetailsSerializer()
                         })
    @view_safe_call_with_log(logger=logger)
    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)

    @swagger_auto_schema(
        responses={
            status.HTTP_200_OK: LccnSubscriptionsSerializer(),
            status.HTTP_400_BAD_REQUEST: ProblemDetailsSerializer(),
            status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()
        })
    @view_safe_call_with_log(logger=logger)
    def get(self, request):
        logger.debug("SubscribeNotification--get::> %s" % request.query_params)

        if request.query_params and not set(request.query_params).issubset(
                set(VALID_FILTERS)):
            problem_details_serializer = get_problem_details_serializer(
                status.HTTP_400_BAD_REQUEST, "Not a valid filter")
            return Response(data=problem_details_serializer.data,
                            status=status.HTTP_400_BAD_REQUEST)
        resp_data = QuerySubscription(
            request.query_params).query_multi_subscriptions()
        subscriptions_serializer = LccnSubscriptionsSerializer(data=resp_data)
        if not subscriptions_serializer.is_valid():
            raise NSLCMException(subscriptions_serializer.errors)
        logger.debug(
            "SubscribeNotification--get::> Remove default fields if exclude_default is "
            "specified")
        return Response(data=resp_data, status=status.HTTP_200_OK)