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/log.err b/log.err new file mode 100644 index 000000000..e69de29bb diff --git a/log.out b/log.out new file mode 100644 index 000000000..c3b1d9e23 --- /dev/null +++ b/log.out @@ -0,0 +1 @@ +[{"pulp_created": "2021-02-13T13:33:04.220502Z", "pulp_href": "/pulp/api/v3/workers/3754d4ea-b554-432d-b20e-45026ce46c12/", "name": "resource-manager", "last_heartbeat": "2021-02-13T22:16:02.245766Z"}] 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..1159a12fd --- /dev/null +++ b/pulpcore/cli/core/worker.py @@ -0,0 +1,27 @@ +import click + +from pulpcore.cli.common.context import ( + PulpContext, + pass_pulp_context, +) +from pulpcore.cli.common.generic import list_command, show_command, href_option, name_option +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..1f1d7ed12 --- /dev/null +++ b/tests/scripts/pulpcore/test_worker.sh @@ -0,0 +1,15 @@ +#!/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" +expect_succ pulp worker list --name-contains "resource"