By using the vSphere Automation REST API, you can create a VM template in a content library from an existing virtual machine in your vCenter Server inventory.
When you call the create function of the com.vmware.vcenter.vm_template.LibraryItems service, a VM template is created as a library item in your local content library. If the operation is successful, the LibraryItems service returns the ID of the newly created library item.
To create a library item that contains a VM template, you can use the POST https://<vcenter_ip_address_or_fqdn>/api/vcenter/vm-template/library-items
HTTP request. You can review the information about a VM template by using the GET https://<vcenter_ip_address_or_fqdn>/api/vcenter/vm-template/library-items/<vm_template_item_id>
HTTP request. For information about how to create a VM template by using the vSphere Client, see the vSphere Virtual Machine Administration documentation.
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.
- Verify that you created a local library by using the vSphere Client or the vSphere Automation APIs.
Procedure
Results
If the operation is successful, the LibraryItems service returns the ID of the library item that contains the VM template. For information about the available responses, see the API Reference documentation.
What to do next
- Review the information stored in the library item by using the
GET https://<vcenter_ip_address_or_fqdn>/api/vcenter/vm-template/library-items/<library_item_id>
HTTP request. If you did not save the ID of the library item holding the VM template, you can check the UUID by using the vSphere Client. The URN ends with the ID of the library item and has the following format:urn:vapi:com.vmware.content.library.Item:<VMTemplateItemID>
.