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 resourceimage_name(str): Docker image to deploy - required for non-default appsentity(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 mountvolume_full_path(str): Mount path for volumesstartup_command(str): Override container entrypointrepository_secret(str): Secret for private registriescgc_data(list[str]): CGC-specific configurationenvironment_data(list[str]): Environment variables as "KEY=value"arguments_data(list[str]): Command line argumentsconfig_maps_data(list): ConfigMap configurationsnode_port_enabled(bool): Enable NodePort service
Returns:
dict: Response withcodeanddetailsfields
Raises:
SDKException: With code -2 if image_name is missingSDKException: 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 resourcescode: HTTP status codedetails: Containspods_listwith resource information
db_list
Signature:
db_list() -> dict
Returns:
dict: Response containing list of compute resourcescode: HTTP status codedetails: Containspods_listwith 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 checkresource_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 nameport_name(str): Name for the portnew_port(int): Port numberingress(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 nameport_name(str): Name of port to updatenew_port(int): New port numberingress(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 nameport_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
Raises:
SDKException: when amount of the templates is incorrect. Usually due to the context configuration missing
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 executeinfinite(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 executeinfinite(bool): Loop infinitely or try 5 times*args: Positional arguments for function**kwargs: Keyword arguments for function