Reputation: 109
I was looking at a solution to convert a VMware vsphere VM to a template using any of Ansible modules and failed as it seems vmware_guest
(using pyvmomi) failed to to that.
So, I started investigating the alternatives; it seems the direct pyvmomi
python script can send the API towards vCenter and it will do the task - though I haven't found any of examples, unfortunately.
I have read the VMware API documentation It states that the VirtualMachineConfigSpec
should be used as well as:
"A virtual machine template is a virtual machine that cannot be powered on and that is not associated with a resource pool. You can convert any powered off virtual machine to a template by calling VirtualMachine.MarkAsTemplate. After the conversion, the original virtual machine no longer exists."
Can I ask anyone to help me develop a very basic script that connects to vCenter, finds the given VM and converts it to template?
Upvotes: 0
Views: 2942
Reputation: 6329
First download and execute some of the samples found in the pyvmomi-community-samples (preferably in a python virtual environment).
Then use any sample which retrieves a vim.VirtualMachine
object (e.g. add_disk_to_vm.py), and after the vm
object is retrieved, call vm.MarkAsTemplate()
.
Upvotes: 2