Skip to main content
Version: 1.12.0

Workspace APIs

This topic describes the Python SDK APIs for the workspace operations.

Create a Workspace

The create workspace API creates a workspace that spans across multiple clusters, and namespaces already onboarded with the EGS controller. Provisioning a workspace creates an isolated environment in which the end user can request GPU resources and deploy workloads.

Syntax

egs.create_workspace(workspace_name, clusters, namespaces, username, email, authenticated_session=None)

Parameters

Input ParameterTypeDescriptionRequired
workspace_nameStringThe name of the workspace to be created.Mandatory
clustersList of stringsThe set of clusters that should be part of the workspace. The cluster must be registered with the EGS controller before it can be onboarded onto a workspace.Mandatory
namespacesList of stringsThe set of namespaces that should be part of the workspace. These namespaces will be created on the workspace cluster if they don’t exist.Mandatory
usernameStringThe name of the user requesting for the workspace.Mandatory
emailStringThe email of the user requesting for the workspace.Mandatory
authenticated_session[AuthenticatedSession]The authenticated session with the EGS controller. The default value is None. If no authenticated session has been provided, SDK will try to use the SDK default. If no SDK default has been found, an exception will be raisedOptinal

Response Object Returned

ReturnsDescription
StringThe name of workspace.

Exceptions Raised

RaisesDescription
exceptions.UnauthorizedThis exception is raised when the workspace creation is not allowed to the API Key.
exceptions.WorkspaceAlreadyExistsThis exception is raised when a workspace with the given name already exists.

Example

import egs
from egs.exceptions import ApiKeyInvalid, ApiKeyNotFound, WorkspaceAlreadyExists
try:
# Authenticate the EGS
auth = egs.authenticate("https://egs-core-apis.example.com", "5067bd55-1aef-4c84-8987-3e966e917f07")
workspace_name = egs.create_workspace("llm-gpt-4o", ["worker-1", "worker-2"], ["llm-gpt-40-dev"], "John Doe", "john.doe@avesha.io", auth)

except ApiKeyInvalid as e:
# Do something when API key is not found
print("API Key is Invalid")
print(e)
except ApiKeyNotFound as e:
# Do something when API key is not found
print("API Key not found")
print(e)
except WorkspaceAlreadyExists as e:
# Do something when API key is not found
print("WorkspaceAlreadyExists found")
print(e)
except Exception as e:
print(e)
print(f"Exception: {e}")

Delete a Workspace

The delete workspace API deletes the provisioned workspace.

Syntax

egs.delete_workspace(workspace_name, authenticated_session=None) 

Parameters

InputParameter TypeDescriptionRequired
workspace_nameStringThe name of the workspace to be deleted.Mandatory
authenticated_session[AuthenticatedSession]The authenticated session with the EGS controller. The default value is None, If no authenticated session has been provided, SDK will try to use the SDK default. If no SDK default has been found, an exception will be raised.Optional

Response Object Returned

ReturnsDescription
BooleanThe value is true, if the workspace deletion is successful. The value is false, if the workspace deletion is unsuccessful.

Exceptions Raised

RaisesDescription
exceptions.UnauthorizedThis exception is raised when the workspace deletion is not allowed to the API Key.

Example

import egs
from egs.exceptions import ApiKeyInvalid, ApiKeyNotFound, WorkspaceAlreadyExists
try:
# Authenticate the EGS
auth = egs.authenticate("https://egs-core-apis.example.com", "5067bd55-1aef-4c84-8987-3e966e917f07")
workspace_name = egs.create_workspace("llm-gpt-4o", ["worker-1", "worker-2"], ["llm-gpt-40-dev"], "John Doe", "john.doe@avesha.io", auth)
delete_status = egs.delete_workspace("llm-gpt-4o", authenticated_session=auth)
print(delete_status)
except ApiKeyInvalid as e:
# Do something when API key is not found
print("API Key is Invalid")
print(e)
except ApiKeyNotFound as e:
# Do something when API key is not found
print("API Key not found")
print(e)
except WorkspaceAlreadyExists as e:
# Do something when API key is not found
print("WorkspaceAlreadyExists found")
print(e)
except Exception as e:
print(e)
print(f"Exception: {e}")

List Workspaces

The list workspaces API returns the list of workspaces that the EGS controller controls.

Syntax

egs.list_workspaces(authenticated_session=None) 

Parameters

InputParameter TypeDescriptionRequired
authenticated_session[AuthenticatedSession]The authenticated session with EGS controller. The default value is None. If no authenticated session has been provided, SDK will use the SDK default. If no SDK default value is found, an exception will be raised.Optional

Response Object Returned

ReturnsDescription
List[class Workspace]The list of EGS workspaces.

Exceptions Raised

RaisesDescription
exceptions.UnauthorizedThis exception is raised when the operation is not allowed to the API Key.

Type: class Workspace

ParameterTypeDescriptionRequired
nameStringThe name of the workspace.Mandatory
clustersList of stringsThe list of clusters that are attached to the workspace.Mandatory
namespacesList of stringsThe list of namespaces that are attached to the workspace.Mandatory

Example

import egs 
auth = egs.authenticate("https://egs-core-apis.example.com", "5067bd55-1aef-4c84-8987-3e966e917f07")
workspaces = egs.list_workspaces(auth)

Get Workspace Kubeconfig

The workspace kubeconfig API returns the Kubernetes kubeconfig YAML in the text format whicch is used directly with Kubernetes SDK and/or with the kubectl CLI for the deployment of workloads on the cluster.

Syntax

egs.get_workspace_kubeconfig(workspace_name, cluster_name, authenticated_session=None)

Parameters

InputParameter TypeDescriptionRequired
workspace_nameStringThe name of the workspace for which the kubeconfig should be generated.Mandatory
cluster_nameStringThe name of the cluster.Mandatory
authenticated_session[AuthenticatedSession]The authenticated session with the EGS controller. The default value is None. If no authenticated session has been provided, SDK will try to use the SDK default. If no SDK default is found, an exception will be raised.Optional

Response Object Returned

ReturnsDescription
StringThe kubeconfig YAML file in the text format.

Exceptions Raised

RaisesDescription
exceptions.UnauthorizedThis exception is raised when requesting the kubeconfig YAML is not allowed to the API Key.

Example

import egs
from egs.exceptions import ApiKeyInvalid, ApiKeyNotFound, WorkspaceAlreadyExists
try:
# Authenticate the EGS
auth = egs.authenticate("https://egs-core-apis.example.com", "5067bd55-1aef-4c84-8987-3e966e917f07")
workspace_name = egs.create_workspace("llm-gpt-4o", ["worker-1", "worker-2"], ["llm-gpt-40-dev"], "John Doe", "john.doe@avesha.io", auth)

kube_config = egs.get_workspace_kubeconfig("llm-gpt-4o",
"worker-1",
authenticated_session=auth)
print(kube_config)
except ApiKeyInvalid as e:
# Do something when API key is not found
print("API Key is Invalid")
print(e)
except ApiKeyNotFound as e:
# Do something when API key is not found
print("API Key not found")
print(e)
except WorkspaceAlreadyExists as e:
# Do something when API key is not found
print("WorkspaceAlreadyExists found")
print(e)
except Exception as e:
print(e)
print(f"Exception: {e}")