Exemplo n.º 1
0
def start_workspace(id_, start_with_latest_version=False, **kwargs):
    """Start a job
    :param id_: The ID of the workspace resource
    :type id_: str
    :param start_with_latest_version: Start job with the latest revision of the project
    :type start_with_latest_version: bool

    :rtype: StatusSerializer
    """
    w = get_workspace_object(id_)
    check_workspace_permission(w, kwargs["token_info"])
    stub = get_workspaces_services_stub()

    if start_with_latest_version:
        w.spec.revision = get_latest_project_revision(w.metadata.project)
        w = stub.Update(w)

    response = stub.Start(job_pb2.ID(id=w.id))

    if response.status != 200:
        return ErrorSerializer(status=response.status,
                               title="Api Error",
                               detail=response.message), response.status

    return StatusSerializer.from_dict(util.deserialize_protobuf(response))
Exemplo n.º 2
0
def create_workspace(body, **kwargs):
    """Create a workspace
    :param body: Workspace payload
    :type body: dict | bytes

    :rtype: WorkspaceSerializer
    """
    serializer = WorkspaceSerializer.from_dict(body)
    check_workspace_permission(serializer, kwargs["token_info"])

    stub = get_workspaces_services_stub()
    response = stub.Create(job_pb2.Workspace(**body))

    return WorkspaceSerializer.from_dict(util.deserialize_protobuf(response))
Exemplo n.º 3
0
def status_workspace(id_, **kwargs):
    """Get state of a workspace.
    :param id_: The ID of the workspace resource
    :type id_: str

    :rtype: Object
    """
    w = get_workspace_object(id_)
    check_workspace_permission(w, kwargs["token_info"])

    stub = get_workspaces_services_stub()
    response = stub.State(job_pb2.ID(id=id_))

    return util.deserialize_protobuf(response)
Exemplo n.º 4
0
def delete_workspace(id_, **kwargs):
    """Delete a workspace
    :param id_: The ID of the workspace resource
    :type id_: str

    :rtype: StatusSerializer
    """
    w = get_workspace_object(id_)
    check_workspace_permission(w, kwargs["token_info"])

    stub = get_workspaces_services_stub()
    response = stub.Delete(job_pb2.ID(id=id_))

    if response.status != 200:
        return ErrorSerializer(status=response.status,
                               title="Api Error",
                               detail=response.message), response.status

    return StatusSerializer.from_dict(util.deserialize_protobuf(response))
Exemplo n.º 5
0
def list_project_workspaces(id_, limit=None, page=None, **kwargs):
    """List project's workspaces

    :param id_: The ID of the project resource
    :type id_: str
    :param limit: 
    :type limit: int
    :param page: 
    :type page: int

    :rtype: PageTokenListSerializer
    """
    proj = get_project_object(id_)
    check_project_permission(proj, kwargs["token_info"])

    stub = get_workspaces_services_stub()
    response = stub.Search(
        job_pb2.SearchRequest(query={"project": proj.id},
                              limit=limit,
                              page=page))
    return util.deserialize_protobuf(response)
Exemplo n.º 6
0
def get_workspace_object(workspace_id):
    stub = get_workspaces_services_stub()
    return stub.Retrieve(job_pb2.ID(id=workspace_id))