Workspace APIs
This topic describes the Python SDK APIs for the workspace operations.
Create a Workspace
The create workspace API provisions a workspace that spans multiple clusters and namespaces already onboarded with the EGS controller. This workspace acts as an isolated environment where end users can request GPU resources and deploy workloads.
Syntax
egs.create_workspace(workspace_name, clusters, namespaces, username, email, authenticated_session=None)
Parameters
Input Parameter | Type | Description | Required |
---|---|---|---|
workspace_name | String | The name of the workspace to be created. | Mandatory |
clusters | List of strings | The 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 |
namespaces | List of strings | The 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 |
username | String | The name of the user requesting the workspace. | Mandatory |
String | The email of the user requesting 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 raised. | Optional |
Response Object Returned
Returns | Description |
---|---|
String | The name of workspace. |
Exceptions Raised
Raises | Description |
---|---|
exceptions.Unauthorized | This exception is raised when the workspace creation is not allowed to the API Key. |
exceptions.WorkspaceAlreadyExists | This 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
Input | Parameter Type | Description | Required |
---|---|---|---|
workspace_name | String | The 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
Returns | Description |
---|---|
Boolean | The value is true, if the workspace deletion is successful. The value is false, if the workspace deletion is unsuccessful. |
Exceptions Raised
Raises | Description |
---|---|
exceptions.Unauthorized | This 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
Input | Parameter Type | Description | Required |
---|---|---|---|
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
Returns | Description |
---|---|
List[class Workspace] | The list of EGS workspaces. |
Exceptions Raised
Raises | Description |
---|---|
exceptions.Unauthorized | This exception is raised when the operation is not allowed to the API Key. |
Type: class Workspace
Parameter | Type | Description | Required |
---|---|---|---|
name | String | The name of the workspace. | Mandatory |
clusters | List of strings | The list of clusters that are attached to the workspace. | Mandatory |
namespaces | List of strings | The 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
Input | Parameter Type | Description | Required |
---|---|---|---|
workspace_name | String | The name of the workspace for which the kubeconfig should be generated. | Mandatory |
cluster_name | String | The 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
Returns | Description |
---|---|
String | The kubeconfig YAML file in the text format. |
Exceptions Raised
Raises | Description |
---|---|
exceptions.Unauthorized | This 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}")