示例#1
0
def sync(
    repository_ctx: PulpRepositoryContext,
    remote: EntityFieldDefinition,
    mirror: Optional[bool],
    skip_types: Iterable[str],
) -> None:
    repository = repository_ctx.entity
    repository_href = repository_ctx.pulp_href

    body: Dict[str, Any] = {}

    if mirror:
        body["mirror"] = mirror
    if skip_types:
        body["skip_types"] = skip_types

    if isinstance(remote, PulpEntityContext):
        body["remote"] = remote.pulp_href
    elif repository["remote"] is None:
        raise click.ClickException(
            _("Repository '{name}' does not have a default remote. "
              "Please specify with '--remote'.").format(
                  name=repository["name"]))

    repository_ctx.sync(
        href=repository_href,
        body=body,
    )
示例#2
0
def sync(
    pulp_ctx: PulpContext,
    repository_ctx: PulpRepositoryContext,
    name: str,
    remote: Optional[str],
    mirror: Optional[bool],
) -> None:
    repository = repository_ctx.find(name=name)
    repository_href = repository["pulp_href"]

    body: Dict[str, Any] = {}

    if mirror:
        body["mirror"] = mirror

    if remote:
        remote_href: str = PulpRpmRemoteContext(pulp_ctx).find(
            name=remote)["pulp_href"]
        body["remote"] = remote_href
    elif repository["remote"] is None:
        raise click.ClickException(
            f"Repository '{name}' does not have a default remote. Please specify with '--remote'."
        )

    repository_ctx.sync(
        href=repository_href,
        body=body,
    )
示例#3
0
def remove(
    pulp_ctx: PulpContext,
    repository_ctx: PulpRepositoryContext,
    sha256: str,
    relative_path: str,
    base_version: Optional[int],
) -> None:
    """Please use 'content remove' instead."""
    repository_href = repository_ctx.pulp_href

    base_version_href: Optional[str]
    if base_version is not None:
        base_version_href = f"{repository_href}versions/{base_version}/"
    else:
        base_version_href = None

    content_href = PulpFileContentContext(
        pulp_ctx, entity={"sha256": sha256, "relative_path": relative_path}
    ).pulp_href

    repository_ctx.modify(
        href=repository_href,
        remove_content=[content_href],
        base_version=base_version_href,
    )
示例#4
0
def modify(
    pulp_ctx: PulpContext,
    repository_ctx: PulpRepositoryContext,
    add_content: List[Dict[str, str]],
    remove_content: List[Dict[str, str]],
    base_version: Optional[int],
) -> None:
    """Please use 'content modify' instead."""
    repository_href = repository_ctx.pulp_href

    base_version_href: Optional[str]
    if base_version is not None:
        base_version_href = f"{repository_href}versions/{base_version}/"
    else:
        base_version_href = None

    add_content_href = [
        PulpFileContentContext(pulp_ctx, entity=unit).pulp_href for unit in add_content
    ]
    remove_content_href = [
        PulpFileContentContext(pulp_ctx, entity=unit).pulp_href for unit in remove_content
    ]

    repository_ctx.modify(
        href=repository_href,
        add_content=add_content_href,
        remove_content=remove_content_href,
        base_version=base_version_href,
    )
示例#5
0
def update(
    pulp_ctx: PulpContext,
    repository_ctx: PulpRepositoryContext,
    name: str,
    description: Optional[str],
    remote: Optional[str],
) -> None:
    repository = repository_ctx.find(name=name)
    repository_href = repository["pulp_href"]

    if description is not None:
        if description == "":
            # unset the description
            description = None
        if description != repository["description"]:
            repository["description"] = description

    if remote is not None:
        if remote == "":
            # unset the remote
            repository["remote"] = ""
        elif remote:
            remote_href: str = PulpContainerRemoteContext(pulp_ctx).find(
                name=remote)["pulp_href"]
            repository["remote"] = remote_href

    repository_ctx.update(repository_href, body=repository)
示例#6
0
def sync(
    pulp_ctx: PulpContext,
    repository_ctx: PulpRepositoryContext,
    name: str,
    remote: Optional[str],
) -> None:
    if repository_ctx.SYNC_ID is None:
        raise click.ClickException("Repository type does not support sync.")

    repository = repository_ctx.find(name=name)
    repository_href = repository["pulp_href"]

    body = {}

    if remote:
        remote_href: str = PulpContainerRemoteContext(pulp_ctx).find(
            name=remote)["pulp_href"]
        body["remote"] = remote_href
    elif repository["remote"] is None:
        raise click.ClickException(
            f"Repository '{name}' does not have a default remote. Please specify with '--remote'."
        )

    repository_ctx.sync(
        href=repository_href,
        body=body,
    )
