Use the disk/action/attach or disk/action/detach links in a Vm to attach or detach an independent disk. You must be the owner of the Vm object and the disk.

Every Vm element includes links of the following form:
<Link
   rel="disk:attach"
   type="application/vnd.vmware.vcloud.diskAttachOrDetachParams+xml"
   href="https://vcloud.example.com/api/vApp/vm-4/disk/action/attach" />
<Link
   rel="disk:detach"
   type="application/vnd.vmware.vcloud.diskAttachOrDetachParams+xml"
   href="https://vcloud.example.com/api/vApp/vm-4/disk/action/detach" />
You can POST a DiskAttachOrDetachParams element to one of these URLs to attach or detach an independent disk.
Note: An independent disk can be attached to at most one virtual machine.

Prerequisites

  • Verify that you are logged in to the VMware Cloud Director API as an administrator or the object owner. Verify that you are logged in to the vCloud Air Compute Service as a Virtual Infrastructure Administrator or the End User who owns this object.

  • Verify that the VDC contains an independent disk. If the VDC does not contain independent disks, you can create one. See Create an Independent Disk.

Procedure

  1. Retrieve a reference to the independent disk to attach to a virtual machine.
    The independent disk and the virtual machine must be contained by the same VDC. You can retrieve references to independent disks in a VDC in the following ways:
    • Use the query service. A query like this one returns references to all Disk objects in the VDC named MyVdc.
      GET https://vcloud.example.com/api/query?type=disk&format=references&filter=vdcName==MyVdc
    • Retrieve the VDC and look for ResourceEntity elements whose type attribute has a value of application/vnd.vmware.vcloud.disk+xml. The href value of a ResourceEntity that represents a disk is a reference to that Disk object.
  2. Verify that the independent disk is not connected to any virtual machine.
  3. Create a DiskAttachOrDetachParams element.
    Provide a reference to the independent disk in the href attribute of the Disk element.
  4. POST the DiskAttachOrDetachParams to the disk/action/attach link of the Vm.

Example: Attach an Independent Disk to a Virtual Machine

This request attaches the disk created in Create an Independent Disk to a virtual machine.

Request:
POST https://vcloud.example.com/api/vApp/vm-4/disk/action/attach
Content-Type: application/vnd.vmware.vcloud.diskAttachOrDetachParams+xml
...
<?xml version="1.0" encoding="UTF-8"?>
<DiskAttachOrDetachParams
   xmlns="http://www.vmware.com/vcloud/v1.5">
   <Disk
      type="application/vnd.vmware.vcloud.disk+xml"
      href="https://vcloud.example.com/api/disk/128" />
</DiskAttachOrDetachParams>

The response is a Task.

Response:
<Task
   href="https://vcloud.example.com/api/task/57"
   ...
   status="running"
   operationName="vappAttachDisk"
   ... />
   ...    
</Task>