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://knowledge.broadcom.com/external/article?legacyId=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

Additional Information

Also we can migrate a VM without migrating the datastore, In the UI we dont have this option pinToDatastore.

Note: To use this new functionality a new value must be added to the payload (meaning the API must be used) "pinToDatastore":"false", This value defaults to true.

API document only has XML payload but, We can get json payload using Developer tools.

https://developer.broadcom.com/xapis/vmware-cloud-director-api/latest/doc//types/MigrateParamsType.html

[Example]

{
    "vmRef":
    [
        {"href":"https://127.0.0.1:8443/api/vApp/vm-8f0479e4-a34f-4d7a-b174-01e310bed134"}
    ],
    "resourcePoolRef":
    {
        "vimServerRef":
        {
            "otherAttributes":{},
            "href":"https://127.0.0.1:8443/api/admin/extension/vimServer/74992881-bfd6-437b-a60d-705c55826c4c",
            "id":"urn:vcloud:vimserver:74992881-bfd6-437b-a60d-705c55826c4c",
            "type":"application/vnd.vmware.admin.vmwvirtualcenter+xml",
            "name":"vc1","vCloudExtension":[]
        },

        "moRef":"resgroup-40",
        "vimObjectType":"RESOURCE_POOL"
    },
    "pinToDatastore":"false"
}