vcloud-director-rest-api

How to change disk storage profile with vCloud API


I'm trying to change disk storage profile of one VM in the vCloud. I've found this link. I use the following xml document as the body of my REST request

<?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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" href="https://192.168.141.100/api/vAppTemplate/vm-4ec8cce7-0b48-483c-ac0c-14ff39d0aa7c/virtualHardwareSection/disks" type="application/vnd.vmware.vcloud.rasdItemsList+xml" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://192.168.141.100/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" href="https://192.168.141.100/api/vAppTemplate/vm-4ec8cce7-0b48-483c-ac0c-14ff39d0aa7c/virtualHardwareSection/disks" type="application/vnd.vmware.vcloud.rasdItemsList+xml"/>
    <Item>
        <rasd:Address>0</rasd:Address>
        <rasd:Description>SCSI Controller</rasd:Description>
        <rasd:ElementName>SCSI Controller 0</rasd:ElementName>
        <rasd:InstanceID>2</rasd:InstanceID>
        <rasd:ResourceSubType>lsilogic</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="10240"
         vcloud:busSubType="lsilogic"
         vcloud:busType="6"
         vcloud:storageProfileOverrideVmDefault="true"
         vcloud:storageProfileHref="https://192.168.141.100/api/vdcStorageProfile/3235c8c2-7489-4e32-b73c-cd8a9d10c4e4">
      </rasd:HostResource>
      <rasd:InstanceID>2000</rasd:InstanceID>
      <rasd:Parent>2</rasd:Parent>
      <rasd:ResourceType>17</rasd:ResourceType>
   </Item>
    <Item>
        <rasd:AddressOnParent>1</rasd:AddressOnParent>
        <rasd:Description>Hard disk</rasd:Description>
        <rasd:ElementName>Hard disk 2</rasd:ElementName>
        <rasd:HostResource xmlns:vcloud="http://www.vmware.com/vcloud/v1.5" vcloud:capacity="1024" vcloud:busSubType="lsilogic" vcloud:busType="6"/>
        <rasd:InstanceID>2001</rasd:InstanceID>
        <rasd:Parent>2</rasd:Parent>
        <rasd:ResourceType>17</rasd:ResourceType>
    </Item>
    <Item>
        <rasd:Address>0</rasd:Address>
        <rasd:Description>IDE Controller</rasd:Description>
        <rasd:ElementName>IDE Controller 0</rasd:ElementName>
        <rasd:InstanceID>3</rasd:InstanceID>
        <rasd:ResourceType>5</rasd:ResourceType>
    </Item>
</RasdItemsList>

For some reason after reconfiguration task is completed I see no changes for the storage profile section

PS C:\Windows\system32> $vmdisks.RasdItemsList.Item[1].HostResource

vcloud                            capacity busSubType busType
------                            -------- ---------- -------
http://www.vmware.com/vcloud/v1.5 10240    lsilogic   6      



PS C:\Windows\system32> $vmdisks.RasdItemsList.Item[2].HostResource

vcloud                            capacity busSubType busType
------                            -------- ---------- -------
http://www.vmware.com/vcloud/v1.5 1024     lsilogic   6 

The interesting thing is re-configuring of disk size runs successfully. Looks like reconfiguration task skips storage profile changes. Can anyone advice me on this matter?

I've double checked fast provisioning in my organisational vDC and it is off.


Solution

  • What you're looking for is on line 27: ProviderVdcStorageProfile I'm using PowerShell to post the XML document that I build in Notepad++, based on the document linked below. The link has a rel of edit, a content-type of orgVdc+xml and the href will be your vdc ID.

    <?xml version="1.0" encoding="UTF-8"?>
    <CreateVdcParams name="{0}" xmlns="http://www.vmware.com/vcloud/v1.5">
      <Description>API VDC</Description>
      <AllocationModel>AllocationVApp</AllocationModel>
      <ComputeCapacity>
        <Cpu>
          <Units>MHz</Units>
          <Allocated>3000</Allocated>
          <Limit>0</Limit>
        </Cpu>
        <Memory>
          <Units>MB</Units>
          <Allocated>0</Allocated>
          <Limit>0</Limit>
        </Memory>
      </ComputeCapacity>
      <NicQuota>0</NicQuota>
      <NetworkQuota>10</NetworkQuota>
      <VdcStorageProfile>
        <Enabled>true</Enabled>
        <Units>MB</Units>
        <Limit>0</Limit>
        <Default>true</Default>
        <ProviderVdcStorageProfile
          href="https://vcloud.example.com/api/admin/pvdcStorageProfile/0b6fe60b-e70b-4529-bbaa-fd82ff59125f" />
      </VdcStorageProfile>
      <ResourceGuaranteedMemory>0.01</ResourceGuaranteedMemory>
      <ResourceGuaranteedCpu>0.01</ResourceGuaranteedCpu>
      <VCpuInMhz>3000</VCpuInMhz>
      <IsThinProvision>true</IsThinProvision>
      <NetworkPoolReference
        href="https://vcloud.example.com/api/admin/extension/externalnet/4444"/>
      <ProviderVdcReference
        name="Provider1"
        href="https://vcloud.example.com/api/admin/extension/providervdc/242424" />
      <UsesFastProvisioning>true</UsesFastProvisioning>
    </CreateVdcParams>