示例#1
0
def _repository_callback(ctx: click.Context, param: click.Parameter,
                         value: Optional[str]) -> EntityFieldDefinition:
    # Pass None and "" verbatim
    if value:
        pulp_ctx: PulpContext = ctx.find_object(PulpContext)
        return PulpAnsibleRepositoryContext(pulp_ctx, entity={"name": value})
    return value
示例#2
0
def update(
    pulp_ctx: PulpContext,
    distribution_ctx: PulpAnsibleDistributionContext,
    name: str,
    base_path: Optional[str],
    repository: Optional[str],
    version: Optional[int],
) -> None:
    """
    To remove repository or repository_version fields set --repository to ""
    """
    dist_body: EntityDefinition = distribution_ctx.find(name=name)
    href: str = dist_body["pulp_href"]
    body: EntityDefinition = dict()

    if base_path:
        body["base_path"] = base_path
    if repository is not None:
        if repository == "":
            # unset repository or repository version
            if dist_body["repository"]:
                body["repository"] = ""
            elif dist_body["repository_version"]:
                body["repository_version"] = ""
        else:
            repo = PulpAnsibleRepositoryContext(pulp_ctx).find(name=repository)
            if version is not None:
                if dist_body["repository"]:
                    distribution_ctx.update(href,
                                            body={"repository": ""},
                                            non_blocking=True)
                body[
                    "repository_version"] = f'{repo["versions_href"]}{version}/'
            else:
                if dist_body["repository_version"]:
                    distribution_ctx.update(href,
                                            body={"repository_version": ""},
                                            non_blocking=True)
                body["repository"] = repo["pulp_href"]
    elif version is not None:
        # keep current repository, change version
        if dist_body["repository"]:
            distribution_ctx.update(href,
                                    body={"repository": ""},
                                    non_blocking=True)
            body[
                "repository_version"] = f'{dist_body["repository"]}versions/{version}/'
        elif dist_body["repository_version"]:
            repository_href, _, _ = dist_body["repository_version"].partition(
                "versions")
            body[
                "repository_version"] = f"{repository_href}versions/{version}/"
        else:
            raise click.ClickException(
                f"Distribution {name} doesn't have a repository set, "
                f"please specify the repository to use  with --repository")
    distribution_ctx.update(href, body=body)
示例#3
0
def create(
    pulp_ctx: PulpContext,
    distribution_ctx: PulpAnsibleDistributionContext,
    name: str,
    base_path: str,
    repository: Optional[str],
    version: Optional[int],
) -> None:
    """Creates a distribution at base-path for repository's content to be discovered at"""
    body: EntityDefinition = {"name": name, "base_path": base_path}
    repo: EntityDefinition = PulpAnsibleRepositoryContext(pulp_ctx).find(
        name=repository)
    if version is not None and not repository:
        click.ClickException("You must set --repository when using version")
    elif version is not None:
        body["repository_version"] = f'{repo["versions_href"]}{version}/'
    elif repository:
        body["repository"] = repo["pulp_href"]
    result = distribution_ctx.create(body=body)
    pulp_ctx.output_result(result)
示例#4
0
def repository(ctx: click.Context, pulp_ctx: PulpContext,
               repo_type: str) -> None:
    if repo_type == "ansible":
        ctx.obj = PulpAnsibleRepositoryContext(pulp_ctx)
    else:
        raise NotImplementedError()