By William Lam, Sr. Technical Marketing Engineer
In vCloud Director today, users can not modify or resize a virtual disk for a Virtual Machine (VM) using the vCloud UI, even if the VM is powered off. Though not ideal, this operation can still be accomplished in vCloud Director by leveraging the vCloud API or vCenter Orchestrator (vCO). In this article, I will demonstrate how you can easily resize a virtual disk for a VM in vCloud Director as well as hot-add and hot-extend a virtual disk for a running VM using the vCloud API.
Before getting started, if you are not familiar with the vCloud API, you should take a look here and here for an introduction on how to get started.
Resize Virtual Disk
Let’s start off by identifying a VM in vCloud Director that we wish to modify the virtual disk. In this example, I have a VM called VM1 that is powered off and it is configured with a single 8GB virtual disk.
To retrieve the VM and inspect its virtual disk configuration using the vCloud API, we will leverage the Query Service API to quickly find the VM in question.
$ curl -i -k -H “Accept:application/*+xml;version=1.5” -H “x-vcloud-authorization: vx0dCUUMJkA/dgRz8SyMfFReOAQju02/LTjm6/JP52Y=” -X GET “https://vcd/api/query?type=adminVM&filter=(name==VM1)“
Next, to get a list of all the virtual disks for the VM, we just need to look at the disk section by using the GET operation for the VM as documented here in the vCloud API. Take the VM’s href URL and append the following /virtualHardwareSection/disks. Using the example above, our final URL will be
https://vcd/api/vApp/vm-e71abae8-ca51-4418-94fd-c726e9e443c6/virtualHardwareSection/disks
$ curl -i -k -H “Accept:application/*+xml;version=1.5” -H “x-vcloud-authorization: vx0dCUUMJkA/dgRz8SyMfFReOAQju02/LTjm6/JP52Y=” -X GET https://vcd/api/vApp/vm-e71abae8-ca51-4418-94fd-c726e9e443c6/virtualHardwareSection/disks
As you can see from the response output, we have a single 8GB virtual disk which is connected to an LSI Logic SCSI controller on bus 0 with unit number 0. It also contains a default IDE controller. To increase the disk capacity from 8GB to 10GB, we just need to adjust the “vcloud:capacity” property and perform an update using the PUT operation.
For this, we need to create a file that contains the changes we plan on making. In this example I will create a file called increase-disk. The easiest way to create this file is to take the output from our initial GET operation on the VM’s disk and paste that into the file and then modify the “vcloud:capacity” property from 8192 to 10240.
Note: Even though we are just changing the capacity of a single virtual disk, we need to ensure that we include the rest of the original elements in the request, else you could accidentally remove a virtual disk or controller.
Now we are ready to resize the VM’s virtual disk by using the PUT operation on the VM’s disk and specifying the request file we just created as outlined in the vCloud API Programming Guide here.
$ curl -i -k -H “Accept:application/*+xml;version=1.5” -H “x-vcloud-authorization: vx0dCUUMJkA/dgRz8SyMfFReOAQju02/LTjm6/JP52Y=” -X PUT https://vcd/api/vApp/vm-e71abae8-ca51-4418-94fd-c726e9e443c6/virtualHardwareSection/disks -H “Content-Type: application/vnd.vmware.vcloud.rasdItemsList+xml” -d @increase-disk
If you take a look at the VM in the vCloud UI after the operation, you should now see the virtual disk for the VM has successfully been increased.
Note: You can only increase the capacity of the virtual disk for a VM, you can not decrease the capacity. This is the exact same behavior in vSphere.
Lastly, you will need to go into your guestOS and extend the disk partition to ensure that the new capacity is now seen. You should refer to the guestOS documentation for the steps.
As you can see the process of modifying a virtual disk for an offline VM is fairly straightforward, we retrieve the disk section of the VM using the GET operation and then we change/modify the disk(s) using the PUT operation. So what about hot-adding or hot-extending a virtual disk for a running VM?
Hot-Extend Virtual Disk
The process of hot-extending a virtual disk is exactly the same as modifying an existing virtual disk. You just need to perform a GET operation on the disk section of the VM in question, then modify the capacity for the virtual disk(s) you wish to extend using the PUT operation as shown above. Here is an example of the request file for increasing our VM1 from 10GB to 20GB while it is running.
Here is the screenshot of the VM in the vCloud UI:
Do not forget to go into the guestOS to extend the disk partition for the new capacity to be seen.
Hot-Add Virtual Disk
The process of hot-adding a virtual disk follows a similar workflow, but instead of just modifying a single property, you will be adding an additional entry into the request. In this example, I will be adding an additional 2GB virtual disk residing on the same SCSI controller and will be using unit 1 as defined in AddressOnParent property (you will need to increment this based on the number of devices on the given controller). Next you need to adjust the ElementName property to reflect the hard disk name, in this example it will be “Hard disk 2”. Finally, you will need to also adjust the InstanceID which must be a unique ID and in this example I took the original InstanceID of our first virtual disk and added that to AddressOnParent property giving me a value of 2001.
Here is an example of the request file for the additional virtual disk to be added to the VM while it is running:
Here is the screenshot of the VM in the vCloud UI:
Do not forget to go into the guestOS to extend the disk partition for the new capacity to be seen.
Fast Provisioning Caveat
One additional thing you should be aware of, is that you will not be able to resize or hot-extend a virtual disk for a Fast Provisioned VM in vCloud Director. The reason for this is the use of snapshots with Linked Clones which Fast Provisioning leverages. If you try to perform the operation using the vCloud API or even the vCO workflow “Change Hard disk capacity”, you may see the following error in the vCloud UI and/or in vCenter Server if you have access:
Invalid hard disk parameters specified. The following parameters are invalid or conflict with other configured devices in the virtual machine:
Adaptor Type: SCSILSILOGIC, Bus Number: 0, Unit Number: 0
If you need to modify the virtual disk for a Fast Provisioned VM, you will need to consolidate the VM’s virtual disk which will inflate the VM to a “thick” provisioned VM and no longer leveraging Linked Clones. You will still be able to hot-add a disk for a Fast Provisioned VM, but if you decide to clone from this VM, that you will not be able to resize or extend the disk afterwards due to use of Fast Provisioning.
In conclusion, though the vCloud UI does not provide the functionality today to resize a virtual disk for a VM in vCloud Director, you can still leverage the vCloud API to help you accomplish this task. In addition, you can also perform both hot-add and hot-extend of a virtual disk for running VMs in vCloud Director.
Additional Resources:
If you are interested in using the PowerCLI cmdlets for vCloud Director, you can check out this blog post by Jake Robinson who shows you an example of using the vCloud API and PowerCLI cmdlets with vCloud Director http://geekafterfive.com/2012/02/24/vcloud-apigui-throwdown-part-2/
Get notification of new blog postings and more by following lamw on Twitter: @lamw