克隆虚拟机xxx指定的参数不正确。 spec.identity自定义新的虚拟机

时间:2015-06-11 20:01:58

标签: esxi pyvmomi

当我尝试运行以下代码时出现以下错误:

“克隆虚拟机xxx指定的参数不正确。规范身份”

当我在没有customSpecs的情况下运行时,一切正常。

不确定为什么它不喜欢“身份”属性

-----------------------------------------------------------


    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)

1 个答案:

答案 0 :(得分:0)

这是因为域名不正确 - ident.domain =' helion.cg'