示例#1
0
def do_checkavailable(data):
    logger.debug("[%s] request.data=%s", fun_name(), data)
    # ret = call_certus_resource("grant/v1/grants", "POST", VNFM_INFO, data)
    ret = call_certus_resource("grant/v1/grants", "POST")
    logger.debug("[%s] call_req ret=%s", fun_name(), ret)
    if ret[0] != 0:
        logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
        raise CertusvmanagerdriverException('Failed to check available.')
    return json.JSONDecoder().decode(ret[1])
示例#2
0
def get_vnfminfo_from_nslcm(vnfm_id):
    logger.debug("[get_vnfminfo_from_nslcm] vnfm_id=[%s]", vnfm_id)
    ret = req_by_msb("api/aai-esr-server/v1/vnfms/%s" % vnfm_id, "GET")
    logger.debug("[get_vnfminfo_from_nslcm] response=%s", ret)
    if ret[0] != 0:
        logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
        raise CertusvmanagerdriverException(
            "Failed to query vnfm(%s) from nslcm." % vnfm_id)
    return json.JSONDecoder().decode(ret[1])
示例#3
0
def do_scalevnf(vnfm_id, vnfInstanceId, data):
    logger.debug("[%s] request.data=%s", fun_name(), data)
    vnfm_info = get_vnfminfo_from_nslcm(vnfm_id)
    logger.debug("[do_terminatevnf] vnfm_info=[%s]", vnfm_info)
    ret = call_vnfm("vnflcm/v1/vnf_instances/%s/scale" % vnfInstanceId, "POST",
                    vnfm_info, data)
    if ret[0] != 0:
        logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
        raise CertusvmanagerdriverException('Failed to terminate vnf.')
    return json.JSONDecoder().decode(ret[1])
示例#4
0
def svnfm_download_vnf_package(vnfm_id, data):
    logger.debug("[%s] request.data=%s", fun_name(), data)
    vnfm_info = get_vnfminfo_from_nslcm(vnfm_id)
    logger.debug("[do_createvnf] vnfm_info=[%s]", vnfm_info)
    ret = call_vnfm("vnfpkgm/v1/vnfd/save", "POST", vnfm_info, data)
    logger.debug("[%s] call_req ret=%s", fun_name(), ret)
    if ret[0] != 0:
        logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
        raise CertusvmanagerdriverException('Failed to save vnfd.')
    return json.JSONDecoder().decode(ret[1])
示例#5
0
def wait4job(vnfm_id,
             job_id,
             gracefulTerminationTimeout=1200,
             retry_count=60,
             interval_second=3):
    logger.debug(
        "[wait4job] vnfm_id=[%s],jobId=[%s],gracefulTerminationTimeout=[%s]",
        vnfm_id, job_id, gracefulTerminationTimeout)
    count = 0
    job_end_normal, job_timeout = False, True
    vnfm_info = get_vnfminfo_from_nslcm(vnfm_id)

    logger.debug("[do_terminatevnf] vnfm_info=[%s]", vnfm_info)
    while count < retry_count:
        count = count + 1
        time.sleep(interval_second)
        # ret = call_vnfm("api/vnflcm/v1/vnf_lc_ops/%s?responseId=%s" % (job_id, response_id), "GET", vnfm_info)
        ret = call_vnfm("vnflcm/v1/vnf_lcm_op_occs/%s" % (job_id), "GET",
                        vnfm_info)
        if ret[0] != 0:
            logger.error("Failed to query job: %s:%s", ret[2], ret[1])
            continue
        job_result = json.JSONDecoder().decode(ret[1])
        if "operationState" not in job_result:
            logger.error("Job(%s) does not exist.", job_id)
            continue
        operationState = job_result["operationState"]
        job_desc = job_result["operation"]
        logger.info("Job(%s)  status:(%s),job_operation.", job_id,
                    operationState, job_desc)

        if operationState == "PROCESSING":
            logger.error("Job(%s) processing: %s", job_id, job_desc)
            continue
        elif operationState == "FAILED_TEMP":
            job_timeout = False
            logger.info("Job(%s) failed: %s", job_id, job_desc)
            break
        elif operationState == "COMPLETED":
            job_end_normal, job_timeout = True, False
            logger.debug(
                "Job(%s) ended normally,job_end_normal=[%s],job_timeout=[%s]",
                job_id, job_end_normal, job_timeout)
            return {"success": "success"}
    if job_timeout:
        logger.error("Job(%s) timeout", job_id)
    raise CertusvmanagerdriverException("Fail to get job status!")
示例#6
0
def get_vnfpkgs(request, *args, **kwargs):
    try:
        logger.debug("Enter %s", fun_name())
        ret = req_by_msb("api/nslcm/v1/vnfpackage", "GET")
        if ret[0] != 0:
            logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
            raise CertusvmanagerdriverException('Failed to get vnfpkgs.')
        resp = json.JSONDecoder().decode(ret[1])
        return Response(data=resp, status=status.HTTP_200_OK)
    except CertusvmanagerdriverException as e:
        logger.error('Get vnfpkgs failed, detail message: %s' % e.message)
        return Response(data={'error': e.message},
                        status=status.HTTP_500_INTERNAL_SERVER_ERROR)
    except:
        logger.error(traceback.format_exc())
        return Response(data={'error': 'unexpected exception'},
                        status=status.HTTP_500_INTERNAL_SERVER_ERROR)
