remote_option = resource_option( "--remote", default_plugin="rpm", default_type="rpm", context_table={"rpm:rpm": PulpRpmRemoteContext}, href_pattern=PulpRemoteContext.HREF_PATTERN, help= _("Remote to attach to ACS in the form '[[<plugin>:]<resource_type>:]<name>' or by href." ), ) lookup_options = [href_option, name_option] update_options = [remote_option] create_options = update_options + [ click.option("--name", required=True), path_option ] acs.add_command(list_command()) acs.add_command(show_command(decorators=lookup_options)) acs.add_command(create_command(decorators=create_options)) acs.add_command(update_command(decorators=lookup_options + update_options)) acs.add_command(destroy_command(decorators=lookup_options)) @acs.command() @pass_entity_context @pass_pulp_context @href_option @name_option def refresh(pulp_ctx: PulpContext, acs_ctx: PulpRpmACSContext) -> None: acs_ctx.refresh(acs_ctx.pulp_href)
if remote_type == "container": ctx.obj = PulpContainerRemoteContext(pulp_ctx) else: raise NotImplementedError() lookup_options = [href_option, name_option] remote_options = [ click.option( "--policy", type=click.Choice(["immediate", "on_demand", "streamed"], case_sensitive=False) ), click.option("--include-tags", callback=load_json_callback), click.option("--exclude-tags", callback=load_json_callback), ] remote_create_options = ( common_remote_create_options + remote_options + [click.option("--upstream-name", required=True)] ) remote_update_options = ( lookup_options + common_remote_update_options + remote_options + [click.option("--upstream-name")] ) remote.add_command(list_command(decorators=[label_select_option])) remote.add_command(show_command(decorators=lookup_options)) remote.add_command(create_command(decorators=remote_create_options)) remote.add_command(update_command(decorators=remote_update_options)) remote.add_command(destroy_command(decorators=lookup_options)) remote.add_command(label_command())
groupname_option = click.option("--groupname", callback=_groupname_callback, expose_value=False) _ = gettext.gettext @click.group(help=_("Manage user groups and their granted permissions.")) @pass_pulp_context @click.pass_context def group(ctx: click.Context, pulp_ctx: PulpContext) -> None: ctx.obj = PulpGroupContext(pulp_ctx) lookup_options = [name_option, href_option] create_options = [click.option("--name", required=True)] group.add_command(list_command()) group.add_command(show_command(decorators=lookup_options)) group.add_command(destroy_command(decorators=lookup_options)) group.add_command(create_command(decorators=create_options)) @group.group() @click.option( "-t", "--type", "perm_type", type=click.Choice(["model", "object"], case_sensitive=False), default="model", ) @pass_entity_context @pass_pulp_context
"-t", "--type", "publication_type", type=click.Choice(["file"], case_sensitive=False), default="file", ) @pass_pulp_context @click.pass_context def publication(ctx: click.Context, pulp_ctx: PulpContext, publication_type: str) -> None: if publication_type == "file": ctx.obj = PulpFilePublicationContext(pulp_ctx) else: raise NotImplementedError() publication.add_command(list_command()) publication.add_command(show_command(decorators=[href_option])) publication.add_command(destroy_command(decorators=[href_option])) @publication.command() @click.option("--repository", required=True) @click.option("--version", type=int, help="a repository version number, leave blank for latest") @pass_entity_context @pass_pulp_context def create( pulp_ctx: PulpContext, publication_ctx: PulpFilePublicationContext, repository: str, version: Optional[int], ) -> None:
from pulpcore.cli.core.context import PulpTaskContext @click.group() @pass_pulp_context @click.pass_context def task(ctx: click.Context, pulp_ctx: PulpContext) -> None: ctx.obj = PulpTaskContext(pulp_ctx) task.add_command( list_command(decorators=[ click.option("--name", help="List only tasks with this name."), click.option( "--name-contains", "name__contains", help="List only tasks whose name contains this.", ), click.option("--state", help="List only tasks in this state."), ])) @task.command() @click.option("--href", required=True, help="HREF of the task") @click.option("-w", "--wait", is_flag=True, help="Wait for the task to finish") @pass_entity_context @pass_pulp_context def show(pulp_ctx: PulpContext, task_ctx: PulpTaskContext, href: str, wait: bool) -> None: """Shows details of a task.""" entity = task_ctx.show(href)
@pass_pulp_context @click.pass_context def repository(ctx: click.Context, pulp_ctx: PulpContext) -> None: """ Perform actions on all repositories. Please look for the plugin specific repository commands for more detailed actions. i.e. 'pulp file repository <...>' """ pulp_ctx.needs_plugin("core", min_version="3.10.dev") ctx.obj = PulpRepositoryContext(pulp_ctx) filter_options = [ click.option("--name"), click.option( "--name-contains", "name__contains", ), click.option( "--name-icontains", "name__icontains", ), click.option( "--name-in", "name__in", ), ] repository.add_command(list_command(decorators=filter_options))
@click.group() @click.option( "-t", "--type", "publication_type", type=click.Choice(["pypi"], case_sensitive=False), default="pypi", ) @pass_pulp_context @click.pass_context def publication(ctx: click.Context, pulp_ctx: PulpContext, publication_type: str) -> None: if publication_type == "pypi": ctx.obj = PulpPythonPublicationContext(pulp_ctx) else: raise NotImplementedError() lookup_options = [href_option] create_options = [ repository_option, click.option( "--version", type=int, help=_("a repository version number, leave blank for latest") ), ] publication.add_command(list_command(decorators=publication_filter_options)) publication.add_command(show_command(decorators=lookup_options)) publication.add_command(create_command(decorators=create_options)) publication.add_command(destroy_command(decorators=lookup_options))
"distribution_type", type=click.Choice(["file"], case_sensitive=False), default="file", ) @pass_pulp_context @click.pass_context def distribution(ctx: click.Context, pulp_ctx: PulpContext, distribution_type: str) -> None: if distribution_type == "file": ctx.obj = PulpFileDistributionContext(pulp_ctx) else: 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"), click.option("--publication"), click.option("--repository", callback=_repository_callback), ] create_options = update_options + [ click.option("--name", required=True), ] distribution.add_command(list_command(decorators=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)) distribution.add_command(destroy_command(decorators=lookup_options)) distribution.add_command(label_command())
from pulpcore.cli.common.context import PulpContext, pass_entity_context, pass_pulp_context from pulpcore.cli.common.generic import list_command from pulpcore.cli.core.context import PulpTaskContext from pulpcore.cli.core.generic import task_filter _ = gettext.gettext @click.group() @pass_pulp_context @click.pass_context def task(ctx: click.Context, pulp_ctx: PulpContext) -> None: ctx.obj = PulpTaskContext(pulp_ctx) task.add_command(list_command(decorators=task_filter)) @task.command() @click.option("--href", required=True, help=_("HREF of the task")) @click.option("-w", "--wait", is_flag=True, help=_("Wait for the task to finish")) @pass_entity_context @pass_pulp_context 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", "canceling"]:
type=click.Choice(["file"], case_sensitive=False), default="file", ) @pass_pulp_context @click.pass_context def content(ctx: click.Context, pulp_ctx: PulpContext, content_type: str) -> None: if content_type == "file": ctx.obj = PulpFileContentContext(pulp_ctx) else: raise NotImplementedError() content.add_command( list_command(decorators=[ click.option("--relative-path", type=str), click.option("--sha256", type=str), ])) content.add_command(show_command(decorators=[href_option])) @content.command() @click.option("--relative-path", required=True) @click.option("--sha256", required=True, help="Digest of the artifact to use") @pass_entity_context @pass_pulp_context def create( pulp_ctx: PulpContext, entity_ctx: PulpFileContentContext, relative_path: str, sha256: str, ) -> None:
elif repo_type == "push": ctx.obj = PulpContainerPushRepositoryContext(pulp_ctx) else: raise NotImplementedError() lookup_options = [href_option, name_option] nested_lookup_options = [repository_href_option, repository_option] update_options = [ click.option("--description"), remote_option, retained_versions_option, ] create_options = update_options + [click.option("--name", required=True)] repository.add_command(list_command(decorators=[label_select_option])) repository.add_command(show_command(decorators=lookup_options)) repository.add_command(create_command(decorators=create_options)) repository.add_command( update_command(decorators=lookup_options + update_options)) repository.add_command(destroy_command(decorators=lookup_options)) repository.add_command(task_command(decorators=nested_lookup_options)) repository.add_command(version_command(decorators=nested_lookup_options)) repository.add_command(label_command(decorators=nested_lookup_options)) @repository.command() @name_option @href_option @remote_option @pass_repository_context
"--base-path", required=True, help=_("the base (relative) path component of the published url."), ), click.option( "--repository", required=True, callback=_repository_callback, help=_("repository with content to distribute"), ), click.option( "--version", type=int, help=_("a repository version number, leave blank for latest")), ] distribution.add_command(list_command(decorators=[label_select_option])) distribution.add_command(show_command(decorators=lookup_options)) distribution.add_command(destroy_command(decorators=lookup_options)) distribution.add_command(create_command(decorators=create_options)) # TODO Add content_guard option @distribution.command() @name_option @href_option @click.option("--base-path", help=_("new base_path")) @click.option("--repository", type=str, default=None, help=_("new repository to be served")) @click.option(
callback=_relative_path_callback, expose_value=False), click.option("--sha256", callback=_sha256_callback, expose_value=False), ] create_options = [ click.option("--relative-path", required=True), click.option( "--sha256", "artifact", required=True, help=_("Digest of the artifact to use"), callback=_sha256_artifact_callback, ), ] content.add_command(list_command(decorators=list_options)) content.add_command(show_command(decorators=lookup_options)) content.add_command(create_command(decorators=create_options)) @content.command() @click.option("--relative-path", required=True) @click.option("--file", type=click.File("rb"), required=True) @chunk_size_option @pass_entity_context @pass_pulp_context def upload( pulp_ctx: PulpContext, entity_ctx: PulpRpmPackageContext, relative_path: str, file: IO[bytes],
import click from pulpcore.cli.common.context import PulpContext, pass_pulp_context from pulpcore.cli.common.generic import href_option, list_command, show_command from pulpcore.cli.common.i18n import get_translation from pulpcore.cli.core.context import PulpTaskGroupContext translation = get_translation(__name__) _ = translation.gettext @click.group() @pass_pulp_context @click.pass_context def task_group(ctx: click.Context, pulp_ctx: PulpContext) -> None: ctx.obj = PulpTaskGroupContext(pulp_ctx) task_group.add_command(list_command()) task_group.add_command(show_command(decorators=[href_option]))
@pass_pulp_context @click.pass_context def access_policy(ctx: click.Context, pulp_ctx: PulpContext) -> None: ctx.obj = PulpAccessPolicyContext(pulp_ctx) lookup_options = [ href_option, click.option("--viewset-name", callback=_vs_name_callback, expose_value=False), ] update_options = [ click.option("--statements", callback=load_json_callback), click.option("--creation-hooks", callback=load_json_callback), ] access_policy.add_command(list_command()) access_policy.add_command(show_command(decorators=lookup_options)) access_policy.add_command(update_command(decorators=lookup_options + update_options)) @access_policy.command() @href_option @click.option("--viewset-name", callback=_vs_name_callback, expose_value=False) @pass_entity_context @pass_pulp_context def reset(pulp_ctx: PulpContext, access_policy_ctx: PulpAccessPolicyContext) -> None: pulp_ctx.needs_plugin(PluginRequirement("core", min="3.17.dev")) result = access_policy_ctx.reset() pulp_ctx.output_result(result)
@click.group() def importer() -> None: pass @importer.group() @pass_pulp_context @click.pass_context def pulp(ctx: click.Context, pulp_ctx: PulpContext) -> None: ctx.obj = PulpImporterContext(pulp_ctx) filter_options = [click.option("--name")] lookup_options = [name_option, href_option] pulp.add_command(list_command(decorators=filter_options)) pulp.add_command(show_command(decorators=lookup_options)) pulp.add_command(destroy_command(decorators=lookup_options)) @pulp.command() @click.option("--name", required=True) @repo_map_option @pass_entity_context @pass_pulp_context def create( pulp_ctx: PulpContext, importer_ctx: PulpImporterContext, name: str, repo_map: List[RepositoryMap], ) -> None: