如何使用vCloud API更改磁盘存储配置文件

时间:2016-08-31 16:13:34

标签: vcloud-director-rest-api

我试图更改vCloud中某个虚拟机的磁盘存储配置文件。我发现了link。我使用以下xml文档作为REST请求的正文

<?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>

由于某些原因,重新配置任务完成后,我看不到存储配置文件部分的更改

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 

有趣的是重新配置磁盘大小成功运行。看起来重新配置任务会跳过存储配置文件更改。任何人都可以就此事向我提出建议吗?

我已经在我的组织vDC中检查了快速配置并且已关闭。

1 个答案:

答案 0 :(得分:2)

您正在寻找的是第27行:ProviderVdcStorageProfile 我使用PowerShell发布我在Notepad ++中构建的XML文档,基于下面链接的文档。该链接具有rel编辑功能,内容类型为orgVdc + xml,href将是您的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>