示例#7
0
def notify(request, *args, **kwargs):
    try:
        logger.debug("[%s]req_data = %s", fun_name(), request.data)
        vnfinstanceid = ignorcase_get(request.data, 'vnfinstanceid')
        ret = req_by_msb("api/nslcm/v1/vnfs/%s/Notify" % vnfinstanceid, "POST",
                         json.JSONEncoder().encode(request.data))
        logger.debug("[%s]data = %s", fun_name(), ret)
        if ret[0] != 0:
            logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
            raise CertusvmanagerdriverException('Failed to notify vnf.')
        return Response(data=None, status=ret[2])
    except CertusvmanagerdriverException as e:
        logger.error('Grant vnf failed, detail message: %s' % e.message)
        return Response(data={'error': e.message},
                        status=status.HTTP_500_INTERNAL_SERVER_ERROR)
    except:
        logger.error(traceback.format_exc())
        return Response(data={'error': 'unexpected exception'},
                        status=status.HTTP_500_INTERNAL_SERVER_ERROR)
示例#8
0
def instantiate_vnf(request, *args, **kwargs):
    try:
        logger.debug("instantiate_vnf--post::> %s" % request.data)
        logger.debug("instantiate_vnf-kwargs = %s" % kwargs)
        logger.debug("Create vnf begin!")
        vnfd_descriptor_id, vnfd_df_flavour_id = get_parameter_from_vnfd(
            ignorcase_get(request.data, "vnfPackageId"))
        logger.debug('vnfd_descriptor_id = %s' % vnfd_descriptor_id)
        logger.debug('vnfd_df_flavour_id = %s' % vnfd_df_flavour_id)

        vnfm_id = ignorcase_get(kwargs, "vnfmid")

        ret = req_by_msb("api/aai-esr-server/v1/vnfms/%s" % vnfm_id, "GET")
        logger.debug("instantiate_vnf-req_by_msb response=%s", ret)
        if ret[0] != 0:
            logger.error('Status code is %s, detail is %s.', ret[2], ret[1])
            raise CertusvmanagerdriverException(
                "Failed to query vnfm(%s) from nslcm." % vnfm_id)
        global mano_vnfm_auth_url
        mano_vnfm_auth_url = json.JSONDecoder().decode(
            ret[1])['certificateUrl']

        logger.debug('instantiate_vnf-mano_vnfm_auth_url = %s' %
                     mano_vnfm_auth_url)

        input_data = {
            "vnfdId":
            vnfd_descriptor_id,
            "vnfInstanceName":
            ignorcase_get(request.data, "vnfInstanceName"),
            "vnfInstanceDescription":
            ignorcase_get(request.data, "vnfInstanceDescription")
        }
        logger.debug(
            "do_createvnf: request data=[%s],input_data=[%s],vnfm_id=[%s]",
            request.data, input_data, vnfm_id)

        #        vnf_package_id = ignorcase_get(request.data, "vnfPackageId")
        #        ret = vnfpackage_get(vnf_package_id)

        #        if ret[0] != 0:
        #            return Response(data={'error': ret[1]}, status=ret[2])
        #        vnf_package_info = json.JSONDecoder().decode(ret[1])
        #        packageInfo = ignorcase_get(vnf_package_info, "packageInfo")
        #        logger.debug("[%s] packageInfo=%s", fun_name(), packageInfo)

        #        vnfPkg_params = {
        #            "vnfdId": ignorcase_get(packageInfo, "vnfdId"),
        #            "vnfPkgId": ignorcase_get(packageInfo, "vnfPackageId"),
        #            "vnfPackageUri": ignorcase_get(packageInfo, "downloadUrl")
        #        }
        #        ret = svnfm_download_vnf_package(vnfm_id, vnfPkg_params)
        #        if ret[0] != 0:
        #            return Response(data={'error': ret[1]}, status=ret[2])

        resp = do_createvnf(vnfm_id, input_data)
        logger.debug("do_createvnf: response data=[%s]", resp)
        logger.debug("Create vnf end!")

        logger.debug("Instantiate vnf start!")
        vnfInstanceId = resp["id"]
        vim_uuid = ignorcase_get(
            ignorcase_get(request.data, "additionalParam"), "vimId")
        vim_connection_info = {"vimId": vim_uuid}
        input_data = {
            "flavourId": vnfd_df_flavour_id,
            # "extVirtualLinks": ignorcase_get(request.data, "extVirtualLink"),
            # 根据sol003,指定实例化的vim信息
            "vimConnectionInfo": vim_connection_info,
            "additionalParams": ignorcase_get(request.data, "additionalParam")
        }
        logger.debug(
            "do_instvnf: vnfInstanceId=[%s], vnfm_id=[%s], input_data=[%s]",
            vnfInstanceId, vnfm_id, input_data)
        resp = do_instvnf(vnfInstanceId, vnfm_id, input_data)
        logger.debug("do_instvnf: response data=[%s]", resp)
        resp_data = {
            "vnfInstanceId": vnfInstanceId,
            "jobId": ignorcase_get(resp, "vnfLcmOpOccId")
        }
        logger.debug("Instantiate vnf end!")
        return Response(data=resp_data, status=status.HTTP_201_CREATED)
    except CertusvmanagerdriverException as e:
        logger.error('instantiate vnf failed, detail message: %s' % e.message)
        return Response(data={'error': e.message},
                        status=status.HTTP_500_INTERNAL_SERVER_ERROR)
    except:
        logger.error(traceback.format_exc())
        return Response(data={'error': 'unexpected exception'},
                        status=status.HTTP_500_INTERNAL_SERVER_ERROR)
