pyvmomi-community-samples icon indicating copy to clipboard operation
pyvmomi-community-samples copied to clipboard

Editing VM Specs issue with InstantClone()

Open sYera21 opened this issue 2 years ago • 0 comments

Describe the bug

Need help with understanding if it is possible to have 2 Vms in esxi to be exact clones with the same IP address and Mac addr.

I used InstantClone() to create a clone and then tried to edit the clones VirtualEthernetCard.

Though once the method below is run, Vsphere UI shows no change to the clones MacAddr field and or the AddrType field though I set it to 'manual'. It still seems persistent with having it be automatic. Is there anything else that needs to be done, or is it even possible to have exact clones with same hardware configurations?

Reproduction steps

...

Expected behavior

`

def edit_resources(self,si,vm_name=str):

content=si.RetrieveContent()
vm_obj=self.get_obj(content,[vim.VirtualMachine],vm_name)

virtual_nic_spec = vim.vm.device.VirtualDeviceSpec()

for dev in vm_obj.config.hardware.device:
    if isinstance(dev, vim.vm.device.VirtualEthernetCard):	
	    dev.macAddress="00:0c:29:aa:16:2f"
	    virtual_nic_spec.device = dev
	    virtual_nic_spec.device.key = dev.key
	    virtual_nic_spec.device.macAddress = dev.macAddress
	    virtual_nic_spec.device.addressType = vim.vm.device.VirtualEthernetCardOption.MacTypes.manual
	    virtual_nic_spec.device.backing = dev.backing
	    virtual_nic_spec.device.wakeOnLanEnabled = dev.wakeOnLanEnabled
	    print(virtual_nic_spec)
	    dev_changes = []
	    dev_changes.append(virtual_nic_spec)
	    reconfig_spec = vim.vm.ConfigSpec()
	    reconfig_spec.deviceChange = dev_changes
	    #update the task manager (i.e. Make the update)
	    task = vm_obj.ReconfigVM_Task(spec=reconfig_spec)
	    tasks.wait_for_tasks(si, [task])

`

Additional context

No response

sYera21 avatar Oct 11 '23 16:10 sYera21