예제 #1
0
def nspackages_rc(request, *args, **kwargs):
    logger.debug("Enter %s, method is %s", fun_name(), request.method)
    ret, normal_status, response_serializer, validation_error = None, None, None, None

    if request.method == 'GET':
        # Gets ns package list
        ret = sdc_ns_package.ns_get_csars()
        normal_status = status.HTTP_200_OK

        if ret[0] == 0:
            response_serializer = NsPackagesSerializer(data=ret[1])
            validation_error = handleValidatonError(response_serializer, False)
            if validation_error:
                return validation_error
    elif request.method == 'POST':
        # Distributes the package accroding to the given csarId
        request_serializer = NsPackageDistributeRequestSerializer(
            data=request.data)
        validation_error = handleValidatonError(request_serializer, True)
        if validation_error:
            return validation_error

        csar_id = ignore_case_get(request.data, "csarId")
        logger.debug("csar_id is %s", csar_id)
        ret = sdc_ns_package.ns_on_distribute(csar_id)
        normal_status = status.HTTP_202_ACCEPTED

    logger.debug("Leave %s, Return value is %s", fun_name(), ret)
    if ret[0] != 0:
        return Response(data={'error': ret[1]},
                        status=status.HTTP_500_INTERNAL_SERVER_ERROR)

    return Response(data=ret[1], status=normal_status)
예제 #2
0
def nf_rd_csar(request, *args, **kwargs):
    csar_id = ignore_case_get(kwargs, "csarId")
    logger.info("Enter %s, method is %s, csar_id is %s", fun_name(),
                request.method, csar_id)
    ret, normal_status, response_serializer, validation_error = None, None, None, None

    if request.method == 'GET':
        ret = sdc_vnf_package.nf_get_csar(csar_id)
        normal_status = status.HTTP_200_OK
        response_serializer = NfPackageSerializer(data=ret[1])

    elif request.method == 'DELETE':
        job_id = str(uuid.uuid4())
        sdc_vnf_package.NfPkgDeleteThread(csar_id, job_id).start()
        ret = [0, {"jobId": job_id}]
        normal_status = status.HTTP_202_ACCEPTED
        response_serializer = PostJobResponseSerializer(data=ret[1])

    logger.info("Leave %s, Return value is %s", fun_name(), ret)
    if ret[0] != 0:
        return Response(data={'error': ret[1]},
                        status=status.HTTP_500_INTERNAL_SERVER_ERROR)

    validation_error = handleValidatonError(response_serializer, False)
    if validation_error:
        return validation_error

    return Response(data=response_serializer.data, status=normal_status)
예제 #3
0
def service_rd_csar(request, *args, **kwargs):
    csar_id = ignore_case_get(kwargs, "csarId")
    logger.info("Enter %s, method is %s, csar_id is %s", fun_name(),
                request.method, csar_id)

    if request.method == 'GET':
        try:
            ret = ServicePackage().get_csar(csar_id)
            response_serializer = ServicePackageSerializer(data=ret)
            validation_error = handleValidatonError(response_serializer, False)
            if validation_error:
                return validation_error
            return Response(data=ret, status=status.HTTP_200_OK)
        except PackageNotFoundException as e:
            error_status = status.HTTP_404_NOT_FOUND
            return Response(data=fmt_error_rsp(e.args[0], error_status),
                            status=error_status)
        except Exception as e:
            error_status = status.HTTP_500_INTERNAL_SERVER_ERROR
            return Response(data=fmt_error_rsp(e.args[0], error_status),
                            status=error_status)

    elif request.method == 'DELETE':
        try:
            ServicePackage().delete_csar(csar_id)
            return Response(status=status.HTTP_204_NO_CONTENT)
        except PackageNotFoundException as e:
            error_status = status.HTTP_404_NOT_FOUND
            return Response(data=fmt_error_rsp(e.args[0], error_status),
                            status=error_status)
        except Exception as e:
            error_status = status.HTTP_500_INTERNAL_SERVER_ERROR
            return Response(data=fmt_error_rsp(e.args[0], error_status),
                            status=error_status)
예제 #4
0
def vnf_model_parser(request, *args, **kwargs):
    csar_id = ignore_case_get(request.data, "csarId")
    inputs = ignore_case_get(request.data, "inputs")
    logger.debug("Enter %s, csar_id=%s, inputs=%s", fun_name(), csar_id,
                 inputs)
    ret = sdc_vnf_package.parse_vnfd(csar_id, inputs)
    logger.info("Leave %s, Return value is %s", fun_name(), ret)
    if ret[0] != 0:
        return Response(data={'error': ret[1]},
                        status=status.HTTP_500_INTERNAL_SERVER_ERROR)

    response_serializer = ParseModelResponseSerializer(data=ret[1])
    validation_error = handleValidatonError(response_serializer, False)
    if validation_error:
        return validation_error

    return Response(data=response_serializer.data,
                    status=status.HTTP_202_ACCEPTED)
예제 #5
0
def ns_rd_csar(request, *args, **kwargs):
    csar_id = ignore_case_get(kwargs, "csarId")
    logger.info("Enter %s, method is %s, csar_id is %s", fun_name(),
                request.method, csar_id)
    ret, normal_status, response_serializer, validation_error = None, None, None, None
    if request.method == 'GET':
        ret = sdc_ns_package.ns_get_csar(csar_id)
        normal_status = status.HTTP_200_OK
        if ret[0] == 0:
            response_serializer = NsPackageSerializer(data=ret[1])
            validation_error = handleValidatonError(response_serializer, False)
            if validation_error:
                return validation_error
    elif request.method == 'DELETE':
        ret = sdc_ns_package.ns_delete_csar(csar_id)
        normal_status = status.HTTP_200_OK
    logger.info("Leave %s, Return value is %s", fun_name(), ret)
    if ret[0] != 0:
        return Response(data={'error': ret[1]},
                        status=status.HTTP_500_INTERNAL_SERVER_ERROR)
    return Response(data=ret[1], status=normal_status)
