Ejemplo n.º 1
0
def purge(
    pulp_ctx: PulpContext,
    task_ctx: PulpTaskContext,
    finished: Optional[datetime],
    state: Optional[Tuple[str]],
) -> None:
    pulp_ctx.needs_plugin(PluginRequirement("core", "3.17.0.dev"))
    state_list = list(state) if state else None
    finished_str = finished.strftime(DATETIME_FORMATS[1]) if finished else None
    task_ctx.purge(finished_str, state_list)
Ejemplo n.º 2
0
 def callback(
     ctx: click.Context,
     pulp_ctx: PulpContext,
     entity_ctx: PulpEntityContext,
 ) -> None:
     ctx.obj = PulpTaskContext(pulp_ctx)
     ctx.obj.resource_context = entity_ctx
Ejemplo n.º 3
0
def cancel(pulp_ctx: PulpContext, task_ctx: PulpTaskContext,
           href: str) -> None:
    """Cancels a task and waits until the cancellation is confirmed."""
    entity = task_ctx.show(href)
    if entity["state"] not in ["waiting", "running"]:
        click.ClickException(
            f"Task {href} is in state {entity['state']} and cannot be canceled."
        )

    task_ctx.cancel(href)
    click.echo(f"Waiting to cancel task {href}", err=True)
    try:
        pulp_ctx.wait_for_task(entity)
    except Exception as e:
        if str(e) != "Task canceled":
            raise e
    click.echo("Done.", err=True)
Ejemplo n.º 4
0
def show(pulp_ctx: PulpContext, task_ctx: PulpTaskContext, href: str,
         wait: bool) -> None:
    """Shows details of a task."""
    entity = task_ctx.show(href)
    if wait and entity["state"] in ["waiting", "running"]:
        click.echo(f"Waiting for task {href} to finish.", err=True)
        entity = pulp_ctx.wait_for_task(entity)
    pulp_ctx.output_result(entity)
Ejemplo n.º 5
0
def cancel(
    pulp_ctx: PulpContext,
    task_ctx: PulpTaskContext,
    all_tasks: bool,
    waiting_tasks: bool,
    running_tasks: bool,
) -> None:
    """Cancels a task and waits until the cancellation is confirmed."""
    states = []
    if waiting_tasks or all_tasks:
        states.append("waiting")
    if running_tasks or all_tasks:
        states.append("running")
    if states:
        tasks = task_ctx.list(limit=1 << 64,
                              offset=0,
                              parameters={"state__in": ",".join(states)})
        for task in tasks:
            with suppress(Exception):
                task_ctx.cancel(task["pulp_href"])
        for task in tasks:
            with suppress(Exception):
                pulp_ctx.wait_for_task(task)
    else:
        entity = task_ctx.entity
        if entity["state"] not in ["waiting", "running"]:
            click.ClickException(
                _("Task {href} is in state {state} and cannot be canceled.").
                format(href=task_ctx.pulp_href, state=entity["state"]))

        task_ctx.cancel(task_ctx.pulp_href)
        click.echo(
            _("Waiting to cancel task {href}").format(href=task_ctx.pulp_href),
            err=True)
        try:
            pulp_ctx.wait_for_task(entity)
        except Exception as e:
            if not re.match("Task /pulp/api/v3/tasks/[-0-9a-f]*/ canceled",
                            str(e)):
                raise e
        click.echo(_("Done."), err=True)
Ejemplo n.º 6
0
def task(ctx: click.Context, pulp_ctx: PulpContext) -> None:
    ctx.obj = PulpTaskContext(pulp_ctx)