示例#7
0
def sync(
    pulp_ctx: PulpContext,
    repository_ctx: PulpRepositoryContext,
    name: str,
    remote: Optional[str],
) -> None:
    """
    If remote is not specified sync will try to use the default remote associated with
    the repository
    """
    repository: EntityDefinition = repository_ctx.find(name=name)
    repository_href: str = repository["pulp_href"]
    body: EntityDefinition = dict()

    if remote:
        try:
            remote_href: str = PulpAnsibleCollectionRemoteContext(
                pulp_ctx).find(name=remote)["pulp_href"]
        except click.ClickException:
            remote_href = PulpAnsibleRoleRemoteContext(pulp_ctx).find(
                name=remote)["pulp_href"]
        body["remote"] = remote_href
    elif repository["remote"] is None:
        raise click.ClickException(
            f"Repository '{name}' does not have a default remote. Please specify with '--remote'."
        )

    repository_ctx.sync(
        href=repository_href,
        body=body,
    )
示例#8
0
def update(
    pulp_ctx: PulpContext,
    repository_ctx: PulpRepositoryContext,
    description: Optional[str],
    remote: Optional[str],
) -> None:
    repository = repository_ctx.entity
    repository_href = repository_ctx.pulp_href

    if description is not None:
        if description == "":
            # unset the description
            description = None
        if description != repository["description"]:
            repository["description"] = description

    if remote is not None:
        if remote == "":
            # unset the remote
            repository["remote"] = ""
        elif remote:
            remote_href: str = PulpFileRemoteContext(pulp_ctx, entity={"name": remote}).pulp_href
            repository["remote"] = remote_href

    repository_ctx.update(repository_href, body=repository)
示例#9
0
def version_group(
    ctx: click.Context,
    pulp_ctx: PulpContext,
    repository_ctx: PulpRepositoryContext,
    repository: Optional[str],
) -> None:
    ctx.obj = repository_ctx.get_version_context()
    if repository is not None:
        repository_ctx.entity = {"name": repository}
