|
|
@ -724,105 +724,99 @@ class PyVmomiHelper(object):
|
|
|
|
int(self.params['hardware']['memory_mb'])
|
|
|
|
int(self.params['hardware']['memory_mb'])
|
|
|
|
|
|
|
|
|
|
|
|
# lets try and assign a static ip addresss
|
|
|
|
# lets try and assign a static ip addresss
|
|
|
|
if 'customize' in self.params:
|
|
|
|
if self.params['customize'] is True:
|
|
|
|
ip_settings = list()
|
|
|
|
ip_settings = list()
|
|
|
|
|
|
|
|
if self.params['ips'] and self.params['network']:
|
|
|
|
for ip_string in self.params['ips']:
|
|
|
|
for ip_string in self.params['ips']:
|
|
|
|
ip = IPAddress(self.params['ips'])
|
|
|
|
ip = IPAddress(self.params['ips'])
|
|
|
|
|
|
|
|
for network in self.params['networks']:
|
|
|
|
for network in self.params['networks']:
|
|
|
|
if ip in IPNetwork(network):
|
|
|
|
|
|
|
|
self.params['networks'][network]['ip'] = str(ip)
|
|
|
|
if ip in IPNetwork(network):
|
|
|
|
ipnet = IPNetwork(network)
|
|
|
|
self.params['networks'][network]['ip'] = str(ip)
|
|
|
|
self.params['networks'][network]['subnet_mask'] = str(
|
|
|
|
ipnet = IPNetwork(network)
|
|
|
|
ipnet.netmask
|
|
|
|
self.params['networks'][network]['subnet_mask'] = str(
|
|
|
|
)
|
|
|
|
ipnet.netmask
|
|
|
|
ip_settings.append(self.params['networks'][network])
|
|
|
|
)
|
|
|
|
|
|
|
|
ip_settings.append(self.params['networks'][network])
|
|
|
|
key = 0
|
|
|
|
|
|
|
|
network = get_obj(self.content, [vim.Network], ip_settings[key]['network'])
|
|
|
|
|
|
|
|
datacenter = get_obj(self.content, [vim.Datacenter], self.params['datacenter'])
|
|
|
|
network = get_obj(self.content, [vim.Network], ip_settings[0]['network'])
|
|
|
|
# get the folder where VMs are kept for this datacenter
|
|
|
|
datacenter = get_obj(self.content, [vim.Datacenter], self.params['datacenter'])
|
|
|
|
destfolder = datacenter.vmFolder
|
|
|
|
# get the folder where VMs are kept for this datacenter
|
|
|
|
|
|
|
|
destfolder = datacenter.vmFolder
|
|
|
|
cluster = get_obj(self.content, [vim.ClusterComputeResource],self.params['cluster'])
|
|
|
|
|
|
|
|
|
|
|
|
cluster = get_obj(self.content, [vim.ClusterComputeResource],self.params['cluster'])
|
|
|
|
devices = []
|
|
|
|
|
|
|
|
adaptermaps = []
|
|
|
|
|
|
|
|
|
|
|
|
devices = []
|
|
|
|
try:
|
|
|
|
adaptermaps = []
|
|
|
|
for device in template.config.hardware.device:
|
|
|
|
|
|
|
|
if hasattr(device, 'addressType'):
|
|
|
|
try:
|
|
|
|
nic = vim.vm.device.VirtualDeviceSpec()
|
|
|
|
for device in template.config.hardware.device:
|
|
|
|
nic.operation = vim.vm.device.VirtualDeviceSpec.Operation.remove
|
|
|
|
|
|
|
|
nic.device = device
|
|
|
|
if hasattr(device, 'addressType'):
|
|
|
|
devices.append(nic)
|
|
|
|
nic = vim.vm.device.VirtualDeviceSpec()
|
|
|
|
except:
|
|
|
|
nic.operation = \
|
|
|
|
pass
|
|
|
|
vim.vm.device.VirtualDeviceSpec.Operation.remove
|
|
|
|
|
|
|
|
nic.device = device
|
|
|
|
# single device support
|
|
|
|
devices.append(nic)
|
|
|
|
nic = vim.vm.device.VirtualDeviceSpec()
|
|
|
|
except:
|
|
|
|
nic.operation = vim.vm.device.VirtualDeviceSpec.Operation.add
|
|
|
|
pass
|
|
|
|
nic.device = vim.vm.device.VirtualVmxnet3()
|
|
|
|
|
|
|
|
nic.device.wakeOnLanEnabled = True
|
|
|
|
# for key, ip in enumerate(ip_settings):
|
|
|
|
nic.device.addressType = 'assigned'
|
|
|
|
# VM device
|
|
|
|
nic.device.deviceInfo = vim.Description()
|
|
|
|
# single device support
|
|
|
|
nic.device.deviceInfo.label = 'Network Adapter %s' % (key + 1)
|
|
|
|
key = 0
|
|
|
|
|
|
|
|
nic = vim.vm.device.VirtualDeviceSpec()
|
|
|
|
nic.device.deviceInfo.summary = ip_settings[key]['network']
|
|
|
|
nic.operation = vim.vm.device.VirtualDeviceSpec.Operation.add
|
|
|
|
nic.device.backing = vim.vm.device.VirtualEthernetCard.NetworkBackingInfo()
|
|
|
|
nic.device = vim.vm.device.VirtualVmxnet3()
|
|
|
|
nic.device.backing.network = get_obj(self.content, [vim.Network], ip_settings[key]['network'])
|
|
|
|
nic.device.wakeOnLanEnabled = True
|
|
|
|
|
|
|
|
nic.device.addressType = 'assigned'
|
|
|
|
nic.device.backing.deviceName = ip_settings[key]['network']
|
|
|
|
nic.device.deviceInfo = vim.Description()
|
|
|
|
nic.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()
|
|
|
|
nic.device.deviceInfo.label = 'Network Adapter %s' % (key + 1)
|
|
|
|
nic.device.connectable.startConnected = True
|
|
|
|
|
|
|
|
nic.device.connectable.allowGuestControl = True
|
|
|
|
nic.device.deviceInfo.summary = ip_settings[key]['network']
|
|
|
|
devices.append(nic)
|
|
|
|
nic.device.backing = vim.vm.device.VirtualEthernetCard.NetworkBackingInfo()
|
|
|
|
|
|
|
|
nic.device.backing.network = get_obj(self.content, [vim.Network], ip_settings[key]['network'])
|
|
|
|
# Update the spec with the added NIC
|
|
|
|
|
|
|
|
clonespec_kwargs['config'].deviceChange = devices
|
|
|
|
nic.device.backing.deviceName = ip_settings[key]['network']
|
|
|
|
|
|
|
|
nic.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()
|
|
|
|
guest_map = vim.vm.customization.AdapterMapping()
|
|
|
|
nic.device.connectable.startConnected = True
|
|
|
|
guest_map.adapter = vim.vm.customization.IPSettings()
|
|
|
|
nic.device.connectable.allowGuestControl = True
|
|
|
|
guest_map.adapter.ip = vim.vm.customization.FixedIp()
|
|
|
|
devices.append(nic)
|
|
|
|
guest_map.adapter.ip.ipAddress = str(ip_settings[key]['ip'])
|
|
|
|
|
|
|
|
guest_map.adapter.subnetMask = str(ip_settings[key]['subnet_mask'])
|
|
|
|
clonespec_kwargs['config'].deviceChange = devices
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
guest_map = vim.vm.customization.AdapterMapping()
|
|
|
|
guest_map.adapter.gateway = ip_settings[key]['gateway']
|
|
|
|
guest_map.adapter = vim.vm.customization.IPSettings()
|
|
|
|
except:
|
|
|
|
guest_map.adapter.ip = vim.vm.customization.FixedIp()
|
|
|
|
pass
|
|
|
|
guest_map.adapter.ip.ipAddress = str(ip_settings[key]['ip'])
|
|
|
|
|
|
|
|
guest_map.adapter.subnetMask = str(ip_settings[key]['subnet_mask'])
|
|
|
|
try:
|
|
|
|
|
|
|
|
guest_map.adapter.dnsDomain = self.params['domain']
|
|
|
|
try:
|
|
|
|
except:
|
|
|
|
guest_map.adapter.gateway = ip_settings[key]['gateway']
|
|
|
|
pass
|
|
|
|
except:
|
|
|
|
|
|
|
|
pass
|
|
|
|
adaptermaps.append(guest_map)
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
# DNS settings
|
|
|
|
guest_map.adapter.dnsDomain = self.params['domain']
|
|
|
|
globalip = vim.vm.customization.GlobalIPSettings()
|
|
|
|
except:
|
|
|
|
globalip.dnsServerList = self.params['dns_servers']
|
|
|
|
pass
|
|
|
|
globalip.dnsSuffixList = str(self.params['domain'])
|
|
|
|
|
|
|
|
|
|
|
|
adaptermaps.append(guest_map)
|
|
|
|
# Hostname settings
|
|
|
|
|
|
|
|
ident = vim.vm.customization.LinuxPrep()
|
|
|
|
# DNS settings
|
|
|
|
ident.domain = str(self.params['domain'])
|
|
|
|
globalip = vim.vm.customization.GlobalIPSettings()
|
|
|
|
ident.hostName = vim.vm.customization.FixedName()
|
|
|
|
globalip.dnsServerList = self.params['dns_servers']
|
|
|
|
ident.hostName.name = self.params['name']
|
|
|
|
globalip.dnsSuffixList = str(self.params['domain'])
|
|
|
|
|
|
|
|
|
|
|
|
customspec = vim.vm.customization.Specification()
|
|
|
|
# Hostname settings
|
|
|
|
customspec.nicSettingMap = adaptermaps
|
|
|
|
ident = vim.vm.customization.LinuxPrep()
|
|
|
|
customspec.globalIPSettings = globalip
|
|
|
|
ident.domain = str(self.params['domain'])
|
|
|
|
customspec.identity = ident
|
|
|
|
ident.hostName = vim.vm.customization.FixedName()
|
|
|
|
|
|
|
|
ident.hostName.name = self.params['name']
|
|
|
|
clonespec = vim.vm.CloneSpec(**clonespec_kwargs)
|
|
|
|
|
|
|
|
clonespec.customization = customspec
|
|
|
|
customspec = vim.vm.customization.Specification()
|
|
|
|
|
|
|
|
customspec.nicSettingMap = adaptermaps
|
|
|
|
|
|
|
|
customspec.globalIPSettings = globalip
|
|
|
|
|
|
|
|
customspec.identity = ident
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clonespec = vim.vm.CloneSpec(**clonespec_kwargs)
|
|
|
|
|
|
|
|
clonespec.customization = customspec
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clonespec = vim.vm.CloneSpec(**clonespec_kwargs)
|
|
|
|
clonespec = vim.vm.CloneSpec(**clonespec_kwargs)
|
|
|
|
task = template.Clone(folder=destfolder, name=self.params['name'], spec=clonespec)
|
|
|
|
task = template.Clone(folder=destfolder, name=self.params['name'], spec=clonespec)
|
|
|
|