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, )
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 = PulpRpmRemoteContext(pulp_ctx).find( name=remote)["pulp_href"] repository["remote"] = remote_href repository_ctx.update(repository_href, body=repository)
def _remote_callback( ctx: click.Context, param: click.Parameter, value: Optional[str]) -> Optional[Union[str, PulpEntityContext]]: # Pass None and "" verbatim if value: pulp_ctx: PulpContext = ctx.find_object(PulpContext) return PulpRpmRemoteContext(pulp_ctx, entity={"name": value}) return value
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 = PulpRpmRemoteContext(pulp_ctx).find( name=remote)["pulp_href"] repository["remote"] = remote_href result = repository_ctx.create(body=repository) pulp_ctx.output_result(result)
def remote(ctx: click.Context, pulp_ctx: PulpContext, remote_type: str) -> None: if remote_type == "rpm": ctx.obj = PulpRpmRemoteContext(pulp_ctx) else: raise NotImplementedError()
def create(pulp_ctx: PulpContext, remote_ctx: PulpRpmRemoteContext, name: str, url: str) -> None: remote = {"name": name, "url": url} result = remote_ctx.create(body=remote) pulp_ctx.output_result(result)