示例#10
0
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 <...>'
    """
    ctx.obj = PulpRepositoryContext(pulp_ctx)
示例#11
0
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("pulpcore", min_version="3.10.dev")
    ctx.obj = PulpRepositoryContext(pulp_ctx)
示例#12
0
def sync(
    repository_ctx: PulpRepositoryContext,
    remote: Optional[Union[str, PulpEntityContext]],
) -> None:
    repository = repository_ctx.entity
    repository_href = repository_ctx.pulp_href

    body = {}

    if isinstance(remote, PulpEntityContext):
        body["remote"] = remote.pulp_href
    elif repository["remote"] is None:
        name = repository["name"]
        raise click.ClickException(
            f"Repository '{name}' does not have a default remote. Please specify with '--remote'."
        )

    repository_ctx.sync(
        href=repository_href,
        body=body,
    )
示例#13
0
def remove(
    pulp_ctx: PulpContext,
    repository_ctx: PulpRepositoryContext,
    filename: str,
    base_version: Optional[int],
) -> None:
    """Please use 'content remove' instead."""
    repository_href = repository_ctx.pulp_href

    base_version_href: Optional[str]
    if base_version is not None:
        base_version_href = f"{repository_href}versions/{base_version}/"
    else:
        base_version_href = None

    content_href = PulpPythonContentContext(pulp_ctx, entity={"filename": filename}).pulp_href

    repository_ctx.modify(
        href=repository_href,
        remove_content=[content_href],
        base_version=base_version_href,
    )
示例#14
0
def update(
    pulp_ctx: PulpContext,
    repository_ctx: PulpRepositoryContext,
    name: str,
    description: Optional[str],
    remote: Optional[str],
) -> None:
    """
    The description and remote can both be unset using an empty string

    e.g. pulp ansible repository update --name foo --description ""
    """
    repository: EntityDefinition = repository_ctx.find(name=name)

    if description is not None:
        if description == "":
            # unset the description
            description = None
        if description != repository["description"]:
            repository["description"] = description

    if remote is not None:
        if remote == "":
            # unset the remote
            remote_href: str = ""
        else:
            try:
                remote_href = PulpAnsibleCollectionRemoteContext(
                    pulp_ctx).find(name=remote)["pulp_href"]
            except click.ClickException:
                remote_href = PulpAnsibleRoleRemoteContext(pulp_ctx).find(
                    name=remote)["pulp_href"]

        repository["remote"] = remote_href

    repository_ctx.update(repository["pulp_href"], body=repository)
    result = repository_ctx.show(repository["pulp_href"])
    pulp_ctx.output_result(result)
示例#15
0
def sync(
    repository_ctx: PulpRepositoryContext,
    remote: Optional[str],
) -> None:
    """
    If remote is not specified sync will try to use the default remote associated with
    the repository
    """
    repository = repository_ctx.entity
    repository_href = repository["pulp_href"]
    body = {}
    if remote:
        body["remote"] = remote
    elif repository["remote"] is None:
        name = repository["name"]
        raise click.ClickException(
            f"Repository '{name}' does not have a default remote. Please specify with '--remote'."
        )

    repository_ctx.sync(
        href=repository_href,
        body=body,
    )
示例#16
0
def sync(
    pulp_ctx: PulpContext,
    repository_ctx: PulpRepositoryContext,
    remote: Optional[str],
) -> None:
    repository = repository_ctx.entity
    repository_href = repository_ctx.pulp_href

    body = {}

    if remote:
        remote_href: str = PulpFileRemoteContext(pulp_ctx).find(name=remote)["pulp_href"]
        body["remote"] = remote_href
    elif repository["remote"] is None:
        name = repository["name"]
        raise click.ClickException(
            f"Repository '{name}' does not have a default remote. Please specify with '--remote'."
        )

    repository_ctx.sync(
        href=repository_href,
        body=body,
    )
示例#17
0
def create(
    pulp_ctx: PulpContext,
    repository_ctx: PulpRepositoryContext,
    name: str,
    description: Optional[str],
    remote: Optional[str],
) -> None:
    repository = {"name": name, "description": description}
    if remote:
        remote_href: str = PulpFileRemoteContext(pulp_ctx, entity={"name": remote}).pulp_href
        repository["remote"] = remote_href

    result = repository_ctx.create(body=repository)
    pulp_ctx.output_result(result)
示例#18
0
def create(
    pulp_ctx: PulpContext,
    repository_ctx: PulpRepositoryContext,
    name: str,
    description: Optional[str],
    remote: Optional[str],
) -> None:
    repository = {"name": name, "description": description}
    if remote:
        remote_href: str = PulpContainerRemoteContext(pulp_ctx).find(name=remote)["pulp_href"]
        repository["remote"] = remote_href

    result = repository_ctx.create(body=repository)
    pulp_ctx.output_result(result)
示例#19
0
def sync(
    repository_ctx: PulpRepositoryContext,
    remote: EntityFieldDefinition,
) -> None:
    """
    If remote is not specified sync will try to use the default remote associated with
    the repository
    """
    repository = repository_ctx.entity
    repository_href = repository["pulp_href"]
    body = {}
    if isinstance(remote, PulpEntityContext):
        body["remote"] = remote.pulp_href
    elif repository["remote"] is None:
        name = repository["name"]
        raise click.ClickException(
            _("Repository '{name}' does not have a default remote."
              " Please specify with '--remote'.").format(name=name))

    repository_ctx.sync(
        href=repository_href,
        body=body,
    )
示例#20
0
def sync(
    repository_ctx: PulpRepositoryContext,
    remote: Optional[Union[str, PulpEntityContext]],
) -> None:
    if repository_ctx.SYNC_ID is None:
        raise click.ClickException(_("Repository type does not support sync."))

    repository = repository_ctx.entity
    repository_href = repository_ctx.pulp_href

    body = {}

    if isinstance(remote, PulpEntityContext):
        body["remote"] = remote.pulp_href
    elif repository["remote"] is None:
        raise click.ClickException(
            _("Repository '{name}' does not have a default remote. "
              "Please specify with '--remote'.").format(
                  name=repository["name"]))

    repository_ctx.sync(
        href=repository_href,
        body=body,
    )
示例#21
0
def sync(
    repository_ctx: PulpRepositoryContext,
    remote: EntityFieldDefinition,
) -> None:
    if not repository_ctx.capable("sync"):
        raise click.ClickException(_("Repository type does not support sync."))

    repository = repository_ctx.entity
    repository_href = repository_ctx.pulp_href

    body: Dict[str, Any] = {}

    if isinstance(remote, PulpEntityContext):
        body["remote"] = remote.pulp_href
    elif repository["remote"] is None:
        raise click.ClickException(
            _("Repository '{name}' does not have a default remote. "
              "Please specify with '--remote'.").format(
                  name=repository["name"]))

    repository_ctx.sync(
        href=repository_href,
        body=body,
    )
示例#22
0
def create(
    pulp_ctx: PulpContext,
    repository_ctx: PulpRepositoryContext,
    name: str,
    description: Optional[str],
    remote: Optional[str],
) -> None:
    """Creates a repository to store Role and Collection content"""
    repository: EntityDefinition = {"name": name, "description": description}
    if remote is not None:
        try:
            remote_href: str = PulpAnsibleCollectionRemoteContext(
                pulp_ctx).find(name=remote)["pulp_href"]
        except click.ClickException:
            remote_href = PulpAnsibleRoleRemoteContext(pulp_ctx).find(
                name=remote)["pulp_href"]
        repository["remote"] = remote_href

    result = repository_ctx.create(body=repository)
    pulp_ctx.output_result(result)
示例#23
0
 def callback(
     ctx: click.Context,
     repository_ctx: PulpRepositoryContext,
 ) -> None:
     ctx.obj = repository_ctx.get_version_context()