pyvmomi-community-samples
pyvmomi-community-samples copied to clipboard
Help wanted with InstantClone
Describe the bug
I am using instantClone, and I am able to spin up the clone, but am unable to adapt any of the option values, in this case they are changes to the hardware of the Instant Clone. I read that the hardware is set by the GuestOS and so I have tired to use this page https://vdc-repo.vmware.com/vmwb-repository/dcr-public/723e7f8b-4f21-448b-a830-5f22fd931b01/5a8257bd-7f41-4423-9a73-03307535bd42/doc/vim.vm.GuestInfo.html to attempt it, but i'm having issues. Currently my code looks as follows:
Option Values that are passed in: {"config.hardware.numCPUs":10,"config.hardware.memoryMB":1000,"guestinfo.nicinfo.macAddress":"00:50:56:a6:e2:9j","guestinfo.ipAddress":"192.168.0.90"}
Option Values method: `def dict_to_optionvalues(self,guestinfo_vars): """ Transform Dictionary to Optional Values type to be passed to InstantClone Config
Args:
guestinfo_vars (dict): dictionary of values we are trying to edit
Returns:
optionvalues(OptionValue: formated list of type Option Value
"""
optionvalues = []
for k, v in guestinfo_vars.items():
opt = vim.option.OptionValue()
(opt.key, opt.value) = (k, v)
optionvalues.append(opt)
return optionvalues`
Instant Clone method: `def instant_clone_vm(self,content,parent_vm_name,vm_name,optionalvalues): """ Instant Clones a VM
Args:
content (Content): Data Stream from the ServiceInstance
parent_vm_name (string): Name of the Host/Parent VM
vm_name (string): Name of Cloned VM
optionalvalues (dict): optional values in key value pair form
"""
#Gets the Host VM Object
parent_vm=self.get_obj(content,[vim.VirtualMachine],parent_vm_name)
#Formats the optional values to type (OptionalValue) from dict
opt=self.dict_to_optionvalues(optionalvalues)
#Used to setup where the clone will be relocated to
vm_relocate_spec=vim.vm.RelocateSpec()
vm_relocate_spec.datastore=self.get_obj(content,[vim.Datastore],"DataCenter")
#Used to describe the given clone specifications
instant_clone_spec=vim.vm.InstantCloneSpec()
instant_clone_spec.name=vm_name
instant_clone_spec.location=vm_relocate_spec
instant_clone_spec.config=opt
#Creates the instant clone task for the Host VM
parent_vm.InstantClone_Task(spec=instant_clone_spec)
#Waits for the Instant Cloning to Occur
WaitForTask(parent_vm.InstantClone_Task(spec=instant_clone_spec))`
Reproduction steps
... Use a ESXI 8 setup
Expected behavior
The VM is expected to have the hardware changes written above
Additional context
Any advice is helpful