Image

image client module.

peak.resources.images.get_client(session=None)

Returns an Image Management client, If no session is provided, a default session is used.

Parameters:

session (Optional[Session]) – A Session Object. Default is None.

Returns:

the image client object

Return type:

Image

Image Client

class peak.resources.images.Image(session=None)

Image Client Class.

Parameters:

session (Session) –

create_image(body, artifact=None)

Create a new image.

REFERENCE:

🔗 API Documentation

Parameters:
  • body (Dict[str, Any]) – Represents the body to be used to create image. Schema can be found below.

  • artifact (Optional[ArtifactInfo]) – Mapping of artifact attributes that specifies how the artifact will be generated, it accepts two keys path, which is required and ignore_files which is optional, and defaults to .dockerignore, it is strongly advised that users use ignore_files when generating artifacts to avoid copying any extra files in artifact.

Returns:

buildId, imageId, and versionId of the newly created image and the corresponding version.

Return type:

Dict[str, Any]

SCHEMA:
{
    "name": "string(required)",
    "type": "string(required)",
    "description": "string",
    "version": "string",
    "buildDetails":
        {
            "source": "string",
            "buildArguments": [
                {
                    "name": "string",
                    "value": "string"
                }
            ],
            "useCache": "boolean",
            "dockerfile": "string",
            "branch": "string",
            "repository": "string",
            "token": "string",
            "dockerfilePath": "string",
            "context": "string"
        },
}
Raises:
  • BadRequestException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • PayloadTooLargeException – The artifact exceeds maximum size.

  • InternalServerErrorException – The server failed to process the request.

Parameters:
  • body (Dict[str, Any]) –

  • artifact (ArtifactInfo | None) –

Return type:

Dict[str, Any]

create_or_update_image_version(body, artifact=None)

Create a new image or version if none exists, update version if exists based on image name and version combination.

REFERENCE:

🔗 API Documentation

Parameters:
  • body (Dict[str, Any]) – Represents the body to be used to create image. Schema can be found below.

  • artifact (Optional[ArtifactInfo]) – Mapping of artifact attributes that specifies how the artifact will be generated, it accepts two keys path, which is required and ignore_files which is optional, and defaults to .dockerignore, it is strongly advised that users use ignore_files when generating artifacts to avoid copying any extra files in artifact.

Returns:

buildId, imageId, and versionId of the newly created image and the corresponding version when no image/version exists.

In case when image exists but version doesn’t it will return buildId and versionId of the newly created version along with imageId of the existing image. In case when image and version exists, it will return buildId for the updated version along with imageId and versionId of the existing image / version.

Return type:

Dict[str, Any]

SCHEMA:
{
    "name": "string(required)",
    "type": "string(required)",
    "description": "string",
    "version": "string",
    "buildDetails":
        {
            "source": "string",
            "buildArguments": [
                {
                    "name": "string",
                    "value": "string"
                }
            ],
            "useCache": "boolean",
            "dockerfile": "string",
            "branch": "string",
            "repository": "string",
            "token": "string",
            "dockerfilePath": "string",
            "context": "string"
        },
}
Raises:
  • BadRequestException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • PayloadTooLargeException – The artifact exceeds maximum size.

  • InternalServerErrorException – The server failed to process the request.

Parameters:
  • body (Dict[str, Any]) –

  • artifact (ArtifactInfo | None) –

Return type:

Dict[str, Any]

create_version(image_id, body, artifact=None)

Create a new version.

REFERENCE:

🔗 API Documentation

Parameters:
  • image_id (int) – The ID of the image for which we have to create a new version.

  • body (Dict[str, Any]) – Represents the body to be used to create image version. Schema can be found below.

  • artifact (Optional[ArtifactInfo]) – Mapping of artifact attributes that specifies how the artifact will be generated, it accepts two keys path, which is required and ignore_files which is optional, and defaults to .dockerignore, it is strongly advised that users use ignore_files when generating artifacts to avoid copying any extra files in artifact.

Returns:

imageId, buildId, versionId and autodeploymentId of the newly created version.

Return type:

Dict[str, Any]

SCHEMA:
{
    "description": "string",
    "version": "string",
    "buildDetails":
        {
            "source": "string",
            "buildArguments": [
                {
                    "name": "string",
                    "value": "string"
                }
            ],
            "useCache": "boolean",
            "dockerfile": "string",
            "branch": "string",
            "repository": "string",
            "token": "string",
            "dockerfilePath": "string",
            "context": "string"
        },
}
Raises:
  • BadRequestException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • PayloadTooLargeException – The artifact exceeds maximum size.

  • InternalServerErrorException – The server failed to process the request.

Parameters:
  • image_id (int) –

  • body (Dict[str, Any]) –

  • artifact (ArtifactInfo | None) –

Return type:

Dict[str, Any]

delete_image(image_id)

Delete an Image. All the versions in the image will first go into deleting state before actually being deleted.

REFERENCE:

🔗 API Documentation

Parameters:

image_id (int) – The ID of the image to delete.

Returns:

Empty dictionary object.

Return type:

dict

