def portalresources_get(graph_format):  # noqa: E501
    """Retrieve a listing and description of available resources for portal

    Retrieve a listing and description of available resources for portal # noqa: E501

    :param graph_format: Graph format
    :type graph_format: str

    :rtype: Success
    """
    handler = OrchestratorHandler()
    logger = handler.get_logger()
    received_counter.labels(GET_METHOD, PORTAL_RESOURCES_PATH).inc()
    try:
        value = handler.portal_list_resources(graph_format_str=graph_format)
        response = Success()
        response.value = value
        success_counter.labels(GET_METHOD, PORTAL_RESOURCES_PATH).inc()
        return response
    except OrchestratorException as e:
        logger.exception(e)
        failure_counter.labels(GET_METHOD, PORTAL_RESOURCES_PATH).inc()
        msg = str(e).replace("\n", "")
        return cors_response(status=e.get_http_error_code(),
                             xerror=str(e),
                             body=msg)
    except Exception as e:
        logger.exception(e)
        failure_counter.labels(GET_METHOD, PORTAL_RESOURCES_PATH).inc()
        msg = str(e).replace("\n", "")
        return cors_response(status=INTERNAL_SERVER_ERROR,
                             xerror=str(e),
                             body=msg)
def slivers_get(slice_id):  # noqa: E501
    """Retrieve a listing of user slivers

    Retrieve a listing of user slivers # noqa: E501

    :param slice_id: Slice identifier as UUID
    :type slice_id: str

    :rtype: Success
    """
    handler = OrchestratorHandler()
    logger = handler.get_logger()
    received_counter.labels(GET_METHOD, SLIVERS_GET_PATH).inc()
    try:
        token = get_token()
        value = handler.get_slivers(slice_id=slice_id, token=token)
        response = Success()
        response.value = value
        success_counter.labels(GET_METHOD, SLIVERS_GET_PATH).inc()
        return response
    except OrchestratorException as e:
        logger.exception(e)
        failure_counter.labels(GET_METHOD, SLIVERS_GET_PATH).inc()
        msg = str(e).replace("\n", "")
        return cors_response(status=e.get_http_error_code(),
                             xerror=str(e),
                             body=msg)
    except Exception as e:
        logger.exception(e)
        failure_counter.labels(GET_METHOD, SLIVERS_GET_PATH).inc()
        msg = str(e).replace("\n", "")
        return cors_response(status=INTERNAL_SERVER_ERROR,
                             xerror=str(e),
                             body=msg)
def resources_get(level: int):  # noqa: E501
    """Retrieve a listing and description of available resources

    :param level: Level of details
    :type level: int
    :param graph_format: Graph format
    :type graph_format: str


    :rtype: Success
    """
    handler = OrchestratorHandler()
    logger = handler.get_logger()
    received_counter.labels(GET_METHOD, RESOURCES_PATH).inc()
    try:
        token = get_token()
        value = handler.list_resources(token=token, level=level)
        response = Success()
        response.value = value
        success_counter.labels(GET_METHOD, RESOURCES_PATH).inc()
        return response
    except OrchestratorException as e:
        logger.exception(e)
        failure_counter.labels(GET_METHOD, RESOURCES_PATH).inc()
        msg = str(e).replace("\n", "")
        return cors_response(status=e.get_http_error_code(),
                             xerror=str(e),
                             body=msg)
    except Exception as e:
        logger.exception(e)
        failure_counter.labels(GET_METHOD, RESOURCES_PATH).inc()
        msg = str(e).replace("\n", "")
        return cors_response(status=INTERNAL_SERVER_ERROR,
                             xerror=str(e),
                             body=msg)
Beispiel #4
0
def slices_delete_slice_iddelete(slice_id):  # noqa: E501
    """Delete slice.

    Request to delete slice. On success, resources associated with slice or sliver are stopped if necessary,
    de-provisioned and un-allocated at the respective sites.  # noqa: E501

    :param slice_id: Slice identifier as UUID
    :type slice_id: str

    :rtype: Success
    """
    handler = OrchestratorHandler()
    logger = handler.get_logger()
    received_counter.labels(DELETE_METHOD, SLICES_DELETE_PATH).inc()
    try:
        token = get_token()
        handler.delete_slice(token=token, slice_id=slice_id)
        response = Success()
        success_counter.labels(DELETE_METHOD, SLICES_DELETE_PATH).inc()
        return response
    except OrchestratorException as e:
        logger.exception(e)
        failure_counter.labels(DELETE_METHOD, SLICES_DELETE_PATH).inc()
        msg = str(e).replace("\n", "")
        return cors_response(status=e.get_http_error_code(),
                             xerror=str(e),
                             body=msg)
    except Exception as e:
        logger.exception(e)
        failure_counter.labels(DELETE_METHOD, SLICES_DELETE_PATH).inc()
        msg = str(e).replace("\n", "")
        return cors_response(status=INTERNAL_SERVER_ERROR,
                             xerror=str(e),
                             body=msg)
