克隆虚拟机 xxx 指定的参数不正确。 spec.identity 自定义新虚拟机
Clone virtual machine xxx A specified parameter was not correct. spec.identity Customizing the new Virtual Machine
当我尝试 运行 以下代码时出现以下错误:
"Clone virtual machine xxx A specified parameter was not correct. spec.identity Customizing the new Virtual Machine"
当我 运行 它没有 customSpecs 时一切正常。
不确定为什么它不喜欢 "identity" 属性
-----------------------------------------------------------
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)
这是因为域名不正确 - ident.domain = 'helion.cg'
当我尝试 运行 以下代码时出现以下错误:
"Clone virtual machine xxx A specified parameter was not correct. spec.identity Customizing the new Virtual Machine"
当我 运行 它没有 customSpecs 时一切正常。
不确定为什么它不喜欢 "identity" 属性
-----------------------------------------------------------
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)
这是因为域名不正确 - ident.domain = 'helion.cg'