I get the following error when I try to run the below code:
"Clone virtual machine xxx A specified parameter was not correct. spec.identity Customizing the new Virtual Machine"
When I run it without customSpecs everything works fine.
Not sure why its not liking the "identity" attribute
-----------------------------------------------------------
from pyVmomi import vim
from pyVim.connect import SmartConnect, Disconnect
import getpass
import vmutils
si = None
try:
si = SmartConnect(host="10.200.216.211", user="root", pwd="vmware", port=443)
except IOError, e:
pass
# Finding source VM
newvm = 'compute-proxy-111'
template_vm = vmutils.get_vm_by_name(si, 'CP')
# cpu/ram changes
#mem = 512 * 1024 # convert to GB
mem = 512 # MB
vmconf = vim.vm.ConfigSpec(numCPUs=1, memoryMB=mem)
#vmconf.deviceChange = devices
# Network adapter settings
adaptermap = vim.vm.customization.AdapterMapping()
adaptermap.adapter = vim.vm.customization.IPSettings()
adaptermap.adapter.ip = vim.vm.customization.FixedIp()
adaptermap.adapter.ip.ipAddress = str('10.200.216.216')
adaptermap.adapter.subnetMask = str('255.255.255.0')
adaptermap.adapter.gateway = str('10.200.216.1')
# IP
globalip = vim.vm.customization.GlobalIPSettings(dnsServerList=['10.1.64.20'])
# Hostname settings
ident = vim.vm.customization.LinuxPrep()
ident.domain = 'helion.cg'
ident.hostName = vim.vm.customization.FixedName()
ident.hostName.name = newvm
# Putting all these pieces together in a custom spec
customspec = vim.vm.customization.Specification(nicSettingMap=[adaptermap], globalIPSettings=globalip, identity=ident)
# Creating relocate spec and clone spec
resource_pool = vmutils.get_resource_pool(si, 'DEV')
relocateSpec = vim.vm.RelocateSpec(pool=resource_pool)
cloneSpec = vim.vm.CloneSpec(powerOn=True, template=False, location=relocateSpec, customization=customspec , config=vmconf)
# Creating clone task
clone = template_vm.Clone(name=newvm, folder=template_vm.parent, spec=cloneSpec)
# close out connection
Disconnect(si)
This was due to incorrect domain in - ident.domain = 'helion.cg'