Przejdź do głównej zawartości

API reference

To work with the module: import cgc.sdk.resource

resource_create

Creates any resource type.

Signature:

resource_create(
name: str,
image_name: str,
entity: str = "custom",
cpu: int = 1,
memory: int = 2,
shm_size: int = 0,
gpu: int = 0,
gpu_type: str = "A5000",
volumes: list = [],
volume_full_path: str = "",
startup_command: str = "",
repository_secret: str = "",
cgc_data: list[str] = [],
environment_data: list[str] = [],
arguments_data: list[str] = [],
config_maps_data: list = [],
node_port_enabled: bool = False
) -> dict

Parameters:

  • name (str, required): Unique name for the resource
  • image_name (str): Docker image to deploy - required for non-default apps
  • entity (str): Entity type, defaults to "custom"
  • cpu (int): Number of CPU cores (default: 1)
  • memory (int): Memory in GB (default: 2)
  • shm_size (int): Shared memory size in GB (default: 0)
  • gpu (int): Number of GPUs (default: 0)
  • gpu_type (str): GPU type - A5000, A100, etc. (default: "A5000")
  • volumes (list): List of volume names to mount
  • volume_full_path (str): Mount path for volumes
  • startup_command (str): Override container entrypoint
  • repository_secret (str): Secret for private registries
  • cgc_data (list[str]): CGC-specific configuration
  • environment_data (list[str]): Environment variables as "KEY=value"
  • arguments_data (list[str]): Command line arguments
  • config_maps_data (list): ConfigMap configurations
  • node_port_enabled (bool): Enable NodePort service

Returns:

  • dict: Response with code and details fields

Raises:

  • SDKException: With code -2 if image_name is missing
  • SDKException: With code -3 if invalid GPU type

resource_delete

Deletes a resource.

Signature:

resource_delete(name: str) -> dict

Parameters:

  • name (str): Name of resource to delete

Returns:

  • dict: Response with deletion status

compute_list

Lists all compute resources in the current context.

Signature:

compute_list() -> dict

Returns:

  • dict: Response containing list of compute resources
    • code: HTTP status code
    • details: Contains pods_list with resource information

db_list

Signature:

db_list() -> dict

Returns:

  • dict: Response containing list of compute resources
    • code: HTTP status code
    • details: Contains pods_list with resource information

resource_ready

Checks if a resource is ready and running.

Signature:

resource_ready(
name: str,
resource_type: ResourceTypes = ResourceTypes.compute
) -> bool

Parameters:

  • name (str): Resource name to check
  • resource_type (ResourceTypes): Type of resource (compute, db, or job)

Returns:

  • bool: True if resource is running, False otherwise

resource_add_port

Adds a port to an existing resource.

Signature:

resource_add_port(
name: str,
port_name: str,
new_port: int,
ingress: bool = True
) -> dict

Parameters:

  • name (str): Resource name
  • port_name (str): Name for the port
  • new_port (int): Port number
  • ingress (bool): Enable external access (default: True)

Returns:

  • dict: Response with operation status

resource_update_port

Updates an existing port configuration.

Signature:

resource_update_port(
name: str,
port_name: str,
new_port: int,
ingress: bool = True
) -> dict

Parameters:

  • name (str): Resource name
  • port_name (str): Name of port to update
  • new_port (int): New port number
  • ingress (bool): Enable external access

Returns:

  • dict: Response with operation status

resource_delete_port

Removes a port from a resource.

Signature:

resource_delete_port(
name: str,
port_name: str
) -> dict

Parameters:

  • name (str): Resource name
  • port_name (str): Name of port to delete

Returns:

  • dict: Response with operation status

resource_list_ports

Lists all ports for a resource.

Signature:

resource_list_ports(name: str) -> dict

Parameters:

  • name (str): Resource name

Returns:

  • dict: Response containing port configurations

get_entity_list

Gets list of all available entity types.

Signature:

get_entity_list() -> list[str]

Returns:

  • list[str]: List of available entity names

get_available_compute_templates

Gets list of available compute templates for the enabled context.

Signature:

get_available_compute_templates() -> list[str]

Returns:

  • list[str]: List of compute template names

get_available_database_templates

Gets list of available database templates for the enabled context.

Signature:

get_available_database_templates() -> list[str]

Returns:

  • list[str]: List of database template names

get_available_gpu_types

Gets list of available GPU types for the enabled context.

Signature:

get_available_gpu_types() -> list[str]

Returns:

  • list[str]: List of GPU type names

start_function_loop

Executes a function in a loop until successful (response code 200).

Signature:

start_function_loop(
function,
infinite: bool = True,
*args,
**kwargs
) -> None

Parameters:

  • function: Function to execute
  • infinite (bool): Loop infinitely or try 5 times (default: True)
  • *args: Positional arguments for function
  • **kwargs: Keyword arguments for function

Raises:

  • SDKException: If response code 409 or not 200 after 5 attempts (when not infinite)

stop_function_loop

Executes a function in a loop until it returns False or 404.

Signature:

stop_function_loop(
function,
infinite: bool = True,
*args,
**kwargs
) -> None

Parameters:

  • function: Function to execute
  • infinite (bool): Loop infinitely or try 5 times
  • *args: Positional arguments for function
  • **kwargs: Keyword arguments for function