diff --git a/CHANGES/517.feature b/CHANGES/517.feature new file mode 100644 index 000000000..f02f65983 --- /dev/null +++ b/CHANGES/517.feature @@ -0,0 +1 @@ +Added global distribution list command. diff --git a/pulpcore/cli/ansible/distribution.py b/pulpcore/cli/ansible/distribution.py index 6ab49efec..8cb5dd244 100644 --- a/pulpcore/cli/ansible/distribution.py +++ b/pulpcore/cli/ansible/distribution.py @@ -15,13 +15,11 @@ pass_pulp_context, ) from pulpcore.cli.common.generic import ( - base_path_contains_option, - base_path_option, create_command, destroy_command, + distribution_filter_options, href_option, label_command, - label_select_option, list_command, name_option, pulp_group, @@ -59,7 +57,6 @@ def distribution(ctx: click.Context, pulp_ctx: PulpContext, distribution_type: s raise NotImplementedError() -filter_options = [label_select_option, base_path_option, base_path_contains_option] lookup_options = [href_option, name_option] create_options = [ click.option("--name", required=True), @@ -73,7 +70,7 @@ def distribution(ctx: click.Context, pulp_ctx: PulpContext, distribution_type: s "--version", type=int, help=_("a repository version number, leave blank for latest") ), ] -distribution.add_command(list_command(decorators=filter_options)) +distribution.add_command(list_command(decorators=distribution_filter_options)) distribution.add_command(show_command(decorators=lookup_options)) distribution.add_command(destroy_command(decorators=lookup_options)) distribution.add_command(create_command(decorators=create_options)) diff --git a/pulpcore/cli/common/generic.py b/pulpcore/cli/common/generic.py index 607848e77..b5ad6aceb 100644 --- a/pulpcore/cli/common/generic.py +++ b/pulpcore/cli/common/generic.py @@ -676,6 +676,12 @@ def _type_callback(ctx: click.Context, param: click.Parameter, value: Optional[s pulp_last_updated_lte_option, ] +distribution_filter_options = name_filter_options + [ + label_select_option, + base_path_option, + base_path_contains_option, +] + publication_filter_options = [ content_in_option, pulp_created_gte_option, diff --git a/pulpcore/cli/container/distribution.py b/pulpcore/cli/container/distribution.py index 281ed76b8..3a1b3cc1d 100644 --- a/pulpcore/cli/container/distribution.py +++ b/pulpcore/cli/container/distribution.py @@ -10,13 +10,11 @@ pass_pulp_context, ) from pulpcore.cli.common.generic import ( - base_path_contains_option, - base_path_option, create_command, destroy_command, + distribution_filter_options, href_option, label_command, - label_select_option, list_command, name_option, pulp_group, @@ -63,7 +61,6 @@ def distribution(ctx: click.Context, pulp_ctx: PulpContext, distribution_type: s raise NotImplementedError() -filter_options = [label_select_option, base_path_option, base_path_contains_option] lookup_options = [href_option, name_option] create_options = [ click.option("--name", required=True), @@ -75,7 +72,7 @@ def distribution(ctx: click.Context, pulp_ctx: PulpContext, distribution_type: s click.option("--private/--public", default=None), ] -distribution.add_command(list_command(decorators=filter_options)) +distribution.add_command(list_command(decorators=distribution_filter_options)) distribution.add_command(show_command(decorators=lookup_options)) distribution.add_command(create_command(decorators=create_options)) distribution.add_command(destroy_command(decorators=lookup_options)) diff --git a/pulpcore/cli/core/__init__.py b/pulpcore/cli/core/__init__.py index 357327103..d566eab9b 100644 --- a/pulpcore/cli/core/__init__.py +++ b/pulpcore/cli/core/__init__.py @@ -6,6 +6,7 @@ from pulpcore.cli.core.artifact import artifact from pulpcore.cli.core.content import content from pulpcore.cli.core.content_guard import content_guard +from pulpcore.cli.core.distribution import distribution from pulpcore.cli.core.export import export from pulpcore.cli.core.exporter import exporter from pulpcore.cli.core.group import group @@ -34,6 +35,7 @@ def mount(main: click.Group, **kwargs: Any) -> None: main.add_command(exporter) main.add_command(group) main.add_command(content_guard) + main.add_command(distribution) main.add_command(importer) main.add_command(orphan) main.add_command(orphans) # This one is deprecated diff --git a/pulpcore/cli/core/context.py b/pulpcore/cli/core/context.py index fe28ed818..def1de90d 100644 --- a/pulpcore/cli/core/context.py +++ b/pulpcore/cli/core/context.py @@ -227,6 +227,13 @@ class PulpContentRedirectContentGuardContext(PulpEntityContext): ID_PREFIX = "contentguards_core_content_redirect" +class PulpDistributionContext(PulpEntityContext): + ENTITY = _("distribution") + ENTITIES = _("distributions") + ID_PREFIX = "distributions" + HREF_PATTERN = r"distributions/(?P\w+)/(?P\w+)/" + + class PulpImporterContext(PulpEntityContext): ENTITY = _("Pulp importer") ENTITIES = _("Pulp importers") diff --git a/pulpcore/cli/core/distribution.py b/pulpcore/cli/core/distribution.py new file mode 100644 index 000000000..83140e62a --- /dev/null +++ b/pulpcore/cli/core/distribution.py @@ -0,0 +1,22 @@ +import click + +from pulpcore.cli.common.context import PluginRequirement, PulpContext, pass_pulp_context +from pulpcore.cli.common.generic import distribution_filter_options, list_command, pulp_group +from pulpcore.cli.core.context import PulpDistributionContext + + +@pulp_group() +@pass_pulp_context +@click.pass_context +def distribution(ctx: click.Context, pulp_ctx: PulpContext) -> None: + """ + Perform actions on all distribution. + + Please look for the plugin specific distribution commands for more detailed actions. + i.e. 'pulp file distribution <...>' + """ + pulp_ctx.needs_plugin(PluginRequirement("core", "3.19.0")) + ctx.obj = PulpDistributionContext(pulp_ctx) + + +distribution.add_command(list_command(decorators=distribution_filter_options)) diff --git a/pulpcore/cli/file/distribution.py b/pulpcore/cli/file/distribution.py index 33eecf0d1..13950f195 100644 --- a/pulpcore/cli/file/distribution.py +++ b/pulpcore/cli/file/distribution.py @@ -2,13 +2,11 @@ from pulpcore.cli.common.context import PulpContext, pass_pulp_context from pulpcore.cli.common.generic import ( - base_path_contains_option, - base_path_option, create_command, destroy_command, + distribution_filter_options, href_option, label_command, - label_select_option, list_command, name_option, pulp_group, @@ -54,7 +52,6 @@ def distribution(ctx: click.Context, pulp_ctx: PulpContext, distribution_type: s raise NotImplementedError() -filter_options = [label_select_option, base_path_option, base_path_contains_option] lookup_options = [href_option, name_option] update_options = [ click.option("--base-path"), @@ -69,7 +66,7 @@ def distribution(ctx: click.Context, pulp_ctx: PulpContext, distribution_type: s ] create_options = update_options + [click.option("--name", required=True)] -distribution.add_command(list_command(decorators=filter_options)) +distribution.add_command(list_command(decorators=distribution_filter_options)) distribution.add_command(show_command(decorators=lookup_options)) distribution.add_command(create_command(decorators=create_options)) distribution.add_command(update_command(decorators=lookup_options + update_options)) diff --git a/pulpcore/cli/python/distribution.py b/pulpcore/cli/python/distribution.py index ff8466cd9..b7b545386 100644 --- a/pulpcore/cli/python/distribution.py +++ b/pulpcore/cli/python/distribution.py @@ -2,13 +2,11 @@ from pulpcore.cli.common.context import PluginRequirement, PulpContext, pass_pulp_context from pulpcore.cli.common.generic import ( - base_path_contains_option, - base_path_option, create_command, destroy_command, + distribution_filter_options, href_option, label_command, - label_select_option, list_command, name_option, pulp_group, @@ -66,7 +64,6 @@ def distribution(ctx: click.Context, pulp_ctx: PulpContext, distribution_type: s raise NotImplementedError() -filter_options = [label_select_option, base_path_option, base_path_contains_option] lookup_options = [href_option, name_option] update_options = [ click.option("--base-path"), @@ -87,7 +84,7 @@ def distribution(ctx: click.Context, pulp_ctx: PulpContext, distribution_type: s ] create_options = update_options + [click.option("--name", required=True)] -distribution.add_command(list_command(decorators=filter_options)) +distribution.add_command(list_command(decorators=distribution_filter_options)) distribution.add_command(show_command(decorators=lookup_options)) distribution.add_command(create_command(decorators=create_options)) distribution.add_command(update_command(decorators=lookup_options + update_options)) diff --git a/pulpcore/cli/rpm/distribution.py b/pulpcore/cli/rpm/distribution.py index ee28154f7..289c5a668 100644 --- a/pulpcore/cli/rpm/distribution.py +++ b/pulpcore/cli/rpm/distribution.py @@ -2,13 +2,11 @@ from pulpcore.cli.common.context import PulpContext, pass_pulp_context from pulpcore.cli.common.generic import ( - base_path_contains_option, - base_path_option, create_command, destroy_command, + distribution_filter_options, href_option, label_command, - label_select_option, list_command, name_option, pulp_group, @@ -52,7 +50,6 @@ def distribution(ctx: click.Context, pulp_ctx: PulpContext, distribution_type: s raise NotImplementedError() -filter_options = [label_select_option, base_path_option, base_path_contains_option] lookup_options = [href_option, name_option] update_options = [ click.option("--base-path"), @@ -69,7 +66,7 @@ def distribution(ctx: click.Context, pulp_ctx: PulpContext, distribution_type: s click.option("--name", required=True), ] -distribution.add_command(list_command(decorators=filter_options)) +distribution.add_command(list_command(decorators=distribution_filter_options)) distribution.add_command(show_command(decorators=lookup_options)) distribution.add_command(create_command(decorators=create_options)) distribution.add_command(update_command(decorators=lookup_options + update_options))