Deploy a Virtual Machine from a VM Template Library Item

By using the API or HTTP requests, you can deploy a virtual machine from a VM Template stored as an item in your local content library.

You can use the com.vmware.vcenter.vm_template_client.LibraryItems class or the POST https://<vCenter_Server_IP>/rest/vcenter/vm-template/library-items/<VM_Template_Item_ID>?action=deploy HTTP request .

For information about the available and mandatory parameters, see the API Reference documentation.

Prerequisites

  • Verify that you have administrative privileges on your vCenter Server instance.
  • Verify that you created a vAPI session to your vCenter Server.

Procedure

  1. Review the information stored in the VM Template library item.
    You can use the com.vmware.vcenter.vm_template_client.LibraryItems.get(VM_template_item_ID) method and pass the ID of your VM Template item or the GET https://<vCenter_Server_IP>/rest/vcenter/vm-template/library-items/<VM_Template_Item_ID> HTTP request. If you did not save the ID of your item, you can check 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 ESXi host on which you want to deploy the VM.
    You can use the com.vmware.vcenter_client.Host.list() method or the GET https://<vCenter_Server_IP>/rest/vcenter/host HTTP request.
  3. Get the ID of the resource pool to which you want to add your VM.
    You can use the com.vmware.vcenter_client.ResourcePool.list() class or the https://<vCenter_Server_IP>/rest/vcenter/resource-pool HTTP request.
  4. Get the ID of the VIRTUAL_MACHINE folder to which you want to add your VM.
    You can use the com.vmware.vcenter_client.Folder.list() method or the GET https://<vCenter_Server_IP>/rest/vcenter/folder HTTP request.
  5. Get the ID of the datastore on which you want to store log, configuration, and disk files of the VM.
    You can use the com.vmware.vcenter_client.Datastore.list() method or the GET https://<vCenter_Server_IP>/rest/vcenter/datastore HTTP request.
  6. Create a deployment specification.
    You can use the com.vmware.vcenter.vm_template_client.LibraryItems.DeploySpec class or the body of the POST https://<vCenter_Server_IP>/rest/vcenter/vm-template/library-items/<VM_Template_Item_ID>?action=deploy HTTP request.
    1. Specify a name and description of the VM that you want to deploy.
    2. Specify the place in your inventory on which you want to deploy the VM such as an ESXi host, resource pool, and VM folder.
      You can use the com.vmware.vcenter.vm_template_client.LibraryItems.DeployPlacementSpec class or 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 VM. You must use the ID of the datastore.
      You can use the DeploySpecVmHomeStorage, DeploySpecDiskStorage classes or the vm_home_storage, and disk_storage parameters in the body of the request.
    4. (Optional) Specify the guest operating system and hardware customization specifications that you want to apply to the VM during the deployment process and include them in the deployment specification.
      You can use the GuestCustomizationSpec and HardwareCustomizationSpec classes or 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 com.vmware.vcenter.guest_client.CustomizationSpecs.list() method or the GET https://<vCenter_Server_IP>/rest/vcenter/guest/customization-specs HTTP request.
    5. Include the placement and storage specifications in the deployment specification.
  7. Deploy a VM from your VM Template library item.
    You can use the com.vmware.vcenter.vm_template_client.LibraryItems.deploy(template_library_item, spec) method by passing the VM Template library item ID and the deployment specification or by sending the POST https://<vCenter_Server_IP>/rest/vcenter/vm-template/library-items/<VM_Template_Item_ID>?action=deploy request.

Results

If the operation is successful, the API returns the ID of the deployed VM. For information about the available responses, see the API Reference documentation.