コード例 #1
0
ファイル: status.py プロジェクト: ggainey/pulp-cli
def status(pulp_ctx: PulpContext, retries: int, retry_delay: int) -> None:
    """
    Retrieve pulp status. And refresh outdated local api caches if server versions changed.
    """
    if retries < 0:
        raise click.ClickException(_("Cannot specify a negative retry count."))
    retries_left = retries
    while True:
        try:
            result = pulp_ctx.call("status_read")
        except click.ClickException:
            if retries_left:
                retries_left = retries_left - 1
                click.echo(".", nl=False, err=True)
                time.sleep(retry_delay)
            else:
                if retries:
                    click.echo(" Failed.", err=True)
                raise
        else:
            if retries:
                click.echo(" Ready.", err=True)
            break

    component_versions = {
        item["component"]: item["version"]
        for item in result.get("versions", [])
    }
    if component_versions != pulp_ctx.component_versions:
        click.echo("Notice: Cached api is outdated. Refreshing...", err=True)
        pulp_ctx.api.load_api(refresh_cache=True)
        result = pulp_ctx.call("status_read")
    pulp_ctx.output_result(result)
コード例 #2
0
def cleanup(pulp_ctx: PulpContext, **kwargs: Any) -> None:
    """
    Cleanup orphaned content.
    """
    body = {k: v for k, v in kwargs.items() if v is not None}
    if pulp_ctx.has_plugin(PluginRequirement("core", "3.14")):
        result = pulp_ctx.call("orphans_cleanup_cleanup", body=body)
    else:
        result = pulp_ctx.call("orphans_delete")
    pulp_ctx.output_result(result)
コード例 #3
0
ファイル: status.py プロジェクト: melcorr/pulp-cli
def status(pulp_ctx: PulpContext) -> None:
    """
    Retrieve pulp status. And refresh outdated local api caches if server versions changed.
    """
    result = pulp_ctx.call("status_read")
    component_versions = {
        item["component"]: item["version"]
        for item in result.get("versions", [])
    }
    if component_versions != pulp_ctx.component_versions:
        click.echo("Notice: Cached api is outdated. Refreshing...", err=True)
        pulp_ctx.api.load_api(refresh_cache=True)
        result = pulp_ctx.call("status_read")
    pulp_ctx.output_result(result)
コード例 #4
0
def call(
    pulp_ctx: PulpContext,
    operation_id: str,
    parameters: Iterable[str],
    body: Any,
    uploads: Iterable[IO[bytes]],
) -> None:
    """
    Make a REST call by operation-id.

    WARNING: Danger ahead!
    """
    try:
        params: Dict[str, str] = dict(
            parameter.partition("=")[::2] for parameter in parameters)
    except ValueError:
        raise click.ClickException(
            "Parameters must be in the form <key>=<value>.")
    uploads_dict: Dict[str,
                       bytes] = {file.name: file.read()
                                 for file in uploads}
    result = pulp_ctx.call(operation_id,
                           parameters=params,
                           body=body,
                           uploads=uploads_dict)
    pulp_ctx.output_result(result)
コード例 #5
0
def task_summary(pulp_ctx: PulpContext) -> None:
    """
    List a summary of tasks by status.
    """
    from pulpcore.cli.core.context import PulpTaskContext

    TASK_STATES = [
        "waiting", "skipped", "running", "completed", "failed", "canceled"
    ]
    if pulp_ctx.has_plugin(PluginRequirement("core", min="3.14")):
        TASK_STATES.append("canceling")
    result = {}
    for state in TASK_STATES:
        payload = {"limit": 1, "state": state}
        answer = pulp_ctx.call(PulpTaskContext.LIST_ID, parameters=payload)
        result[state] = answer["count"]
    pulp_ctx.output_result(result)
コード例 #6
0
ファイル: orphans.py プロジェクト: ggainey/pulp-cli
def delete(pulp_ctx: PulpContext) -> None:
    """
    Use pulp 'orphan cleanup' instead.
    """
    result = pulp_ctx.call("orphans_delete")
    pulp_ctx.output_result(result)
コード例 #7
0
def delete(pulp_ctx: PulpContext) -> None:
    result = pulp_ctx.call("orphans_delete")
    pulp_ctx.output_result(result)
コード例 #8
0
def show(pulp_ctx: PulpContext, href: str) -> None:
    """Show any resource given its href."""
    # use a random read operation to call the href
    entity = pulp_ctx.call("artifacts_read",
                           parameters={"artifact_href": href})
    pulp_ctx.output_result(entity)