In the previous post (vCloud Independent Disks: Part 1 – Creating Disks) I went through how to create a 50Gb Indepenedent disk called “IndDisk_DBFiles1”. In this post, I will show the process for attaching an Independent Disk (this time called “50GB-IndDisk” but the name doesn’t matter) to a VM and detaching it again.
Attaching an Independent Disk
To attach the independent disk to a VM, you first need to know the “HREF” for the VM. This is the URL that represents the VM within the vCloud API. In the case of my case VM, this will be https://vcloud.mycloud.com/api/vApp/vm-6e245160-58ae-421d-8109-74d5c795b7a1. You then have to build up a “DiskAttachOrDetachParams” XML element which will contain the HREF to the Independent Disk. Then you POST that XML into the vCloud API using VM HREF with “/disk/action/attach” added to the end.
So in this example I used:
URL | https://vcloud.mycloud.com/api/vApp/vm-6e245160-58ae-421d-8109-74d5c795b7a1/disk/action/attach |
Action | POST |
Content-Type | application/vnd.vmware.vcloud.diskAttachOrDetachParams+xml |
Request Body | <?xml version="1.0" encoding="UTF-8"?> <DiskAttachOrDetachParams xmlns="http://www.vmware.com/vcloud/v1.5"> <Disk type="application/vnd.vmware.vcloud.disk+xml" href="https://vcloud.mycloud.com/api/disk/bda4fb2c-d4eb-4976-8bdc-52b2b7f28b3a" /> </DiskAttachOrDetachParams> |
In the vSphere Client, we can see that the disk is removed from the disk shell VM and the disk shell VMs deleted as it’s no longer needed. The target VM is then reconfigured, attaching the VMDK for the Independent Disk to the target VM.
The newly added disk as it appears in the VM Hardware properties in vCloud Director. It’s obviously not a normal disk as it has a Name rather than something like “Disk1” and the size cannot be changed within the interface.
Now it’s on the VM it can be mounted in the OS, formatted and used for whatever you want. Note, it can only be attached to a single VM at any one time. This is not for use for clustered storage between VMs.
Detaching an Independent Disk
To detach the disk, you make almost an identical call as you do to attach a disk, except you change the end of the URL to “detach” rather than “attach”.
So in this example I used:
URL | https://vcloud.mycloud.com/api/vApp/vm-6e245160-58ae-421d-8109-74d5c795b7a1/disk/action/detach |
Action | POST |
Content-Type | application/vnd.vmware.vcloud.diskAttachOrDetachParams+xml |
Request Body | <?xml version="1.0" encoding="UTF-8"?> <DiskAttachOrDetachParams xmlns="http://www.vmware.com/vcloud/v1.5"> <Disk type="application/vnd.vmware.vcloud.disk+xml" href="https://vcloud.mycloud.com/api/disk/bda4fb2c-d4eb-4976-8bdc-52b2b7f28b3a" /> </DiskAttachOrDetachParams> |
The disk is removed from the VM. A new disk shell VM is created and the disk is mounted to it.
Again you can see the disk shell VM from the vSphere Client.