Raises:
  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • NotFoundException – The given image does not exist.

  • UnprocessableEntityException – The server was unable to process the request.

  • InternalServerErrorException – The server failed to process the request.

delete_version(image_id, version_id)

Delete an Image Version.

REFERENCE:

🔗 API Documentation

Parameters:
  • image_id (int) – The ID of the image to delete.

  • version_id (int) – The ID of the version to delete.

Returns:

Empty dictionary object.

Return type:

dict

Raises:
  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform this operation.

  • NotFoundException – The given image does not exist.

  • UnprocessableEntityException – The server was unable to process the request.

  • InternalServerErrorException – The server failed to process the request.

delete_versions(image_id, version_ids)

Delete given versions for an image. All the versions will first go into deleting state before they and all their associated resources are deleted.

REFERENCE:

🔗 API Documentation

Parameters:
  • image_id (int) – The ID of the image to delete.

  • version_ids (List[int]) – The IDs of the versions to delete.

Returns:

Empty dictionary object.

Return type:

dict

Raises:
  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform this operation.

  • NotFoundException – The given image does not exist.

  • UnprocessableEntityException – The server was unable to process the request.

  • InternalServerErrorException – The server failed to process the request.

describe_image(image_id)

Retrieve details of a specific image and its latest version.

REFERENCE:

🔗 API Documentation

Parameters:

image_id (int) – The ID of the image to retrieve.

Returns:

A dictionary containing the details of the image and its latest version.

Return type:

Dict[str, Any]

Raises:
  • BadRequestException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • NotFoundException – The given image does not exist.

  • UnprocessableEntityException – The server was unable to process the request.

  • InternalServerErrorException – The server failed to process the request.

describe_version(image_id, version_id)

Retrieve details of a specific version.

REFERENCE:

🔗 API Documentation

Parameters:
  • image_id (int) – The ID of the image to retrieve.

  • version_id (int) – The ID of the image to retrieve.

Returns:

a dictionary containing the details of the version.

Return type:

Dict[str, Any]

Raises:
  • BadRequestException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • NotFoundException – The given image does not exist.

  • UnprocessableEntityException – The server was unable to process the request.

  • InternalServerErrorException – The server failed to process the request.

get_build_logs(image_id, build_id, next_token=None, save=False, file_name=None)

Retrieve or save the logs of an image build.

REFERENCE:

🔗 API Documentation

Parameters:
  • image_id (int) – The ID of the image.

  • build_id (int) – The ID of the image build.

  • next_token (str | None) – The token to retrieve the next set of logs.

  • save (bool) – Whether to save the logs to a file. Defaults to False.

  • file_name (str | None) – File name or path where the contents should be saved. Default file name is image_build_logs_{image_id}_{build_id}.log.

Returns:

A dictionary containing the logs of the build. If save is set to True, the signed URL to download the logs is returned and the logs are saved to a file.

Return type:

Dict[str, Any]

Raises:
  • BadRequestException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform this operation.

  • NotFoundException – The given image or build does not exist.

  • InternalServerErrorException – The server failed to process the request.

list_image_builds(image_id: int, date_from: str | None = None, date_to: str | None = None, page_size: int | None = None, page_number: int | None = None, count: int | None = None, version_ids: List[str] | None = None, build_status: List[str] | None = None, *, return_iterator: Literal[False]) Dict[str, Any]
list_image_builds(image_id: int, date_from: str | None = None, date_to: str | None = None, page_size: int | None = None, page_number: int | None = None, count: int | None = None, version_ids: List[str] | None = None, build_status: List[str] | None = None, *, return_iterator: Literal[True] = True) Iterator[Dict[str, Any]]

Lists image builds.

REFERENCE:

🔗 API Documentation

Parameters:
  • image_id (int) – ID of the image to fetch image build history.

  • date_from (str | None) – The date after which the image builds should be included (in ISO format). It is 90 days from current date by default.

  • date_to (str | None) – The date till which the image builds should be included (in ISO format). It is current date by default.

  • page_size (int | None) – Number of builds per page.

  • page_number (int | None) – Page number to retrieve. Only used when return_iterator is False.

  • count (int | None) – Number of builds required (Ordered by latest to earliest). For example, if 5 is provided, it will return last 5 builds. It is -1 by default which means it will return all the available builds within the given dates.

  • version_ids (List[str] | None) – List of version ids to filter builds.

  • build_status (List[str] | None) – List of build statuses to filter builds. Valid values are building, failed, success, stopped, stopping.

  • return_iterator (bool) – Whether to return an iterator object or a dictionary of list of image builds. Defaults to True.

Returns:

an iterator object which returns an element per iteration, until there are no more elements to return. If return_iterator is set to False, a dictionary containing the list and pagination details is returned instead.

Set return_iterator to True if you want automatic client-side pagination, or False if you want server-side pagination.

Return type:

Iterator[Dict[str, Any]] | Dict[str, Any]

Raises:
  • BadRequestException – BadRequestException: The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • NotFoundException – The given image does not exist.

  • InternalServerErrorException – The server failed to process the request.

