diff --git a/CHANGES/144.feature b/CHANGES/144.feature new file mode 100644 index 000000000..4f740bd9e --- /dev/null +++ b/CHANGES/144.feature @@ -0,0 +1 @@ +Added worker command. diff --git a/pulpcore/cli/core/__init__.py b/pulpcore/cli/core/__init__.py index 22e19e36b..c8ae1dc8d 100644 --- a/pulpcore/cli/core/__init__.py +++ b/pulpcore/cli/core/__init__.py @@ -11,6 +11,7 @@ from pulpcore.cli.core.status import status from pulpcore.cli.core.task import task from pulpcore.cli.core.user import user +from pulpcore.cli.core.worker import worker # Register commands with cli main.add_command(status) @@ -25,3 +26,4 @@ main.add_command(export) main.add_command(importer) main.add_command(config) +main.add_command(worker) diff --git a/pulpcore/cli/core/context.py b/pulpcore/cli/core/context.py index c328fa5b4..f604635c2 100644 --- a/pulpcore/cli/core/context.py +++ b/pulpcore/cli/core/context.py @@ -253,3 +253,10 @@ def find(self, **kwargs: Any) -> Any: if len(search_result) != 1: raise click.ClickException(f"Could not find {self.ENTITY} with {kwargs}.") return search_result[0] + + +class PulpWorkerContext(PulpEntityContext): + ENTITY = "worker" + HREF = "worker_href" + LIST_ID = "workers_list" + READ_ID = "workers_read" diff --git a/pulpcore/cli/core/worker.py b/pulpcore/cli/core/worker.py new file mode 100644 index 000000000..bc8f57924 --- /dev/null +++ b/pulpcore/cli/core/worker.py @@ -0,0 +1,24 @@ +import click + +from pulpcore.cli.common.context import PulpContext, pass_pulp_context +from pulpcore.cli.common.generic import href_option, list_command, name_option, show_command +from pulpcore.cli.core.context import PulpWorkerContext + + +@click.group() +@pass_pulp_context +@click.pass_context +def worker(ctx: click.Context, pulp_ctx: PulpContext) -> None: + ctx.obj = PulpWorkerContext(pulp_ctx) + + +filter_options = [ + click.option("--name"), + click.option("--name-contains", "name__contains"), + click.option("--name-icontains", "name__icontains"), + click.option("--missing/--not-missing", default=None), + click.option("--online/--not-online", default=None), +] + +worker.add_command(list_command(decorators=filter_options)) +worker.add_command(show_command(decorators=[href_option, name_option])) diff --git a/tests/scripts/pulpcore/test_worker.sh b/tests/scripts/pulpcore/test_worker.sh new file mode 100755 index 000000000..7bc4b7b17 --- /dev/null +++ b/tests/scripts/pulpcore/test_worker.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +# shellcheck source=tests/scripts/config.source +. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source + +expect_succ pulp worker list +href=$(echo "$OUTPUT" | jq -r ".[0].pulp_href") +expect_succ pulp worker show --href "$href" + +expect_succ pulp worker list --missing +expect_succ pulp worker list --not-missing +expect_succ pulp worker list --online +expect_succ pulp worker list --not-online +expect_succ pulp worker list --name "resource-manager" + +if pulp debug has-plugin --name "pulpcore" --min-version "3.10.0" +then + expect_succ pulp worker list --name-contains "resource" +fi