Reputation: 591
I have an instance that I can upgrade and downgrade machine type from gcloud command. For example, I can do
gcloud compute instances set-machine-type instance-name --machine-type f1-micro
to downgrade an existing instance and
gcloud compute instances set-machine-type ubuntu --machine-type n1-standard-1
to upgrade the machine type. But I need to also attach an GPU when I upgrade. I can do that on web interface but I need to do this on command line.
Upvotes: 0
Views: 458
Reputation: 591
It's possible to attach a GPU from API but looks like it's not possible to detach one after attaching.
Here's how to attach a GPU to an existing instance.
POST https://www.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instances/ubuntu/setMachineResources
{
"guestAccelerators": [
{
"acceleratorType": "https://www.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/acceleratorTypes/nvidia-tesla-k80",
"acceleratorCount": 1
}
]
}
Here's the reference to the feature request to made for detaching a GPU.
https://issuetracker.google.com/65267943
Upvotes: 2
Reputation: 327
Currently, it is not possible to attach GPU to an existing instance using "gcloud" command. You can attach GPU using cloud console, "EDIT" option of the instance when it is in the stop state. Another way to attach GPU to an existing instance (stopped) is through API [1][2].
Following is the URL syntax which needs to be defined for property guestAccelerators[].acceleratorType:
https://www.googleapis.com/compute/beta/projects/project-id/zones/zone-where-instance-is-deployed/acceleratorTypes/nvidia-tesla-k80
Example:
https://www.googleapis.com/compute/beta/projects/test-project/zones/us-west1-b/acceleratorTypes/nvidia-tesla-k80
[2] https://cloud.google.com/compute/docs/reference/beta/instances/setMachineResources
Upvotes: 0