Source code for contree_client.operations

"""Request builders and response parsers for the Contree API.

Generated by codegen from the OpenAPI spec - do not edit.
"""

from __future__ import annotations

import json
from collections.abc import Sequence
from datetime import datetime
from types import EllipsisType
from typing import IO, Any, Literal

from .models import (
    ClosableStreamRepr,
    DirectoryList,
    ExecSpec,
    File,
    FileResponse,
    FilesListResponse,
    FileSpec,
    GrepResult,
    Image,
    ImageImportRegistry,
    ImageImportRequest,
    ImageListResponse,
    InstanceNetworking,
    InstanceResourcesLimits,
    InstanceResult,
    InstanceSpawnRequest,
    InstanceSpawnResponse,
    ListNetworkPolicyTagsResponse,
    NetworkPolicy,
    NetworkPolicyCIDRRule,
    NetworkPolicyCreateRequest,
    NetworkPolicyListResponse,
    NetworkPolicyTag,
    OperationResponse,
    OperationStatus,
    OperationSummary,
    ProcessResourcesLimits,
    WhoAmIResponse,
)
from .runtime import (
    RequestSpec,
    ResponseData,
    format_time_param,
    json_array,
    json_object,
    quote_path,
)


[docs] def build_list_network_policies( *, search: str | None = None, limit: int | None = None, offset: int | None = None ) -> RequestSpec: """Build the request for `GET /network/policies`.""" query: dict[str, str] = {} if search is not None: query["search"] = search if limit is not None: query["limit"] = str(limit) if offset is not None: query["offset"] = str(offset) request_path = "/network/policies" return RequestSpec(method="GET", path=request_path, idempotent=True, query=query)
[docs] def parse_list_network_policies(response: ResponseData) -> NetworkPolicyListResponse: """Parse the response of `GET /network/policies`.""" if 200 <= response.status < 300: return NetworkPolicyListResponse.from_dict(json_object(response)) raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_create_network_policy(cidrs: list[NetworkPolicyCIDRRule]) -> RequestSpec: """Build the request for `POST /network/policies`.""" payload = NetworkPolicyCreateRequest(cidrs=cidrs).to_dict() request_path = "/network/policies" return RequestSpec( method="POST", path=request_path, idempotent=False, body=json.dumps(payload).encode(), content_type="application/json", )
[docs] def parse_create_network_policy(response: ResponseData) -> NetworkPolicy: """Parse the response of `POST /network/policies`.""" if 200 <= response.status < 300: return NetworkPolicy.from_dict(json_object(response)) raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_get_network_policy(uuid: str) -> RequestSpec: """Build the request for `GET /network/policies/{uuid}`.""" request_path = f"/network/policies/{quote_path(uuid)}" return RequestSpec(method="GET", path=request_path, idempotent=True)
[docs] def parse_get_network_policy(response: ResponseData) -> NetworkPolicy: """Parse the response of `GET /network/policies/{uuid}`.""" if 200 <= response.status < 300: return NetworkPolicy.from_dict(json_object(response)) raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_delete_network_policy(uuid: str) -> RequestSpec: """Build the request for `DELETE /network/policies/{uuid}`.""" request_path = f"/network/policies/{quote_path(uuid)}" return RequestSpec(method="DELETE", path=request_path, idempotent=True)
[docs] def parse_delete_network_policy(response: ResponseData) -> None: """Parse the response of `DELETE /network/policies/{uuid}`.""" if 200 <= response.status < 300: return raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_list_network_policy_tags( *, limit: int | None = None, offset: int | None = None ) -> RequestSpec: """Build the request for `GET /network/tags`.""" query: dict[str, str] = {} if limit is not None: query["limit"] = str(limit) if offset is not None: query["offset"] = str(offset) request_path = "/network/tags" return RequestSpec(method="GET", path=request_path, idempotent=True, query=query)
[docs] def parse_list_network_policy_tags( response: ResponseData, ) -> ListNetworkPolicyTagsResponse: """Parse the response of `GET /network/tags`.""" if 200 <= response.status < 300: return ListNetworkPolicyTagsResponse.from_dict(json_object(response)) raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_get_network_policy_tag(tag: str) -> RequestSpec: """Build the request for `GET /network/tags/{tag}`.""" request_path = f"/network/tags/{quote_path(tag)}" return RequestSpec(method="GET", path=request_path, idempotent=True)
[docs] def parse_get_network_policy_tag(response: ResponseData) -> NetworkPolicyTag: """Parse the response of `GET /network/tags/{tag}`.""" if response.status == 302: return NetworkPolicyTag.from_dict(json_object(response)) raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_set_network_policy_tag(tag: str, uuid: str) -> RequestSpec: """Build the request for `PUT /network/tags/{tag}`.""" payload: dict[str, Any] = {} payload["uuid"] = uuid request_path = f"/network/tags/{quote_path(tag)}" return RequestSpec( method="PUT", path=request_path, idempotent=True, body=json.dumps(payload).encode(), content_type="application/json", )
[docs] def parse_set_network_policy_tag(response: ResponseData) -> NetworkPolicyTag: """Parse the response of `PUT /network/tags/{tag}`.""" if 200 <= response.status < 300: return NetworkPolicyTag.from_dict(json_object(response)) raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_delete_network_policy_tag(tag: str) -> RequestSpec: """Build the request for `DELETE /network/tags/{tag}`.""" request_path = f"/network/tags/{quote_path(tag)}" return RequestSpec(method="DELETE", path=request_path, idempotent=True)
[docs] def parse_delete_network_policy_tag(response: ResponseData) -> None: """Parse the response of `DELETE /network/tags/{tag}`.""" if 200 <= response.status < 300: return raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_list_images( *, limit: int | None = None, offset: int | None = None, tagged: bool = False, tag: str | None = None, uuid: str | None = None, since: str | int | float | datetime | None = None, until: str | int | float | datetime | None = None, ) -> RequestSpec: """Build the request for `GET /images`.""" query: dict[str, str] = {} if limit is not None: query["limit"] = str(limit) if offset is not None: query["offset"] = str(offset) if tagged: query["tagged"] = "1" if tag is not None: query["tag"] = tag if uuid is not None: query["uuid"] = uuid if since is not None: query["since"] = format_time_param(since) if until is not None: query["until"] = format_time_param(until) request_path = "/images" return RequestSpec(method="GET", path=request_path, idempotent=True, query=query)
[docs] def parse_list_images(response: ResponseData) -> ImageListResponse: """Parse the response of `GET /images`.""" if 200 <= response.status < 300: return ImageListResponse.from_dict(json_object(response)) raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_delete_image_tag(image_uuid: str, *, tag: str | None = None) -> RequestSpec: """Build the request for `DELETE /images/{imageUUID}/tag`.""" query: dict[str, str] = {} if tag is not None: query["tag"] = tag request_path = f"/images/{quote_path(image_uuid)}/tag" return RequestSpec(method="DELETE", path=request_path, idempotent=True, query=query)
[docs] def parse_delete_image_tag(response: ResponseData) -> None: """Parse the response of `DELETE /images/{imageUUID}/tag`.""" if 200 <= response.status < 300: return raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_update_image_tag(image_uuid: str, tag: str) -> RequestSpec: """Build the request for `PATCH /images/{imageUUID}/tag`.""" payload: dict[str, Any] = {} payload["tag"] = tag request_path = f"/images/{quote_path(image_uuid)}/tag" return RequestSpec( method="PATCH", path=request_path, idempotent=False, body=json.dumps(payload).encode(), content_type="application/json", )
[docs] def parse_update_image_tag(response: ResponseData) -> Image: """Parse the response of `PATCH /images/{imageUUID}/tag`.""" if 200 <= response.status < 300: return Image.from_dict(json_object(response)) raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_import_image( registry: ImageImportRegistry, *, tag: str | None | EllipsisType = ..., timeout: int | EllipsisType = ..., ) -> RequestSpec: """Build the request for `POST /images/import`.""" payload = ImageImportRequest(registry=registry, tag=tag, timeout=timeout).to_dict() request_path = "/images/import" return RequestSpec( method="POST", path=request_path, idempotent=False, body=json.dumps(payload).encode(), content_type="application/json", )
[docs] def parse_import_image(response: ResponseData) -> str: """Parse the response of `POST /images/import`.""" if 200 <= response.status < 300: return str(json_object(response)["uuid"]) raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_list_files( *, limit: int | None = None, offset: int | None = None, since: str | int | float | datetime | None = None, until: str | int | float | datetime | None = None, ) -> RequestSpec: """Build the request for `GET /files`.""" query: dict[str, str] = {} if limit is not None: query["limit"] = str(limit) if offset is not None: query["offset"] = str(offset) if since is not None: query["since"] = format_time_param(since) if until is not None: query["until"] = format_time_param(until) request_path = "/files" return RequestSpec(method="GET", path=request_path, idempotent=True, query=query)
[docs] def parse_list_files(response: ResponseData) -> FilesListResponse: """Parse the response of `GET /files`.""" if 200 <= response.status < 300: return FilesListResponse.from_dict(json_object(response)) raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_upload_file(content: bytes | IO[bytes]) -> RequestSpec: """Build the request for `POST /files`.""" request_path = "/files" return RequestSpec( method="POST", path=request_path, idempotent=False, body=content, content_type="application/octet-stream", )
[docs] def parse_upload_file(response: ResponseData) -> FileResponse: """Parse the response of `POST /files`.""" if 200 <= response.status < 300: return FileResponse.from_dict(json_object(response)) raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_get_file(sha256: str) -> RequestSpec: """Build the request for `GET /files/{sha256}`.""" request_path = f"/files/{quote_path(sha256)}" return RequestSpec(method="GET", path=request_path, idempotent=True)
[docs] def parse_get_file(response: ResponseData) -> File: """Parse the response of `GET /files/{sha256}`.""" if 200 <= response.status < 300: return File.from_dict(json_object(response)) raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_check_file_exists(sha256: str) -> RequestSpec: """Build the request for `HEAD /files/{sha256}`.""" request_path = f"/files/{quote_path(sha256)}" return RequestSpec(method="HEAD", path=request_path, idempotent=True)
[docs] def parse_check_file_exists(response: ResponseData) -> bool: """Parse the response of `HEAD /files/{sha256}`.""" if 200 <= response.status < 300: return True if response.status == 404: return False raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_spawn_instance( command: str, image: str, *, disposable: bool | EllipsisType = ..., hostname: str | EllipsisType = ..., args: list[str] | EllipsisType = ..., shell: bool | EllipsisType = ..., env: dict[str, str] | None | EllipsisType = ..., preserve_env: bool | EllipsisType = ..., preserve_cwd: bool | EllipsisType = ..., cwd: str | EllipsisType = ..., uid: int | EllipsisType = ..., gid: int | EllipsisType = ..., resources_limits: InstanceResourcesLimits | EllipsisType = ..., networking: InstanceNetworking | EllipsisType = ..., stdin: ClosableStreamRepr | EllipsisType = ..., timeout: int | EllipsisType = ..., truncate_output_at: int | EllipsisType = ..., files: dict[str, FileSpec] | EllipsisType = ..., ) -> RequestSpec: """Build the request for `POST /instances`.""" payload = InstanceSpawnRequest( command=command, image=image, disposable=disposable, hostname=hostname, args=args, shell=shell, env=env, preserve_env=preserve_env, preserve_cwd=preserve_cwd, cwd=cwd, uid=uid, gid=gid, resources_limits=resources_limits, networking=networking, stdin=stdin, timeout=timeout, truncate_output_at=truncate_output_at, files=files, ).to_dict() request_path = "/instances" return RequestSpec( method="POST", path=request_path, idempotent=False, body=json.dumps(payload).encode(), content_type="application/json", )
[docs] def parse_spawn_instance(response: ResponseData) -> InstanceSpawnResponse: """Parse the response of `POST /instances`.""" if 200 <= response.status < 300: return InstanceSpawnResponse.from_dict(json_object(response)) raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_list_operations( *, limit: int | None = None, offset: int | None = None, status: OperationStatus | str | None = None, kind: Literal["image_import", "instance"] | None = None, since: str | int | float | datetime | None = None, until: str | int | float | datetime | None = None, ) -> RequestSpec: """Build the request for `GET /operations`.""" query: dict[str, str] = {} if limit is not None: query["limit"] = str(limit) if offset is not None: query["offset"] = str(offset) if status is not None: query["status"] = str(status) if kind is not None: query["kind"] = kind if since is not None: query["since"] = format_time_param(since) if until is not None: query["until"] = format_time_param(until) request_path = "/operations" return RequestSpec(method="GET", path=request_path, idempotent=True, query=query)
[docs] def parse_list_operations(response: ResponseData) -> list[OperationSummary]: """Parse the response of `GET /operations`.""" if 200 <= response.status < 300: return [OperationSummary.from_dict(item) for item in json_array(response)] raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_get_operation_status( operation_id: str, *, inflight: bool = False ) -> RequestSpec: """Build the request for `GET /operations/{operationId}`.""" query: dict[str, str] = {} if inflight: query["inflight"] = "1" request_path = f"/operations/{quote_path(operation_id)}" return RequestSpec(method="GET", path=request_path, idempotent=True, query=query)
[docs] def parse_get_operation_status(response: ResponseData) -> OperationResponse: """Parse the response of `GET /operations/{operationId}`.""" if 200 <= response.status < 300: return OperationResponse.from_dict(json_object(response)) raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_cancel_operation(operation_id: str) -> RequestSpec: """Build the request for `DELETE /operations/{operationId}`.""" request_path = f"/operations/{quote_path(operation_id)}" return RequestSpec(method="DELETE", path=request_path, idempotent=True)
[docs] def parse_cancel_operation(response: ResponseData) -> None: """Parse the response of `DELETE /operations/{operationId}`.""" if 200 <= response.status < 300: return raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_iter_operation_events( operation_id: str, *, follow: bool = False, spid: int | None = None, since: int | None = None, last_event_id: int | None = None, ) -> RequestSpec: """Build the request for `GET /operations/{operationId}/events`.""" query: dict[str, str] = {} if follow: query["follow"] = "1" if spid is not None: query["spid"] = str(spid) if since is not None: query["since"] = str(since) headers: dict[str, str] = {} if last_event_id is not None: headers["Last-Event-Id"] = str(last_event_id) request_path = f"/operations/{quote_path(operation_id)}/events" return RequestSpec( method="GET", path=request_path, idempotent=True, query=query, headers=headers, accept="text/event-stream", )
[docs] def build_operation_subprocess_create( operation_id: str, command: str, *, resources_limits: ProcessResourcesLimits | EllipsisType = ..., args: list[str] | EllipsisType = ..., shell: bool | EllipsisType = ..., env: dict[str, str] | None | EllipsisType = ..., cwd: str | EllipsisType = ..., uid: int | EllipsisType = ..., gid: int | EllipsisType = ..., stdin: ClosableStreamRepr | EllipsisType = ..., truncate_output_at: int | EllipsisType = ..., ) -> RequestSpec: """Build the request for `POST /operations/{operationId}/subprocesses`.""" payload = ExecSpec( command=command, resources_limits=resources_limits, args=args, shell=shell, env=env, cwd=cwd, uid=uid, gid=gid, stdin=stdin, truncate_output_at=truncate_output_at, ).to_dict() request_path = f"/operations/{quote_path(operation_id)}/subprocesses" return RequestSpec( method="POST", path=request_path, idempotent=False, body=json.dumps(payload).encode(), content_type="application/json", )
[docs] def parse_operation_subprocess_create(response: ResponseData) -> int: """Parse the response of `POST /operations/{operationId}/subprocesses`.""" if 200 <= response.status < 300: return int(json_object(response)["spid"]) raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_operation_subprocess(operation_id: str, spid: int) -> RequestSpec: """Build the request for `GET /operations/{operationId}/subprocesses/{spid}`. """ request_path = ( f"/operations/{quote_path(operation_id)}/subprocesses/{quote_path(spid)}" ) return RequestSpec(method="GET", path=request_path, idempotent=True)
[docs] def parse_operation_subprocess(response: ResponseData) -> InstanceResult: """Parse the response of `GET /operations/{operationId}/subprocesses/{spid}`. """ if 200 <= response.status < 300: return InstanceResult.from_dict(json_object(response)) raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_operation_subprocess_kill( operation_id: str, spid: int, *, signal: str | None = None ) -> RequestSpec: """Build the request for `DELETE /operations/{operationId}/subprocesses/{spid}`. """ query: dict[str, str] = {} if signal is not None: query["signal"] = signal request_path = ( f"/operations/{quote_path(operation_id)}/subprocesses/{quote_path(spid)}" ) return RequestSpec(method="DELETE", path=request_path, idempotent=True, query=query)
[docs] def parse_operation_subprocess_kill(response: ResponseData) -> None: """Parse the response of `DELETE /operations/{operationId}/subprocesses/{spid}`. """ if 200 <= response.status < 300: return raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_operation_subprocess_stdin( operation_id: str, spid: int, value: str, *, encoding: Literal["ascii", "base64"] | EllipsisType = ..., close: bool | EllipsisType = ..., ) -> RequestSpec: """Build the request for `POST /operations/{operationId}/subprocesses/{spid}/stdin`. """ payload = ClosableStreamRepr(value=value, encoding=encoding, close=close).to_dict() request_path = ( f"/operations/{quote_path(operation_id)}/subprocesses/{quote_path(spid)}/stdin" ) return RequestSpec( method="POST", path=request_path, idempotent=False, body=json.dumps(payload).encode(), content_type="application/json", )
[docs] def parse_operation_subprocess_stdin(response: ResponseData) -> None: """Parse the response of `POST /operations/{operationId}/subprocesses/{spid}/stdin`. """ if 200 <= response.status < 300: return raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_apply_instance_file( operation_uuid: str, file_uuid: str, path: str, *, unpack: bool | EllipsisType = ..., replace: bool | EllipsisType = ..., merge: bool | EllipsisType = ..., ) -> RequestSpec: """Build the request for `POST /operations/{operation_uuid}/files`.""" payload: dict[str, Any] = {} payload["file_uuid"] = file_uuid payload["path"] = path if unpack is not ...: payload["unpack"] = unpack if replace is not ...: payload["replace"] = replace if merge is not ...: payload["merge"] = merge request_path = f"/operations/{quote_path(operation_uuid)}/files" return RequestSpec( method="POST", path=request_path, idempotent=False, body=json.dumps(payload).encode(), content_type="application/json", )
[docs] def parse_apply_instance_file(response: ResponseData) -> None: """Parse the response of `POST /operations/{operation_uuid}/files`.""" if 200 <= response.status < 300: return raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_inspect_instance_download(operation_uuid: str, path: str) -> RequestSpec: """Build the request for `GET /operations/{operation_uuid}/inspect/download`. """ query: dict[str, str] = {} query["path"] = path request_path = f"/operations/{quote_path(operation_uuid)}/inspect/download" return RequestSpec(method="GET", path=request_path, idempotent=True, query=query)
[docs] def parse_inspect_instance_download(response: ResponseData) -> bytes: """Parse the response of `GET /operations/{operation_uuid}/inspect/download`. """ if 200 <= response.status < 300: return response.body raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_check_instance_file(operation_uuid: str, path: str) -> RequestSpec: """Build the request for `HEAD /operations/{operation_uuid}/inspect/download`. """ query: dict[str, str] = {} query["path"] = path request_path = f"/operations/{quote_path(operation_uuid)}/inspect/download" return RequestSpec(method="HEAD", path=request_path, idempotent=True, query=query)
[docs] def parse_check_instance_file(response: ResponseData) -> bool: """Parse the response of `HEAD /operations/{operation_uuid}/inspect/download`. """ if 200 <= response.status < 300: return True if response.status == 404: return False raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_inspect_instance_list(operation_uuid: str, path: str) -> RequestSpec: """Build the request for `GET /operations/{operation_uuid}/inspect/list`.""" query: dict[str, str] = {} query["path"] = path request_path = f"/operations/{quote_path(operation_uuid)}/inspect/list" return RequestSpec(method="GET", path=request_path, idempotent=True, query=query)
[docs] def parse_inspect_instance_list(response: ResponseData) -> DirectoryList: """Parse the response of `GET /operations/{operation_uuid}/inspect/list`.""" if 200 <= response.status < 300: return DirectoryList.from_dict(json_object(response)) raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_inspect_instance_archive(operation_uuid: str, path: str) -> RequestSpec: """Build the request for `GET /operations/{operation_uuid}/inspect/archive`. """ query: dict[str, str] = {} query["path"] = path request_path = f"/operations/{quote_path(operation_uuid)}/inspect/archive" return RequestSpec(method="GET", path=request_path, idempotent=True, query=query)
[docs] def build_check_instance_archive(operation_uuid: str, path: str) -> RequestSpec: """Build the request for `HEAD /operations/{operation_uuid}/inspect/archive`. """ query: dict[str, str] = {} query["path"] = path request_path = f"/operations/{quote_path(operation_uuid)}/inspect/archive" return RequestSpec(method="HEAD", path=request_path, idempotent=True, query=query)
[docs] def parse_check_instance_archive(response: ResponseData) -> bool: """Parse the response of `HEAD /operations/{operation_uuid}/inspect/archive`. """ if 200 <= response.status < 300: return True if response.status == 404: return False raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_inspect_find_image_by_tag(tag: str) -> RequestSpec: """Build the request for `GET /inspect/`.""" query: dict[str, str] = {} query["tag"] = tag request_path = "/inspect/" return RequestSpec(method="GET", path=request_path, idempotent=True, query=query)
[docs] def parse_inspect_find_image_by_tag(response: ResponseData) -> str: """Parse the response of `GET /inspect/`.""" if response.status == 302: location = response.headers["location"] return location.rstrip("/").rsplit("/", 1)[-1] raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_inspect_image(image_uuid: str) -> RequestSpec: """Build the request for `GET /inspect/{image_uuid}/`.""" request_path = f"/inspect/{quote_path(image_uuid)}/" return RequestSpec(method="GET", path=request_path, idempotent=True)
[docs] def parse_inspect_image(response: ResponseData) -> Image: """Parse the response of `GET /inspect/{image_uuid}/`.""" if 200 <= response.status < 300: return Image.from_dict(json_object(response)) raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_inspect_image_download(image_uuid: str, path: str) -> RequestSpec: """Build the request for `GET /inspect/{image_uuid}/download`.""" query: dict[str, str] = {} query["path"] = path request_path = f"/inspect/{quote_path(image_uuid)}/download" return RequestSpec(method="GET", path=request_path, idempotent=True, query=query)
[docs] def parse_inspect_image_download(response: ResponseData) -> bytes: """Parse the response of `GET /inspect/{image_uuid}/download`.""" if 200 <= response.status < 300: return response.body raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_check_image_file(image_uuid: str, path: str) -> RequestSpec: """Build the request for `HEAD /inspect/{image_uuid}/download`.""" query: dict[str, str] = {} query["path"] = path request_path = f"/inspect/{quote_path(image_uuid)}/download" return RequestSpec(method="HEAD", path=request_path, idempotent=True, query=query)
[docs] def parse_check_image_file(response: ResponseData) -> bool: """Parse the response of `HEAD /inspect/{image_uuid}/download`.""" if 200 <= response.status < 300: return True if response.status == 404: return False raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_inspect_image_archive(image_uuid: str, path: str) -> RequestSpec: """Build the request for `GET /inspect/{image_uuid}/archive`.""" query: dict[str, str] = {} query["path"] = path request_path = f"/inspect/{quote_path(image_uuid)}/archive" return RequestSpec(method="GET", path=request_path, idempotent=True, query=query)
[docs] def build_check_image_archive(image_uuid: str, path: str) -> RequestSpec: """Build the request for `HEAD /inspect/{image_uuid}/archive`.""" query: dict[str, str] = {} query["path"] = path request_path = f"/inspect/{quote_path(image_uuid)}/archive" return RequestSpec(method="HEAD", path=request_path, idempotent=True, query=query)
[docs] def parse_check_image_archive(response: ResponseData) -> bool: """Parse the response of `HEAD /inspect/{image_uuid}/archive`.""" if 200 <= response.status < 300: return True if response.status == 404: return False raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_inspect_image_list(image_uuid: str, path: str) -> RequestSpec: """Build the request for `GET /inspect/{image_uuid}/list`.""" query: dict[str, str] = {} query["path"] = path request_path = f"/inspect/{quote_path(image_uuid)}/list" return RequestSpec(method="GET", path=request_path, idempotent=True, query=query)
[docs] def parse_inspect_image_list(response: ResponseData) -> DirectoryList: """Parse the response of `GET /inspect/{image_uuid}/list`.""" if 200 <= response.status < 300: return DirectoryList.from_dict(json_object(response)) raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_inspect_instance_grep( operation_uuid: str, pattern: str | Sequence[str], *, path: str | Sequence[str] | None = None, glob: str | Sequence[str] | None = None, max_count: int | None = None, max_total: int | None = None, case: Literal["sensitive", "insensitive", "smart"] | None = None, before: int | None = None, after: int | None = None, ) -> RequestSpec: """Build the request for `GET /operations/{operation_uuid}/inspect/grep`.""" query: dict[str, str | Sequence[str]] = {} query["pattern"] = pattern if path is not None: query["path"] = path if glob is not None: query["glob"] = glob if max_count is not None: query["max_count"] = str(max_count) if max_total is not None: query["max_total"] = str(max_total) if case is not None: query["case"] = case if before is not None: query["before"] = str(before) if after is not None: query["after"] = str(after) request_path = f"/operations/{quote_path(operation_uuid)}/inspect/grep" return RequestSpec(method="GET", path=request_path, idempotent=True, query=query)
[docs] def parse_inspect_instance_grep(response: ResponseData) -> GrepResult: """Parse the response of `GET /operations/{operation_uuid}/inspect/grep`.""" if 200 <= response.status < 300: return GrepResult.from_dict(json_object(response)) raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_inspect_image_grep( image_uuid: str, pattern: str | Sequence[str], *, path: str | Sequence[str] | None = None, glob: str | Sequence[str] | None = None, max_count: int | None = None, max_total: int | None = None, case: Literal["sensitive", "insensitive", "smart"] | None = None, before: int | None = None, after: int | None = None, ) -> RequestSpec: """Build the request for `GET /inspect/{image_uuid}/grep`.""" query: dict[str, str | Sequence[str]] = {} query["pattern"] = pattern if path is not None: query["path"] = path if glob is not None: query["glob"] = glob if max_count is not None: query["max_count"] = str(max_count) if max_total is not None: query["max_total"] = str(max_total) if case is not None: query["case"] = case if before is not None: query["before"] = str(before) if after is not None: query["after"] = str(after) request_path = f"/inspect/{quote_path(image_uuid)}/grep" return RequestSpec(method="GET", path=request_path, idempotent=True, query=query)
[docs] def parse_inspect_image_grep(response: ResponseData) -> GrepResult: """Parse the response of `GET /inspect/{image_uuid}/grep`.""" if 200 <= response.status < 300: return GrepResult.from_dict(json_object(response)) raise ValueError(f"unexpected HTTP status {response.status}")
[docs] def build_whoami() -> RequestSpec: """Build the request for `GET /whoami`.""" request_path = "/whoami" return RequestSpec(method="GET", path=request_path, idempotent=True)
[docs] def parse_whoami(response: ResponseData) -> WhoAmIResponse: """Parse the response of `GET /whoami`.""" if 200 <= response.status < 300: return WhoAmIResponse.from_dict(json_object(response)) raise ValueError(f"unexpected HTTP status {response.status}")