By using the vSphere
Automation APIs, you can deploy a virtual machine
from a VM template stored in a content library.
To deploy a virtual machine from a VM template in a
content library, call the deploy function of the com.vmware.vcenter.vm_template.LibraryItems interface or use the
POST https://<vCenter_Server_IP>/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.
Prerequisites
- Verify that you have administrative
privileges on your vCenter Server instance.
- Verify that you created a vSphere
Automation session to your vCenter Server instance.
Procedure
-
Review the information stored in
the VM template library item.
You can use the
get(VM_template_item_ID) function of the com.vmware.vcenter.vm_template.LibraryItems interface and pass
the ID of your VM template item or the GET https://<vCenter_Server_IP>/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>
.
-
Get the ID of the host on which you
want to deploy the virtual machine.
You can use the list
function of the com.vmware.vcenter.Host interface or the GET
https://<vCenter_Server_IP>/api/vcenter/host
HTTP request.
-
Get the ID of the resource pool to
which you want to add your virtual machine.
You can use the list
function of the com.vmware.vcenter.ResourcePool interface or the
https://<vCenter_Server_IP>/api/vcenter/resource-pool
HTTP
request.
-
Get the ID of the VIRTUAL_MACHINE
folder to which you want to add your virtual machine.
You can use the list
function of the com.vmware.vcenter.Folder interface or the GET
https://<vCenter_Server_IP>/api/vcenter/folder
HTTP
request.
-
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 list
function of the com.vmware.vcenter.Datastore interface or the GET
https://<vCenter_Server_IP>/api/vcenter/datastore
HTTP
request.
-
Create a deployment specification.
You can use the com.vmware.vcenter.vm_template.LibraryItems.DeploySpec class or
the body of the POST https://<vCenter_Server_IP>/api/vcenter/vm-template/library-items/<VM_Template_Item_ID>?action=deploy
HTTP request.
-
Specify a name and
description of the virtual machine that you want to deploy.
-
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 com.vmware.vcenter.vm_template.LibraryItems.DeployPlacementSpec
class or the placement parameter in the body of the request. You must
use the IDs of your inventory objects.
-
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 DeploySpecVmHomeStorage and DeploySpecDiskStorage classes or the vm_home_storage, and disk_storage
parameters in the body of the request.
- (Optional)
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 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 list
function of the com.vmware.vcenter.guest.CustomizationSpecs interface or
the GET https://<vCenter_Server_IP>/api/vcenter/guest/customization-specs
HTTP request.
-
Include the placement and
storage specifications in the deployment specification.
-
Deploy a virtual machine from your
VM template.
You can use the
deploy(template_library_item, spec) function of the
com.vmware.vcenter.vm_template.LibraryItems interface by passing
the library item ID where the VM template is stores and the deployment
specification. You can also send the POST https://<vCenter_Server_IP>/api/vcenter/vm-template/library-items/<VM_Template_Item_ID>?action=deploy
HTTP request.
Results
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.