VMware Cloud Community
adityaravi007
Contributor
Contributor

Virtual VM Disk resizing

Is there any provision for resizing the virtual disk allocated to a virtual machine inVirtual CLoud Director like we have vMware vCentre Converter for VMware?

I need help on this. So if somebody has any information related to this, please do share with me.

0 Kudos
7 Replies
IamTHEvilONE
Immortal
Immortal

Resizing the disks is not part of the vCloud Web UI at this point in time, and we are looking at this in the future ... but I can't say much about that now.

For sake of vCloud, it'll be an export / modify / import ... and I think there is an API call that might be able to do is (but you'd have to ask in that forum).

As for vCenter ... converter will make a number of other changes to the OS than just increasing the disk size.

Also, in vCenter, you can just "edit settings" on the VM and increase the disk size granted that it has no snapshots or other links to the disk.  This will increase the disk size ... but doesn't modify partition information from the Guest OS perspective.

best Regards,

Jon Hemming

0 Kudos
kirilk
VMware Employee
VMware Employee

Hi,

I was able to do this using the API for a Linux VM using SCSI BusLogic virtual disk.

In essence the steps were:

0. Log in to the API and navigate to the VM whose disk you want to resize.

1. Get the VMs disks hardware section (there is a link to it from the vApp/VM representation. GET https://cloud-test/api/vApp/vm-60423e4d-b937-4a7f-b73c-cfd5605a590b/virtualHardwareSection/disks

2. Update the HostResource capacity value of the disk uyou want to resize

<rasd:HostResource xmlns:vcloud="http://www.vmware.com/vcloud/v1.5" vcloud:capacity="213" vcloud:busSubType="buslogic" vcloud:busType="6" />

3. PUT back the XML at the same URL as shown below.

4. This starts a task in vCloud Director that when finished has changed the size of the VM disk to desired value

What I have noted is that this does not resize the partitions on the disk. I used fdisk on the Linux VM and saw the disk size has changed and I have free space that I can possibly reclaim in a new partition

hope this helps

Request:


HTTP 1.1
PUT https://cloud-test/api/vApp/vm-60423e4d-b937-4a7f-b73c-cfd5605a590b/virtualHardwareSection/disks
Content-type:application/vnd.vmware.vcloud.rasditemslist+xml;version=1.5; charset=UTF-8
Headers:
Cookie: vcloud-token=nWGT42IHT6IT4x8E7zE9aV4BT4COX7Q5uS/TLGVV7u8=; Secure; Path=/
Accept: application/*+xml;version=1.5
Body:
<?xml version="1.0" encoding="UTF-8"?>
<RasdItemsList xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" type="application/vnd.vmware.vcloud.rasdItemsList+xml" href="https://cloud-test/api/vApp/vm-60423e4d-b937-4a7f-b73c-cfd5605a590b/virtualHardwareSection/disks" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://10.147.44.125/api/v1.5/schema/master.xsd http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2.22.0/CIM_ResourceAllocationSettingData.xsd">
     <Link rel="edit" type="application/vnd.vmware.vcloud.rasdItemsList+xml" href="https://cloud-test/api/vApp/vm-60423e4d-b937-4a7f-b73c-cfd5605a590b/virtualHardwareSection/disks"/>
     <Item>
         <rasd:Address>0</rasd:Address>
         <rasd:Description>SCSI Controller</rasd:Description>
         <rasd:ElementName>SCSI Controller 0</rasd:ElementName>
         <rasd:InstanceID>1</rasd:InstanceID>
         <rasd:ResourceSubType>buslogic</rasd:ResourceSubType>
         <rasd:ResourceType>6</rasd:ResourceType>
     </Item>
     <Item>
         <rasd:AddressOnParent>0</rasd:AddressOnParent>
         <rasd:Description>Hard disk</rasd:Description>
         <rasd:ElementName>Hard disk 1</rasd:ElementName>
         <rasd:HostResource xmlns:vcloud="http://www.vmware.com/vcloud/v1.5" vcloud:capacity="213" vcloud:busSubType="buslogic" vcloud:busType="6"></rasd:HostResource>
         <rasd:InstanceID>2000</rasd:InstanceID>
         <rasd:Parent>1</rasd:Parent>
         <rasd:ResourceType>17</rasd:ResourceType>
     </Item>
</RasdItemsList>

--------------------------------------------------

Response:


HTTP/1.1 202 Accepted
Headers:
Date: Fri, 02 Sep 2011 15:26:34 GMT
Location: https://cloud-test/api/task/5ca2c7f7-7471-42de-a42b-042422b94fd9
Content-Type: application/vnd.vmware.vcloud.task+xml;version=1.5
Content-Length: 1237
Body:
<?xml version="1.0" encoding="UTF-8"?>
<Task xmlns="http://www.vmware.com/vcloud/v1.5" status="running" startTime="2011-09-02T08:26:34.149-07:00" operationName="vappUpdateVm" operation="Updating Virtual Machine DSL tools(60423e4d-b937-4a7f-b73c-cfd5605a590b)" expiryTime="2011-12-01T08:26:34.149-08:00" name="task" id="urn:vcloud:task:5ca2c7f7-7471-42de-a42b-042422b94fd9" type="application/vnd.vmware.vcloud.task+xml" href="https://cloud-test/api/task/5ca2c7f7-7471-42de-a42b-042422b94fd9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://10.147.44.125/api/v1.5/schema/master.xsd">
     <Link rel="task:cancel" href="https://cloud-test/api/task/5ca2c7f7-7471-42de-a42b-042422b94fd9/action/cancel"/>
     <Owner type="application/vnd.vmware.vcloud.vm+xml" name="DSL tools" href="https://cloud-test/api/vApp/vm-60423e4d-b937-4a7f-b73c-cfd5605a590b"/>
     <User type="application/vnd.vmware.admin.user+xml" name="vadmin" href="https://cloud-test/api/admin/user/0b753f88-053b-4850-9bd4-47c6a6f00efa"/>
     <Organization type="application/vnd.vmware.vcloud.org+xml" name="Default" href="https://cloud-test/api/org/3cb7a07b-63b7-40f8-bfbd-4ea2d08c5a64"/>
</Task>

0 Kudos
JoshBonczkowski
Enthusiast
Enthusiast

This process using the REST API does work. I have been testing it this morning with vCloud Director 1.5. Here are a few addendums I found for the notes

Make sure you include all disks for the VM when you post the changes back. Otherwise, the REST API will delete any disk that is not resubmitted.

When modifying the XML response for each disk, remove the 'AddressOnParent', 'Description' and 'Parent' elements.They are not needed and at least one of them causes an exception from the API.

With these small additions to what kirlik provided, I was able to modify the virtual disks for a stopped or running VM within vCD.

0 Kudos
OwainNorth
Contributor
Contributor

Has anyone managed this using the API and .NET SDK? I'm desperately trying to resize a Windows partition on an LSI Logic SAS controller and getting nowhere. Seems a little odd that expanding disks isn't possible.

0 Kudos
JoshBonczkowski
Enthusiast
Enthusiast

I used the Java API to build an application to do this. It should be similar, but you'll have to translate it yourself.

First, I will leave it to you to find a reference to the VM in question. I ended up with an object of type VM.

You can then see all of the attached disks (and controllers) using

List<VirtualDisk> disks = vm.getDisk();

You will need to walk through all of the disks. Keep a list of only the hard disks, not the controllers. Then create a new VirtualHard disk with only the attribute that are needed. When you get to the disk you want to resize, you will need to handle that as well.

List<VirtualDisk> hardDisks = new ArrayList<VirtualDisk>();
for (VirtualDisk disk : vm.getDisks())
            {
                if (disk.isHardDisk())
                {
                    /*
                     * Create a new RASDType for each hard disk. only keep properties that are used for updating disks
                     * You must do this for every disk. Failing to send back a disk, even when it does not
                     * change, will cause the disk to be *removed* if the VM is powered off. It is a failure
                     * if the VM is powered on.
                     */
                    BigInteger size = disk.getHardDiskSize();
                    RASDType diskResourceType = new RASDType();
                    diskResourceType.setElementName(disk.getItemResource().getElementName());
                    diskResourceType.setResourceType(disk.getItemResource().getResourceType());
                    diskResourceType.setInstanceID(disk.getItemResource().getInstanceID());
                    for (int i = 0; i < disk.getItemResource().getHostResource().size(); i++)
                    {
                        CimString resource = disk.getItemResource().getHostResource().get(i);
                        diskResourceType.getHostResource().add(resource);
                        if (disk.getItemResource().getElementName().getValue().equals(diskName))
                        {
                            for (QName key : resource.getOtherAttributes().keySet())
                            {
                                /* This is the section to change the size of the disk. For a simple test, increase by 1GB */
                                if (key.getLocalPart().equals("capacity"))
                                {
                                    BigInteger newSize = size.add(new BigInteger("1024"));
                                    String newSizeValue = newSize.toString();
                                    resource.getOtherAttributes().put(key, newSizeValue);
                                }
                            }
                        }
                    }
                    /* Keep track of the disk so we can call the update method */
                    hardDisks.add(new VirtualDisk(diskResourceType));
                }
            }

Once you have the list of disks, call the update method. This is where the actual change takes place. Tune your waitForTask time values appropriately.

            try             {                 Task task = vm.updateDisks(hardDisks);                 task.waitForTask(1000, 2000);             }             catch (TimeoutException e)             {                 // TODO Auto-generated catch block                 e.printStackTrace();             }

Hopefully this gives you a decent starting point.

0 Kudos
OwainNorth
Contributor
Contributor

Hi Josh

That's fantastic, I'll get cracking with that and report back after some coffee.

O.

0 Kudos
cfor
Expert
Expert

Just a quick note, if using the .NET SDK v1.0 you will have an issue due to a bug in it.  Upgrade to the v1.02 API and getDisks is suppose to be fixed (1.0 throws error when trying to use).

ChrisF (VCP4, VCP5, VCP-Cloud) - If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful
0 Kudos