A Vm element, whether part of a Vapp or VappTemplate element, includes an action/relocate link that you can use to move the virtual machine to a different datastore.

Note

Beginning with this release of the vCloud API, the action/relocate operation in a Vm is deprecated. If the datastore that contains a virtual machine has been disabled by the system administrator or is no longer associated with virtual machine's designated storage profile, you must update the Vm element that represents the virtual machine. That update revalidates the storage profile and relocates the virtual machine if necessary. See Update the Storage Profile for a Virtual Machine.

In both vApps and vApp templates, virtual machines are defined by a combination of metadata in the vCloud Director database and virtual disk files stored on a datastore in the cloud. vCloud Director determines the initial location of this datastore based on how the virtual machine was created. You can move the disk files to another datastore in the cloud by POSTing a RelocateParams element to the virtual machine's action/relocate link.

When a virtual machine is deployed in a vDC that supports fast provisioning, its disks can become part of a tree structure that includes parent and child disks. Disk tree structure and total storage consumption remain the same regardless of the order in which virtual machines are relocated The folder structure in the target datastore might change depending on the order in which virtual machines are relocated.

Verify that you are logged in to the vCloud API as a system administrator.

1

List the datastores available in the cloud.

Use a request like this one.

GET https://vcloud.example.com/api/admin/extension/datastores

The response is a DatastoreReferences element, as shown here:.

<vmext:DatastoreReferences
   xmlns:vmext="http://www.vmware.com/vcloud/extension/v1.5"
   xmlns:vcloud="http://www.vmware.com/vcloud/v1.5"
   type="application/vnd.vmware.admin.datastoreList+xml"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://vcloud.example.com/api/v1.5/schema/master.xsd">
   <vcloud:Link
      rel="up"
      type="application/vnd.vmware.admin.vmwExtension+xml"
      href="https://vcloud.example.com/api/admin/extension" />
   <vcloud:Reference
      type="application/vnd.vmware.admin.datastore+xml"
      name="example-lun2"
      href="https://vcloud.example.com/api/admin/extension/datastore/607" />
   <vcloud:Reference
      type="application/vnd.vmware.admin.datastore+xml"
      name="example-lun4"
      href="https://vcloud.example.com/api/admin/extension/datastore/191" />
 </vmext:DatastoreReferences>
2

Retrieve the representation of the virtual machine.

The following request retrieves a Vm from a Vapp:

GET https://vcloud.example.com/api/vApp/vm-257
3

Find the action/relocate link for the Vm, and note the datastore that the Vm currently occupies.

This fragment of the response to the request made in Step 2 includes the action/relocate link and the reference to the datastore that the Vm currently occupies.

<Vm
   xmlns="http://www.vmware.com/vcloud/v1.5"
   ... >
   <VCloudExtension
      required="false">
   ...
       <vmext:VimObjectRef>
         <vmext:VimServerRef
            type="application/vnd.vmware.admin.vmwvirtualcenter+xml"
            name="VC1"
            href="https://vcloud.example.com/api/admin/extension/vimServer/35" />
         <vmext:MoRef>datastore-191</vmext:MoRef>
         <vmext:VimObjectType>DATASTORE</vmext:VimObjectType>
      </vmext:VimObjectRef>
   </VCloudExtension>
   ...
   <Link
      rel="relocate"
      type="application/vnd.vmware.vcloud.relocateVmParams+xml"
      href="https://vcloud.example.com/api/vApp/vm-257/action/relocate" />
   ...
</Vm>
4

Construct a RelocateParams element that specifies the destination datastore for the Vm.

See Example: Relocate a Virtual Machine.

5

POST the RelocateParams element to the action/relocate link described in Step 3.

You do not need to power off the virtual machine before you make the request. See Example: Relocate a Virtual Machine.

The system creates a task to manage the relocation and returns a Task element in the response. When the task is complete, the virtual machine is relocated.

This request relocates the virtual machine retrieved in Step 2 to one of the datastores listed in Step 1. The response is a Task.

Request:

POST https://vcloud.example.com/api/vApp/vm-257/action/relocate
Content-Type: application/vnd.vmware.vcloud.relocateVmParams+xml
...
<?xml version="1.0" encoding="UTF-8"?>
<RelocateParams
   xmlns="http://www.vmware.com/vcloud/v1.5">
   <Datastore
      href="https://vcloud.example.com/api/admin/extension/datastore/607" />
</RelocateParams>