コード例 #1
0
def _get_servers(project_id, name=None, status=None):
    """List servers in the given project."""
    client = faculty.client("server")
    servers = client.list(project_id, name)
    if status is not None:
        servers = [s for s in servers if s.status == status]
    return servers
コード例 #2
0
def ls(project, path):
    """List files and directories on Faculty workspace."""
    if not path.startswith("/project"):
        _print_and_exit("{} is outside the project workspace".format(path), 66)

    project_id = _resolve_project(project)
    relative_path = os.path.relpath(path, "/project")
    client = faculty.client("workspace")

    try:
        directory_details_list = client.list(project_id=project_id,
                                             prefix=relative_path,
                                             depth=1)
    except faculty.clients.base.NotFound:
        _print_and_exit("{}: No such file or directory".format(path), 66)

    try:
        [directory_details] = directory_details_list
    except ValueError:
        _print_and_exit("Zero or more than one objects returned", 70)

    for item in directory_details.content:
        if hasattr(item, "content"):
            click.echo("/project{}/".format(item.path))
        else:
            click.echo("/project{}".format(item.path))
コード例 #3
0
def _job_by_name(project_id, job_name):
    """Resolve a project ID and job name to a job ID."""
    client = faculty.client("job")
    jobs = client.list(project_id)
    matching_jobs = [job for job in jobs if job.metadata.name == job_name]
    if len(matching_jobs) == 1:
        return matching_jobs[0]
    else:
        if not matching_jobs:
            msg = 'no job of name "{}" in this project'.format(job_name)
            raise NameNotFoundError(msg)
        else:
            msg = ('more than one job of name "{}", please select by job ID '
                   "instead").format(job_name)
            raise AmbiguousNameError(msg)
コード例 #4
0
def _environment_by_name(project_id, environment_name):
    client = faculty.client("environment")
    environments = client.list(project_id)
    matching_environments = [
        e for e in environments if e.name == environment_name
    ]
    if len(matching_environments) == 1:
        return matching_environments[0]
    else:
        if not matching_environments:
            msg = 'no available environment of name "{}"'.format(
                environment_name)
            raise NameNotFoundError(msg)
        else:
            msg = ('more than one environment of name "{}", please select by '
                   "environment ID instead").format(environment_name)
            raise AmbiguousNameError(msg)
コード例 #5
0
def list_environments(project, verbose):
    """List your environments."""
    client = faculty.client("environment")
    project_id = _resolve_project(project)
    environments = client.list(project_id)
    if verbose:
        if not environments:
            click.echo("No environments.")
        else:
            click.echo(
                tabulate(
                    [(e.name, e.id) for e in environments],
                    ("Environment Name", "ID"),
                    tablefmt="plain",
                ))
    else:
        for environment in environments:
            click.echo(environment.name)
コード例 #6
0
def list_jobs(project, verbose):
    """List the jobs in a project."""

    project_id = _resolve_project(project)

    client = faculty.client("job")
    jobs = client.list(project_id)
    if verbose:
        if not jobs:
            click.echo("No jobs.")
        else:
            rows = [(job.metadata.name, job.id, job.metadata.description)
                    for job in jobs]
            click.echo(
                tabulate(rows, ("Name", "ID", "Description"),
                         tablefmt="plain"))
    else:
        for job in jobs:
            click.echo(job.metadata.name)