Beispiel #5
0
def slices_create_post(body, slice_name, ssh_key,
                       lease_end_time):  # noqa: E501
    """Create slice

    Request to create slice as described in the request. Request would be a graph ML describing the requested resources.
    Resources may be requested to be created now or in future. On success, one or more slivers are allocated, containing
    resources satisfying the request, and assigned to the given slice. This API returns list and description of the
    resources reserved for the slice in the form of Graph ML. Orchestrator would also trigger provisioning of these
    resources asynchronously on the appropriate sites either now or in the future as requested. Experimenter can invoke
    get slice API to get the latest state of the requested resources.   # noqa: E501

    :param body:
    :type body: dict | bytes
    :param slice_name: Slice Name
    :type slice_name: str
    :param ssh_key: User SSH Key
    :type ssh_key: str
    :param lease_end_time: Lease End Time for the Slice
    :type lease_end_time: str

    :rtype: Success
    """

    handler = OrchestratorHandler()
    logger = handler.get_logger()
    received_counter.labels(POST_METHOD, SLICES_CREATE_PATH).inc()

    try:
        token = get_token()
        slice_graph = body.decode("utf-8")
        value = handler.create_slice(token=token,
                                     slice_name=slice_name,
                                     slice_graph=slice_graph,
                                     ssh_key=ssh_key,
                                     lease_end_time=lease_end_time)
        response = Success()
        response.value = value
        success_counter.labels(POST_METHOD, SLICES_CREATE_PATH).inc()
        return response
    except OrchestratorException as e:
        logger.exception(e)
        failure_counter.labels(POST_METHOD, SLICES_CREATE_PATH).inc()
        msg = str(e).replace("\n", "")
        return cors_response(status=e.get_http_error_code(),
                             xerror=str(e),
                             body=msg)
    except Exception as e:
        logger.exception(e)
        failure_counter.labels(POST_METHOD, SLICES_CREATE_PATH).inc()
        msg = str(e).replace("\n", "")
        return cors_response(status=INTERNAL_SERVER_ERROR,
                             xerror=str(e),
                             body=msg)
def slivers_status_sliver_idget(slice_id, sliver_id):  # noqa: E501
    """slivers status

    Retrieve the status of a sliver. Status would include dynamic reservation or instantiation information.
    This API is used to provide updates on the state of the resources after the completion of create,
    which began to asynchronously provision the resources. The response would contain relatively dynamic data,
    not descriptive data as returned in the Graph ML.  # noqa: E501

    :param slice_id: Slice identifier as UUID
    :type slice_id: str
    :param sliver_id: Sliver identifier as UUID
    :type sliver_id: str

    :rtype: Success
    """
    handler = OrchestratorHandler()
    logger = handler.get_logger()
    received_counter.labels(GET_METHOD, SLIVERS_STATUS_SLIVER_ID_PATH).inc()
    try:
        token = get_token()
        value = handler.get_slivers(slice_id=slice_id,
                                    token=token,
                                    sliver_id=sliver_id,
                                    include_notices=True)
        response = Success()
        response.value = value
        success_counter.labels(GET_METHOD, SLIVERS_STATUS_SLIVER_ID_PATH).inc()
        return response
    except OrchestratorException as e:
        logger.exception(e)
        failure_counter.labels(GET_METHOD, SLIVERS_STATUS_SLIVER_ID_PATH).inc()
        msg = str(e).replace("\n", "")
        return cors_response(status=e.get_http_error_code(),
                             xerror=str(e),
                             body=msg)
    except Exception as e:
        logger.exception(e)
        failure_counter.labels(GET_METHOD, SLIVERS_STATUS_SLIVER_ID_PATH).inc()
        msg = str(e).replace("\n", "")
        return cors_response(status=INTERNAL_SERVER_ERROR,
                             xerror=str(e),
                             body=msg)
