pyvmomi
pyvmomi copied to clipboard
how to customization network when I create a new windows machine by clone from template.
when i crate vm by templeate, if templete is Linux, the network can work, but windows templeate can't work . how to customization network when I create a new windows machine by clone from template.
below is my codes: ` def get_customspec(self, vm_ip=None, vm_subnetmask=None, vm_gateway=None, vm_dns=None, vm_hostname=None,template=None): # guest NIC settings adaptermaps = [] guest_map = vim.vm.customization.AdapterMapping() guest_map.adapter = vim.vm.customization.IPSettings() guest_map.adapter.ip = vim.vm.customization.FixedIp() guest_map.adapter.ip.ipAddress = vm_ip guest_map.adapter.subnetMask = vm_subnetmask guest_map.adapter.gateway = vm_gateway adaptermaps.append(guest_map)
# DNS settings
globalip = vim.vm.customization.GlobalIPSettings(dnsServerList=vm_dns)
ident = None
_host_name = "localhost"
# import pdb
# pdb.set_trace()
if 'windows' in template:
ident = vim.vm.customization.Sysprep()
ident.guiUnattended = vim.vm.customization.GuiUnattended()
ident.guiUnattended.autoLogon = False
ident.guiUnattended.password = vim.vm.customization.Password()
ident.guiUnattended.password.value = 'xxxxxx'
ident.guiUnattended.password.plainText = True
ident.userData = vim.vm.customization.UserData()
ident.userData.fullName = "Derek Chadwell"
ident.userData.orgName = "NetApp"
ident.userData.computerName = vim.vm.customization.FixedName()
ident.userData.computerName.name = _host_name
ident.identification = vim.vm.customization.Identification()
else:
ident = vim.vm.customization.LinuxPrep()
ident.domain = "baidu.com"
ident.hostName = vim.vm.customization.FixedName()
if vm_hostname:
print(vm_hostname)
ident.hostName.name = _host_name
customspec = vim.vm.customization.Specification()
customspec.nicSettingMap = adaptermaps
customspec.globalIPSettings = globalip
customspec.identity = ident
return customspec`