Create a VM Template in a Content Library
from a Virtual Machine
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.- Verify that you have administrative privileges on yourvCenter Serverinstance.
- Verify that you created avSphere Automationsession to yourvCenter Server.
- Verify that you created a local library by using thevSphere Clientor thevSphere AutomationAPIs.
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 . You can review the information about a VM template by using
the . For
information about how to create a VM template by using the
POST https://<
HTTP requestvcenter_ip_address_or_fqdn
>/api/vcenter/vm-template/library-itemsGET
https://<
HTTP requestvcenter_ip_address_or_fqdn
>/api/vcenter/vm-template/library-items/<vm_template_item_id
>vSphere Client
, see the vSphere Virtual Machine Administration
documentation. For information about the
available and mandatory parameters, see the
API Reference
documentation.
- Get the ID of yourESXihost on which you want to store the VM template.You can use the.GET https://<HTTP requestvcenter_ip_address_or_fqdn>/api/vcenter/host
- Get the ID of the datastore on which you want to store the VM template files.You can use the.GET https://<HTTP requestvcenter_ip_address_or_fqdn>/api/vcenter/datastore
- Get the ID of the virtual machine that you want to save as a VM template.You can use the.GET https://<HTTP requestvcenter_ip_address_or_fqdn>/api/vcenter/vm
- Get the ID of your local library.You can get the list of the local libraries in yourvCenter Serverand review the information about each library by using the.GET https://<andvcenter_ip_address_or_fqdn>/api/com/vmware/content/local-libraryGET https://<HTTP requestsvcenter_ip_address_or_fqdn>/api/com/vmware/content/library/id:<library_id>
- Create a library item specification for the VM template.You can use thebody of the.POST https://<HTTP requestvcenter_ip_address_or_fqdn>/api/vcenter/vm-template/library-items
- Specify the local library, source virtual machine, and the name of the library item by using thelibrary,source_vm, andnameparameters. You must use the IDs of the local library and source virtual machine.
- Specify the placement information for your VM template.You can use the. To specify the host, resource pool, cluster, and folder, you must use their IDs.placementparameters in the body of the HTTP request
- Specify the datastore on which you want to store the log, configuration, and disk files of your VM template.To specify the storage backing for the VM template, you can use the. You must use the ID of the datastore.vm_home_storageanddisk_storageparameters in the body of the HTTP request
- Include the placement and storage specifications in the library item specification.
- Create a library item for storing the VM template.You can use the.POST https://<HTTP requestvcenter_ip_address_or_fqdn>/api/vcenter/vm-template/library-items
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. - Review the information stored in the library item by using the. If you did not save the ID of the library item holding the VM template, you can check the UUID by using theGET https://<HTTP requestvcenter_ip_address_or_fqdn>/api/vcenter/vm-template/library-items/<library_item_id>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>