Reputation: 3
I want to add more data disks to existing VM instance object using java SDK. Below are my sample code:
Compute.Instances.Get getinstance = compute.instances().get(projectId, zone, instanceName);
Instance instance = getinstance.execute();
AttachedDisk dataDisk = new AttachedDisk();
dataDisk.setSource("projects/project/zones/zone/disks/diskName");
dataDisk.setType("PERSISTENT");
dataDisk.setMode("READ_WRITE");
dataDisk.setAutoDelete(true);
instance.getDisks().add(attacheddisk);
But I didn't see any method in compute service for update/put.Can any one help on this. I know how to do update the instance by using Rest API,But i want do this by java sdk.
Upvotes: 0
Views: 252
Reputation: 1839
You can attach instance using methods of Compute.Instances
class only. These methods will update the instance during execution.
AttachedDisk dataDisk = new AttachedDisk();
dataDisk.setSource("projects/project/zones/zone/disks/diskName");
dataDisk.setType("PERSISTENT");
dataDisk.setMode("READ_WRITE");
dataDisk.setAutoDelete(true);
//attach disk to instance
Compute.Instances.AttachDisk attachDisk=compute.instances().attachDisk(projectId, zone, instanceName, dataDisk);
To attach multiple disk, I don't think there is any method exposed in java API. You would have to call attachDisk()
To check LUN AttachDisk
class provides getIndex()
, where 0 is reserved for boot disk. Check the link for more information on LUN in GCP.
Upvotes: 1