VMware Cloud Community
Mehrdadkohen
Contributor
Contributor

Deploy vm template with API

Hi everyone
I use vcenter 7u3
I am going to create a virtual machine with a template through api.
I can see the correct output when I use the following command.
https://{api_host}/api/vcenter/vm-template/library-items/{template_library_item}

But when I want to deploy the vm with the following command, I get an error.
https://{api_host}/api/vcenter/vm-template/library-items/{template_library_item}?action=deploy
I don't know exactly what concepts I should put in BODY

{
"name": "string",
"placement": {
"folder": "string"
}
}

For NAME, I put a desired name, and for FOLDER, I created a folder in the VM AND TEMPLATE section, but I still have the following error in the output.

{
"error_type": "INVALID_REQUEST",
"messages": [
{
"args": [],
"default_message": "Unsupported media type.",
"id": "com.vmware.vapi.rest.unsupportedMediaType"
}
]
}

What points should be paid attention to for these options?
What is the correct string for name & palcement?

what am i doing wrong

thanks 

Labels (1)
0 Kudos
1 Reply
lamw
Community Manager
Community Manager

You'll need to fill out the placement spec, which specifies the compute for the VM Template to be deployed.

At a minimum, you'll need to specify folder, host or cluster or resource pool (depending on your vSphere setup)

"placement": {
   "cluster": "string",
   "folder": "string",
   "host": "string",
   "resource_pool": "string"
}

The values are the Managed Object References, not the name of the inventory items. You can use https://developer.vmware.com/apis/vsphere-automation/latest/vcenter/vcenter/ to retrieve the desired resources and get their IDs. 

If you're familiar w/PowerCLI, I've demonstrated the use of the VM Template API over on my blog https://williamlam.com/2018/07/automating-vm-template-management-using-content-library-in-vmc.html which you can use as a reference

 

0 Kudos