Deploy a Virtual Machine from a VM Template in a Content Library

By using the
vSphere Automation
APIs, you can deploy a virtual machine from a VM template stored in a content library.
  • Verify that you have administrative privileges on your
    vCenter Server
    instance.
  • Verify that you created a
    vSphere Automation
    session to your
    vCenter Server
    instance.
To deploy a virtual machine from a VM template in a content library,
use the
POST https://<
vcenter_ip_address_or_fqdn
>/api/vcenter/vm-template/library-items/<
vm_template_item_id
>?action=deploy
HTTP request
. You can specify the power state and customize the guest operation system prior to the virtual machine deployment.
For information about the available and mandatory parameters, see the
API Reference
documentation.
  1. Review the information stored in the VM template library item.
    You can use the
    GET https://<
    vcenter_ip_address_or_fqdn
    >/api/vcenter/vm-template/library-items/<
    vm_template_item_id
    >
    HTTP request
    . If you did not save the ID of your item, you can select the UUID of your VM template item by using the
    vSphere Client
    . The URN ends with the ID of the item and has the following format:
    urn:vapi:com.vmware.content.library.Item:<
    VMTemplateItemID
    >
    .
  2. Get the ID of the host on which you want to deploy the virtual machine.
    You can use the
    GET https://<
    vcenter_ip_address_or_fqdn
    >/api/vcenter/host
    HTTP request
    .
  3. Get the ID of the resource pool to which you want to add your virtual machine.
    You can use the
    https://<
    vcenter_ip_address_or_fqdn
    >/api/vcenter/resource-pool
    HTTP request
    .
  4. Get the ID of the
    VIRTUAL_MACHINE
    folder to which you want to add your virtual machine.
    You can use the
    GET https://<
    vcenter_ip_address_or_fqdn
    >/api/vcenter/folder
    HTTP request
    .
  5. Get the ID of the datastore on which you want to store log, configuration, and disk files of the virtual machine.
    You can use the
    GET https://<
    vcenter_ip_address_or_fqdn
    >/api/vcenter/datastore
    HTTP request
    .
  6. Create a deployment specification.
    You can use the
    body of the
    POST https://<
    vcenter_ip_address_or_fqdn
    >/api/vcenter/vm-template/library-items/<
    vm_template_item_id
    >?action=deploy
    HTTP request
    .
    1. Specify a name and description of the virtual machine that you want to deploy.
    2. Specify the place in your inventory on which you want to deploy the virtual machine such as an
      ESXi
      host, resource pool, and VM folder.
      You can use the
      placement
      parameter in the body of the request
      . You must use the IDs of your inventory objects.
    3. Specify the datastore on which you want to store the log, configuration, and disk files of the virtual machine. You must use the ID of the datastore.
      You can use the
      vm_home_storage
      , and
      disk_storage
      parameters in the body of the request
      .
    4. Specify the guest operating system and hardware customization specifications that you want to apply to the virtual machine during the deployment process. Add this information to the deployment specification.
      You can use the
      guest_customization
      and
      hardware_customization
      parameters in the body of the request
      . You can get a list of the guest operating system customization specifications that are available in your
      vCenter Server
      by using the
      GET https://<
      vcenter_ip_address_or_fqdn
      >/api/vcenter/guest/customization-specs
      HTTP request
      .
    5. Include the placement and storage specifications in the deployment specification.
  7. Deploy a virtual machine from your VM template.
    You can use the
    POST https://<
    vcenter_ip_address_or_fqdn
    >/api/vcenter/vm-template/library-items/<
    vm_template_item_id
    >?action=deploy
    HTTP request
    .
If the operation is successful, the ID of the deployed virtual machine is returned. For information about the possible exceptions, see the
API Reference
documentation.