Service

Service client module.

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

Returns a Service client, If no session is provided, a default session is used.

Parameters:

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

Returns:

The service client object.

Return type:

Service

Service Client

class peak.resources.services.Service(session=None)

Client class for interacting with services resource.

Parameters:

session (Session) –

create_or_update_service(body)

Create a new service or updates an existing service based on service name.

When updating the service, it will trigger a redeployment only under specific conditions. Redeployment is triggered if you make changes to any of the following parameters: imageId, versionId, instanceTypeId, parameters, healthCheckURL, entrypoint or sessionStickiness. However, only modifying the title or description will not trigger a redeployment.

REFERENCE:

🔗 API Documentation

Parameters:

body (Dict[str, Any]) – A dictionary containing the service config. Schema can be found below.

Returns:

Id of the new or updated service.

Return type:

Dict[str, str]

SCHEMA:
{
    "name": "string(required)",
    "title": "string",
    "serviceType": "string. Valid values are 'api', 'web-app' and 'shiny'",
    "imageDetails": {
        "imageId": "number(required)",
        "versionId": "number"
    },
    "resources": {
        "instanceTypeId": "number"
    },
    "parameters": {
        "env": {
            "key: string": "value: string",
        },
        "secrets": []
    },
    "description": "string",
    "sessionStickiness": "boolean. Not required for 'api' service type.",
    "entrypoint": "string",
    "healthCheckURL": "string",
    "minInstances": "number. Default is 1 and maximum is 2",
}
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.

Parameters:

body (Dict[str, Any]) –

Return type:

Dict[str, str]

create_service(body)

Create a new service.

REFERENCE:

🔗 API Documentation

Parameters:

body (Dict[str, Any]) – A dictionary containing the service config. Schema can be found below.

Returns:

Id of the new service

Return type:

Dict[str, str]

SCHEMA:
{
    "name": "string(required)",
    "title": "string",
    "serviceType": "string. Valid values are 'api', 'web-app' and 'shiny'",
    "imageDetails": {
        "imageId": "number(required)",
        "versionId": "number"
    },
    "resources": {
        "instanceTypeId": "number"
    },
    "parameters": {
        "env": {
            "key: string": "value: string"
        },
        "secrets": []
    },
    "description": "string",
    "sessionStickiness": "boolean. Not required for 'api' service type.",
    "entrypoint": "string",
    "healthCheckURL": "string",
    "minInstances": "number. Default is 1 and maximum is 2",
}
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.

Parameters:

body (Dict[str, Any]) –

Return type:

Dict[str, str]

delete_service(service_id)

Delete a service.

REFERENCE:

🔗 API Documentation

Parameters:

service_id (str) – The ID of the service to delete.

Returns:

Dictonary containing ID of the deleted service.

Return type:

Dict[str, str]

Raises:
  • UnauthorizedException – The credentials are invalid.

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

  • NotFoundException – The given service does not exist.

  • ConflictException – If the service is in a conflicting state while deleting.

  • InternalServerErrorException – The server failed to process the request.

describe_service(service_id)

Retrieve details of a specific service.

REFERENCE:

🔗 API Documentation

Parameters:

service_id (str) – The ID of the service to fetch.

Returns:

Dictonary containing details of the service.

Return type:

Dict[str, Any]

Raises:
  • UnauthorizedException – The credentials are invalid.

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

  • NotFoundException – The given service does not exist.

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

  • InternalServerErrorException – The server failed to process the request.

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

Retrieve a list of services.

REFERENCE:

🔗 API Documentation

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

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

  • status (List[str] | None) – A list of service status to filter the list by. Valid values are CREATING, DEPLOYING, AVAILABLE, DELETING, CREATE_FAILED, DELETE_FAILED.

  • name (str | None) – Name of the service to search for.

  • service_type (List[str] | None) – A list of service types to filter the list by. Valid values are api, web-app and shiny.

  • return_iterator (bool) – Whether to return an iterator object or list of services 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.

test_service(service_name, http_method, path=None, payload=None)

Test an API service to verify it’s health and if it is working. Make sure the service is of type “api”.

REFERENCE:

🔗 API Documentation

Parameters:
  • service_name (str) – The name of the API type service to test.

  • http_method (str) – The HTTP method to use for the test. Valid values are ‘get’, ‘post’, ‘put’, ‘patch’ and ‘delete’.

  • path (str, None) – The path to test the service with. Default is ‘/’.

  • payload (Dict[str, Any], None) – The payload to test the service with.

Returns:

Dictonary containing response of the test.

Return type:

Dict[str, Any]

Raises:
  • UnauthorizedException – The credentials are invalid.

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

  • NotFoundException – The given service does not exist.

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

  • InternalServerErrorException – The server failed to process the request.

update_service(service_id, body)

Updates the existing service.

When updating the service, it will trigger a redeployment only under specific conditions. Redeployment is triggered if you make changes to any of the following parameters: imageId, versionId, instanceTypeId, parameters, healthCheckURL, entrypoint or sessionStickiness. However, only modifying the title or description will not trigger a redeployment.

With the help of this operation, we can just update the required fields (except name and serviceType) and keep the rest of the fields as it is.

REFERENCE:

🔗 API Documentation

Parameters:
  • service_id (str) – The ID of the service to update.

  • body (Dict[str, Any]) – A dictionary containing the service config. Schema can be found below.

Returns:

Id of the service.

Return type:

Dict[str, str]

SCHEMA:
{
    "title": "string",
    "imageDetails": {
        "imageId": "number(required)",
        "versionId": "number",
    },
    "resources": {
        "instanceTypeId": "number"
    },
    "parameters": {
        "env": {
            "key: string": "value: string",
        },
        "secrets": []
    },
    "description": "string",
    "sessionStickiness": "boolean. Not required for 'api' service type.",
    "entrypoint": "string",
    "healthCheckURL": "string",
    "minInstances": "number. Default is 1 and maximum is 2",
}
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 service does not exist.

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

  • InternalServerErrorException – The server failed to process the request.

Parameters:
  • service_id (str) –

  • body (Dict[str, Any]) –

Return type:

Dict[str, str]