Skip to content

Commit

Permalink
Add global distribution commands
Browse files Browse the repository at this point in the history
fixes: pulp#517
  • Loading branch information
gerrod3 committed Jul 8, 2022
1 parent 364cf3d commit 1801c0c
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGES/517.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added global distribution list command.
7 changes: 2 additions & 5 deletions pulpcore/cli/ansible/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand All @@ -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))
Expand Down
6 changes: 6 additions & 0 deletions pulpcore/cli/common/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 2 additions & 5 deletions pulpcore/cli/container/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand All @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions pulpcore/cli/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions pulpcore/cli/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<plugin>\w+)/(?P<resource_type>\w+)/"


class PulpImporterContext(PulpEntityContext):
ENTITY = _("Pulp importer")
ENTITIES = _("Pulp importers")
Expand Down
22 changes: 22 additions & 0 deletions pulpcore/cli/core/distribution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import click

from pulpcore.cli.common.context import PulpContext, pass_pulp_context, PluginRequirement
from pulpcore.cli.common.generic import list_command, pulp_group, distribution_filter_options
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))
7 changes: 2 additions & 5 deletions pulpcore/cli/file/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"),
Expand All @@ -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))
Expand Down
7 changes: 2 additions & 5 deletions pulpcore/cli/python/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"),
Expand All @@ -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))
Expand Down
7 changes: 2 additions & 5 deletions pulpcore/cli/rpm/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"),
Expand All @@ -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))
Expand Down

0 comments on commit 1801c0c

Please sign in to comment.