示例#9
0
def operation_status(request, *args, **kwargs):
    logger.debug("operation_status--post::> %s" % request.data)
    try:
        logger.debug("[%s] request.data=%s", fun_name(), request.data)
        vnfm_id = ignorcase_get(kwargs, "vnfmid")
        jobId = ignorcase_get(kwargs, "jobId")
        responseId = ignorcase_get(kwargs, "responseId")
        logger.debug("[operation_status] vnfm_id=%s", vnfm_id)
        vnfm_info = get_vnfminfo_from_nslcm(vnfm_id)
        logger.debug("[operation_status] vnfm_info=[%s]", vnfm_info)

        ret = call_vnfm(
            "lcm/v1/vnf_lc_ops/%s?responseId=%s" % (jobId, responseId), "GET",
            vnfm_info)
        if ret[0] != 0:
            logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
            raise CertusvmanagerdriverException(
                'Failed to query vnf operation status.')
        resp_data = json.JSONDecoder().decode(ret[1])
        logger.debug("[%s]resp_data=%s", fun_name(), resp_data)
        query_operation_resp_mapping = {
            "progress": "",
            "status": "",
            "statusDescription": "",
            "errorCode": "",
            "responseId": "",
        }
        responseDescriptor = mapping_conv(
            query_operation_resp_mapping,
            ignorcase_get(resp_data, "ResponseInfo"))
        ResponseInfo = []
        resp_desc = ignorcase_get(resp_data, "responseDescriptor")
        if ignorcase_get(resp_desc, "lcmOperationStatus") == "COMPLETED":
            responseDescriptor["status"] = "finished"
        elif ignorcase_get(resp_desc, "lcmOperationStatus") == "FAILED_TEMP":
            responseDescriptor["status"] = "error"
        elif ignorcase_get(resp_desc, "lcmOperationStatus") == "FAILED":
            responseDescriptor["status"] = "error"
        elif ignorcase_get(resp_desc, "lcmOperationStatus") == "PROCESSING":
            responseDescriptor["status"] = "processing"
        else:
            responseDescriptor["status"] = ignorcase_get(
                resp_desc, "lcmOperationStatus")
        responseDescriptor["progress"] = ignorcase_get(resp_desc, "progress")
        responseDescriptor["responseId"] = ignorcase_get(
            resp_desc, "responseId")
        responseDescriptor["statusDescription"] = ignorcase_get(
            resp_desc, "statusDescription")
        responseDescriptor["errorCode"] = ignorcase_get(resp_desc, "errorCode")
        responseHistory = resp_desc["responseHistoryList"]
        for index, item in enumerate(responseHistory):
            history_dict = {}
            history_dict["responseId"] = ignorcase_get(item, "responseId")
            history_dict["progress"] = ignorcase_get(item, "progress")
            if ignorcase_get(item, "lcmOperationStatus") == "COMPLETED":
                history_dict["status"] = "finished"
            elif ignorcase_get(item, "lcmOperationStatus") == "FAILED_TEMP":
                history_dict["status"] = "error"
            elif ignorcase_get(item, "lcmOperationStatus") == "FAILED":
                history_dict["status"] = "error"
            elif ignorcase_get(item, "lcmOperationStatus") == "PROCESSING":
                history_dict["status"] = "processing"
            else:
                history_dict["status"] = ignorcase_get(item,
                                                       "lcmOperationStatus")
            history_dict["statusDescription"] = ignorcase_get(
                item, "statusDescription")
            history_dict["errorCode"] = ignorcase_get(item, "errorCode")
            ResponseInfo.append(history_dict)
        responseDescriptor["responseHistoryList"] = ResponseInfo
        operation_data = {
            "jobId": ignorcase_get(resp_data, "vnfLcOpId"),
            "responseDescriptor": responseDescriptor
        }
        logger.debug("[%s]operation_data=%s", fun_name(), operation_data)
        return Response(data=operation_data, status=status.HTTP_200_OK)
    except CertusvmanagerdriverException as e:
        logger.error('Query vnf failed, detail message: %s' % e.message)
        return Response(data={'error': e.message},
                        status=status.HTTP_500_INTERNAL_SERVER_ERROR)
    except:
        logger.error(traceback.format_exc())
        return Response(data={'error': 'unexpected exception'},
                        status=status.HTTP_500_INTERNAL_SERVER_ERROR)