예제 #6
0
def nfpackages_rc(request, *args, **kwargs):
    logger.debug("Enter %s%s, method is %s", fun_name(), request.data,
                 request.method)
    ret, normal_status, response_serializer, validation_error = None, None, None, None
    if request.method == 'GET':
        ret = sdc_vnf_package.nf_get_csars()
        normal_status = status.HTTP_200_OK
        response_serializer = NfPackagesSerializer(data=ret[1])
    elif request.method == 'POST':
        request_serivalizer = NfPackageDistributeRequestSerializer(
            data=request.data)
        validation_error = handleValidatonError(request_serivalizer, True)
        if validation_error:
            return validation_error

        csar_id = ignore_case_get(request_serivalizer.data, "csarId")
        vim_ids = ignore_case_get(request_serivalizer.data, "vimIds")
        lab_vim_id = ignore_case_get(request_serivalizer.data, "labVimId")
        job_id = str(uuid.uuid4())
        sdc_vnf_package.NfDistributeThread(csar_id, vim_ids, lab_vim_id,
                                           job_id).start()
        ret = [0, {"jobId": job_id}]
        normal_status = status.HTTP_202_ACCEPTED

        response_serializer = PostJobResponseSerializer(data=ret[1])
    logger.debug("Leave %s, Return value is %s", fun_name(), ret)

    if ret[0] != 0:
        return Response(data={'error': ret[1]},
                        status=status.HTTP_500_INTERNAL_SERVER_ERROR)

    validation_error = handleValidatonError(response_serializer, False)
    if validation_error:
        return validation_error

    return Response(data=response_serializer.data, status=normal_status)
예제 #7
0
def model_parser(request, *args, **kwargs):
    csar_id = ignore_case_get(request.data, "csarId")
    package_type = ignore_case_get(request.data, "packageType")
    inputs = ignore_case_get(request.data, "inputs")
    logger.debug("Enter %s, csar_id=%s, package_type=%s, inputs=%s",
                 fun_name(), csar_id, package_type, inputs)

    if package_type.lower().__eq__("service"):
        try:
            ret = ServicePackage().parse_serviced(csar_id, inputs)
            response_serializer = ParseModelResponseSerializer(data=ret)
            validation_error = handleValidatonError(response_serializer, False)
            if validation_error:
                return validation_error
            return Response(data=response_serializer.data,
                            status=status.HTTP_202_ACCEPTED)
        except PackageNotFoundException as e:
            error_status = status.HTTP_404_NOT_FOUND
            return Response(data=fmt_error_rsp(e.args[0], error_status),
                            status=error_status)
        except Exception as e:
            error_status = status.HTTP_500_INTERNAL_SERVER_ERROR
            return Response(data=fmt_error_rsp(e.args[0], error_status),
                            status=error_status)
    elif package_type.lower().__eq__("ns"):
        ret = sdc_ns_package.parse_nsd(csar_id, inputs)
    elif package_type.lower().__eq__("vnf"):
        ret = sdc_vnf_package.parse_vnfd(csar_id, inputs)
    elif package_type.lower().__eq__("pnf"):
        ret = PnfDescriptor().parse_pnfd(csar_id, inputs)
    else:
        error_status = status.HTTP_400_BAD_REQUEST
        error_message = "Invalid package type, it should be one of [VNF, PNF, NS, Service]"
        return Response(data=fmt_error_rsp(error_message, error_status),
                        status=error_status)

    if ret[0] != 0:
        return Response(data={'error': ret[1]},
                        status=status.HTTP_500_INTERNAL_SERVER_ERROR)

    response_serializer = ParseModelResponseSerializer(data=ret[1])
    validation_error = handleValidatonError(response_serializer, False)
    if validation_error:
        return validation_error

    return Response(data=response_serializer.data,
                    status=status.HTTP_202_ACCEPTED)
예제 #8
0
def servicepackages_rc(request, *args, **kwargs):
    logger.debug("Enter %s, method is %s", fun_name(), request.method)

    if request.method == 'GET':
        # Gets service package list
        try:
            csar_list = ServicePackage().get_csars()
            response_serializer = ServicePackagesSerializer(data=csar_list)
            validation_error = handleValidatonError(response_serializer, False)
            if validation_error:
                return validation_error
            return Response(data=csar_list, status=status.HTTP_200_OK)
        except Exception as e:
            error_status = status.HTTP_500_INTERNAL_SERVER_ERROR
            return Response(data=fmt_error_rsp(e.args[0], error_status),
                            status=error_status)
    elif request.method == 'POST':
        # Distributes the package according to the given csarId
        request_serializer = ServicePackageDistributeRequestSerializer(
            data=request.data)
        validation_error = handleValidatonError(request_serializer, True)
        if validation_error:
            return validation_error

        csar_id = ignore_case_get(request.data, "csarId")
        logger.debug("csar_id is %s", csar_id)
        try:
            ServicePackage().on_distribute(csar_id)
            return Response(status=status.HTTP_202_ACCEPTED)
        except PackageHasExistsException as e:
            error_status = status.HTTP_400_BAD_REQUEST
            return Response(data=fmt_error_rsp(e.args[0], error_status),
                            status=error_status)
        except Exception as e:
            error_status = status.HTTP_500_INTERNAL_SERVER_ERROR
            return Response(data=fmt_error_rsp(e.args[0], error_status),
                            status=error_status)