Need to move virtual machines between resource pools in a Provider vDC
search cancel

Need to move virtual machines between resource pools in a Provider vDC

book

Article ID: 322119

calendar_today

Updated On:

Products

VMware Cloud Director

Issue/Introduction

Provide examples of using the API to move virtual machines between resource pools

Resolution

Note: please be aware that the ability to do this via the UI was added as a feature in vCloud Director version 10.3.

Workaround:
1. Get Authenticated:
https://kb.vmware.com/s/article/56948

2. Use the API to list out the provider vDCs
https://vcloud.example.com/api/admin/extension/providerVdcReferences/query

Sample response information:
    <VMWProviderVdcRecord cpuAllocationMhz="xxxxxx" cpuLimitMhz="xxxxx" cpuUsedMhz="xxxx" isBusy="false" isDeleted="false" isEnabled="true" memoryAllocationMB="xxxx" memoryLimitMB="xxxx" memoryUsedMB="xxxxx" name="Merge" numberOfDatastores="x" numberOfResourcePools="x" numberOfStorageProfiles="xx" numberOfVdcs="x" status="READY" storageAllocationMB="xxxx" storageLimitMB="xxxxx" storageUsedMB="xxxxx" href="https://vcloud.example.com/api/admin/providervdc/<PROVIDER_VDC_UUID>"
.../>

3. Using the provider ID from above to list the resource pools:
https://vcloud.example.com/api/admin/extension/providervdc/<PROVIDER_VDC_UUID>/resourcePools

Sample response information:
        <Link rel="migrateVms" href="https://vcloud.example.com/api/admin/extension/resourcePool/<RESOURCE_POOL_UUID>/action/migrateVms"/>

4: Using the resource pool ID found in Step 3, list the virtual machines:
https://vcloud.example.com/api/admin/extension/resourcePool/<RESOURCE_POOL_UUID>/vmList?show=all&pageSize=xxx

Sample response information:
    <ResourcePoolVMRecord containerName="TestMovevApp" guestOs="Other 3.x Linux (32-bit)" hardwareVersion="11" isBusy="false" isDeployed="true" name="TestMoveVM" status="POWERED_ON" href="https://vcloud.example.com/api/vApp/vm-<VIRTUAL_MACHINE_UUID>" taskStatusName="vappDeploy" task="https://vcloud.example.com/api/task/<TASK_UUID>" taskStatus="success" taskDetails=" "/>

5: Put everything together in a POST statement:
https://vcloud.example.com/api/admin/extension/resourcePool/<RESOURCE_POOL_UUID>/action/migrateVms

Add a Content-Type header:
application/vnd.vmware.admin.migrateVmParams+xml

Body:
<MigrateParams xmlns = "http://www.xxxxxxxx/vcloud/extension/v1.5" xmlns:vcloud_v1.5 = "http://www.xxxxxxxx/vcloud/v1.5" >
     <VmRef href = "https://vcloud.example.com/api/vApp/vm-<VIRTUAL_MACHINE_UUID>" />
     <ResourcePoolRef>
         <VimServerRef href = "https://vcloud.example.com/api/admin/extension/vimServer/<VCENTER_UUID>" type="appliance/vnd.xxxxxx.admin.vmwvirtualcenter+xml" />
         <MoRef>resgroup-xx</MoRef >
         <VimObjectType>RESOURCE_POOL</VimObjectType>
     </ResourcePoolRef>
</MigrateParams>

Note:
This section is from step 4 :
https://vcloud.example.com/api/vApp/vm-<VIRTUAL_MACHINE_UUID>  

This section is from step 3
https://vcloud.example.com/api/admin/extension/vimServer/<VCENTER_UUID>       

This resource pool is found during step 3
resgroup-xx                        

NOTE: You can add multiple VmRef records to the same request