list_image_versions(image_id: int, page_size: int | None = None, page_number: int | None = None, version: str | None = None, status: List[str] | None = None, last_build_status: List[str] | None = None, tags: List[str] | None = None, *, return_iterator: Literal[False]) Dict[str, Any]
list_image_versions(image_id: int, page_size: int | None = None, page_number: int | None = None, version: str | None = None, status: List[str] | None = None, last_build_status: List[str] | None = None, tags: List[str] | None = None, *, return_iterator: Literal[True] = True) Iterator[Dict[str, Any]]

Retrieve a list of image versions.

REFERENCE:

🔗 API Documentation

Parameters:
  • image_id (int) – The Image id for which we want to get versions.

  • page_size (int | None) – The number of images per page.

  • page_number (int | None) – The page number to retrieve. Only used when return_iterator is False.

  • version – (str | None): Search by version.

  • status (List[str] | None) – Filter versions on the basis of their status. Valid values are not-ready, ready, in-use, deleting, delete-failed.

  • last_build_status (List[str] | None) – Filter out on the basis of last build status of version. Valid values are building, failed, success, stopped, stopping.

  • tags (List[str] | None) – Filter out on the basis of the tags attached to the version.

  • return_iterator (bool) – Whether to return an iterator object or list of images for a specified page number, defaults to True.

Returns:

An iterator object which returns an element per iteration, until there are no more elements to return. If return_iterator is set to False, a dictionary containing the list and pagination details is returned instead.

Set return_iterator to True if you want automatic client-side pagination, or False if you want server-side pagination.

Return type:

Iterator[Dict[str, Any] | Dict[str, Any]

Raises:
  • BadRequestException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform this operation.

  • InternalServerErrorException – The server failed to process the request.

list_images(page_size: int | None = None, page_number: int | None = None, name: str | None = None, status: List[str] | None = None, scope: List[str] | None = None, last_build_status: List[str] | None = None, tags: List[str] | None = None, *, return_iterator: Literal[False]) Dict[str, Any]
list_images(page_size: int | None = None, page_number: int | None = None, name: str | None = None, status: List[str] | None = None, scope: List[str] | None = None, last_build_status: List[str] | None = None, tags: List[str] | None = None, *, return_iterator: Literal[True] = True) Iterator[Dict[str, Any]]

Retrieve the list of images.

REFERENCE:

🔗 API Documentation

Parameters:
  • page_size (int | None) – The number of images per page.

  • page_number (int | None) – The page number to retrieve. Only used when return_iterator is False.

  • name – (str | None): Image Name or version to search for.

  • status (List[str] | None) – Filter images on the basis of the status of the latest version. Valid values are not-ready, ready, in-use, deleting, delete-failed.

  • scope (List[str] | None) – Filter out on the basis of the type of the image - global or custom.

  • last_build_status (List[str] | None) – Filter out on the basis of last build status of the latest version. Valid values are building, failed, success, stopped, stopping.

  • tags (List[str] | None) – Filter out on the basis of the tags attached to the latest version.

  • return_iterator (bool) – Whether to return an iterator object or list of images for a specified page number, defaults to True.

Returns:

an iterator object which returns an element per iteration, until there are no more elements to return. If return_iterator is set to False, a dictionary containing the list and pagination details is returned instead.

Set return_iterator to True if you want automatic client-side pagination, or False if you want server-side pagination.

Return type:

Iterator[Dict[str, Any]] | Dict[str, Any]

Raises:
  • BadRequestException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • InternalServerErrorException – The server failed to process the request.

update_version(image_id, version_id, body, artifact=None)

Update an existing image version.

REFERENCE:

🔗 API Documentation

Parameters:
  • image_id (int) – The ID of the image to update.

  • version_id (int) – The ID of the version to update.

  • body (Dict[str, Any]) – Represents the body to be used to update image version. Schema can be found below.

  • artifact (Optional[ArtifactInfo]) – Mapping of artifact attributes that specifies how the artifact will be generated, it accepts two keys path, which is required and ignore_files which is optional, and defaults to .dockerignore, it is strongly advised that users use ignore_files when generating artifacts to avoid copying any extra files in artifact.

Returns:

imageId, buildId, versionId and autodeploymentId of the updated version.

Return type:

Dict[str, Any]

SCHEMA:
{
    "description": "string",
    "buildDetails":
        {
            "source": "string",
            "buildArguments": [
                {
                    "name": "string",
                    "value": "string"
                }
            ],
            "useCache": "boolean",
            "dockerfile": "string",
            "branch": "string",
            "repository": "string",
            "token": "string",
            "dockerfilePath": "string",
            "context": "string"
        },
}
Raises:
  • BadRequestException – The given request parameters are invalid.

  • UnauthorizedException – The credentials are invalid.

  • ForbiddenException – The user does not have permission to perform the operation.

  • NotFoundException – The given image or version does not exist.

  • PayloadTooLargeException – The artifact exceeds maximum size.

  • UnprocessableEntityException – The server was unable to process the request.

  • InternalServerErrorException – The server failed to process the request.

Parameters:
  • image_id (int) –

  • version_id (int) –

  • body (Dict[str, Any]) –

  • artifact (ArtifactInfo | None) –

Return type:

dict[str, str]