Beispiel #7
0
def slices_renew_slice_idpost(slice_id, new_lease_end_time):  # noqa: E501
    """Renew slice

    Request to extend slice be renewed with their expiration extended. If possible, the orchestrator should extend the
    slivers to the requested expiration time, or to a sooner time if policy limits apply.  # noqa: E501

    :param slice_id: Slice identifier as UUID
    :type slice_id: str
    :param new_lease_end_time: New Lease End Time for the Slice
    :type new_lease_end_time: str

    :rtype: Success
    """
    handler = OrchestratorHandler()
    logger = handler.get_logger()
    received_counter.labels(POST_METHOD, SLICES_RENEW_PATH).inc()

    try:
        token = get_token()
        value = handler.renew_slice(token=token,
                                    slice_id=slice_id,
                                    new_lease_end_time=new_lease_end_time)
        response = Success()
        response.value = value
        success_counter.labels(POST_METHOD, SLICES_RENEW_PATH).inc()
        return response
    except OrchestratorException as e:
        logger.exception(e)
        failure_counter.labels(POST_METHOD, SLICES_RENEW_PATH).inc()
        msg = str(e).replace("\n", "")
        return cors_response(status=e.get_http_error_code(),
                             xerror=str(e),
                             body=msg)
    except Exception as e:
        logger.exception(e)
        failure_counter.labels(POST_METHOD, SLICES_RENEW_PATH).inc()
        msg = str(e).replace("\n", "")
        return cors_response(status=INTERNAL_SERVER_ERROR,
                             xerror=str(e),
                             body=msg)
Beispiel #8
0
def version_get():  # noqa: E501
    """version

    Version # noqa: E501


    :rtype: Version
    """
    received_counter.labels(GET_METHOD, VERSIONS_PATH).inc()
    from fabric_cf.actor.core.container.globals import GlobalsSingleton
    logger = GlobalsSingleton.get().get_logger()
    try:
        version = __VERSION__
        tag = f"rel{__VERSION__}"
        url = "https://api.github.com/repos/fabric-testbed/ControlFramework/git/ref/tags/{}".format(
            tag)

        response = Version()
        response.version = version
        response.gitsha1 = 'Not Available'

        result = requests.get(url)
        if result.status_code == OK and result.json() is not None:
            object_json = result.json().get("object", None)
            if object_json is not None:
                sha = object_json.get("sha", None)
                if sha is not None:
                    response.gitsha1 = sha
        success_counter.labels(GET_METHOD, VERSIONS_PATH).inc()
    except Exception as e:
        logger.exception(e)
        failure_counter.labels(GET_METHOD, VERSIONS_PATH).inc()
        return cors_response(status=INTERNAL_SERVER_ERROR,
                             xerror=str(e),
                             body=str(e))
    return response
Beispiel #9
0
def slices_slice_idget(slice_id, graph_format):  # noqa: E501
    """slice properties

    Retrieve Slice properties # noqa: E501

    :param slice_id: Slice identifier as UUID
    :type slice_id: str

    :rtype: Success
    """
    handler = OrchestratorHandler()
    logger = handler.get_logger()
    received_counter.labels(GET_METHOD, SLICES_GET_SLICE_ID_PATH).inc()
    try:
        token = get_token()
        value = handler.get_slice_graph(token=token,
                                        slice_id=slice_id,
                                        graph_format_str=graph_format)
        response = Success()
        response.value = value
        success_counter.labels(GET_METHOD, SLICES_GET_SLICE_ID_PATH).inc()
        return response
    except OrchestratorException as e:
        logger.exception(e)
        failure_counter.labels(GET_METHOD, SLICES_GET_SLICE_ID_PATH).inc()
        msg = str(e).replace("\n", "")
        return cors_response(status=e.get_http_error_code(),
                             xerror=str(e),
                             body=msg)
    except Exception as e:
        logger.exception(e)
        failure_counter.labels(GET_METHOD, SLICES_GET_SLICE_ID_PATH).inc()
        msg = str(e).replace("\n", "")
        return cors_response(status=INTERNAL_SERVER_ERROR,
                             xerror=str(e),
                             body=msg)