Managing Your Compute
Manage your clusters, nodepools, and deployments
You can efficiently manage your clusters, nodepools, and deployments within the Clarifai platform to optimize performance and costs. You can gain valuable insights by retrieving detailed resource information, and streamline your compute environment by removing unused resources.
Cluster Operations
Get a Cluster
To get a specific compute cluster, pass the compute_cluster_id
to the compute_cluster
method of the User
class.
- Python
from clarifai.client.user import User
import os
# Set the PAT key
os.environ["CLARIFAI_PAT"] = "YOUR_PAT_HERE"
# Initialize the client
client = User(
user_id="YOUR_USER_ID_HERE",
base_url="https://api.clarifai.com"
)
# Get and print the compute cluster
compute_cluster = client.compute_cluster(
compute_cluster_id="test-compute-cluster"
)
print(compute_cluster)
List All Clusters
To list your existing compute clusters, call the list_compute_clusters
method of the User
class.
- Python
- Bash
from clarifai.client.user import User
import os
# Set the PAT key
os.environ["CLARIFAI_PAT"] = "YOUR_PAT_HERE"
# Initialize the client
client = User(
user_id="YOUR_USER_ID_HERE",
base_url="https://api.clarifai.com"
)
# Get and print all the compute clusters
all_compute_clusters = list(
client.list_compute_clusters()
)
print(all_compute_clusters)
$ clarifai computecluster list
Nodepool Operations
Get a Nodepool
To get a specific nodepool, provide the nodepool_id
to the nodepool
method of the ComputeCluster
class.
- Python
from clarifai.client.compute_cluster import ComputeCluster
import os
# Set the PAT key
os.environ["CLARIFAI_PAT"] = "YOUR_PAT_HERE"
# Initialize the ComputeCluster instance
compute_cluster = ComputeCluster(
user_id="YOUR_USER_ID_HERE",
compute_cluster_id="test-compute-cluster",
base_url="https://api.clarifai.com"
)
# Get and print the nodepool
nodepool = compute_cluster.nodepool(
nodepool_id="test-nodepool"
)
print(nodepool)
List All Nodepools
To list the existing nodepools, call the list_nodepools
method of the ComputeCluster
class.
- Python
- Bash
from clarifai.client.compute_cluster import ComputeCluster
import os
# Set the PAT key
os.environ["CLARIFAI_PAT"] = "YOUR_PAT_HERE"
# Initialize the ComputeCluster instance
compute_cluster = ComputeCluster(
user_id="YOUR_USER_ID_HERE",
compute_cluster_id="test-compute-cluster",
base_url="https://api.clarifai.com"
)
# Get and print all the nodepools
all_nodepools = list(
compute_cluster.list_nodepools()
)
print(all_nodepools)
$ clarifai nodepool list --compute_cluster_id <compute-cluster-id>
Deployment Operations
Get a Deployment
To get a specific deployment, provide the deployment_id
to the deployment
method of the Nodepool
class.
- Python
from clarifai.client.nodepool import Nodepool
import os
# Set the PAT key
os.environ["CLARIFAI_PAT"] = "YOUR_PAT_HERE"
# Initialize the Nodepool instance
nodepool = Nodepool(
user_id="YOUR_USER_ID_HERE",
nodepool_id="test-nodepool",
base_url="https://api.clarifai.com"
)
## Get and print the deployment
deployment = nodepool.deployment(
deployment_id="test-deployment"
)
print(deployment)
List All Deployments
To list existing deployments, call the list_deployments
method of the Nodepool
class.
- Python
- Bash
from clarifai.client.nodepool import Nodepool
import os
# Set the PAT key
os.environ["CLARIFAI_PAT"] = "YOUR_PAT_HERE"
# Initialize the Nodepool instance
nodepool = Nodepool(
user_id="YOUR_USER_ID_HERE",
nodepool_id="test-nodepool",
base_url="https://api.clarifai.com"
)
# Get and print all the deployments
all_deployments = list(
nodepool.list_deployments()
)
print(all_deployments)
$ clarifai deployment list --nodepool_id <nodepool-id>
Delete Resources
Delete Deployments
To delete deployments, pass a list of deployment IDs to the delete_deployments
method of the Nodepool
class.
- Python
- Bash
from clarifai.client.nodepool import Nodepool
import os
# Set the PAT key
os.environ["CLARIFAI_PAT"] = "YOUR_PAT_HERE"
# Initialize the Nodepool instance
nodepool = Nodepool(
user_id="YOUR_USER_ID_HERE",
nodepool_id="test-nodepool",
base_url="https://api.clarifai.com"
)
# Get all the deployments in the nodepool
all_deployments = list(nodepool.list_deployments())
# Extract deployment IDs for deletion
deployment_ids = [deployment.id for deployment in all_deployments]
# Delete a specific deployment by providing its deployment ID
# deployment_ids = ["test-deployment"]
# Delete the deployments
nodepool.delete_deployments(deployment_ids=deployment_ids)
$ clarifai deployment delete --nodepool_id <nodepool-id> --deployment_id <deployment-id>
Delete Nodepools
To delete nodepools, provide a list of nodepool IDs to the delete_nodepools
method of the ComputeCluster
class.
- Python
- Bash
from clarifai.client.compute_cluster import ComputeCluster
import os
# Set the PAT key
os.environ["CLARIFAI_PAT"] = "YOUR_PAT_HERE"
# Initialize the ComputeCluster instance
compute_cluster = ComputeCluster(
user_id="YOUR_USER_ID_HERE",
compute_cluster_id="test-compute-cluster",
base_url="https://api.clarifai.com"
)
# Get all nodepools within the compute cluster
all_nodepools = list(compute_cluster.list_nodepools())
# Extract nodepool IDs for deletion
nodepool_ids = [nodepool.id for nodepool in all_nodepools]
# Delete a specific nodepool by providing its ID
# nodepool_ids = ["test-nodepool"]
# Delete the nodepools
compute_cluster.delete_nodepools(nodepool_ids=nodepool_ids)
$ clarifai nodepool delete --compute_cluster_id <compute-cluster-id> --nodepool_id <nodepool-id>
Delete Compute Clusters
To delete compute clusters, provide a list of compute cluster IDs to the delete_compute_clusters
method of the User
class.
- Python
- Bash
from clarifai.client.user import User
import os
# Set the PAT key
os.environ["CLARIFAI_PAT"] = "YOUR_PAT_HERE"
# Initialize the User client
client = User(
user_id="YOUR_USER_ID_HERE",
base_url="https://api.clarifai.com"
)
# Get all compute clusters associated with the user
all_compute_clusters = list(client.list_compute_clusters())
# Extract compute cluster IDs for deletion
compute_cluster_ids = [compute_cluster.id for compute_cluster in all_compute_clusters]
# Delete a specific nodepool by providing its ID
# compute_cluster_ids = ["test-compute-cluster"]
# Delete the compute clusters
client.delete_compute_clusters(compute_cluster_ids=compute_cluster_ids)
$ clarifai computecluster delete --compute_cluster_id <compute-cluster-id>