added vDS support for config spec and note/annotation support
This commit is contained in:
parent
4d3fec908b
commit
e51f6c18eb
1 changed files with 43 additions and 18 deletions
|
@ -89,6 +89,11 @@ options:
|
||||||
description:
|
description:
|
||||||
- The esxi hostname where the VM will run.
|
- The esxi hostname where the VM will run.
|
||||||
required: True
|
required: True
|
||||||
|
annotation:
|
||||||
|
description:
|
||||||
|
- A note or annotation to include in the VM
|
||||||
|
required: False
|
||||||
|
version_added: "2.3"
|
||||||
customize:
|
customize:
|
||||||
description:
|
description:
|
||||||
- Should customization spec be run
|
- Should customization spec be run
|
||||||
|
@ -796,10 +801,11 @@ class PyVmomiHelper(object):
|
||||||
# lets try and assign a static ip addresss
|
# lets try and assign a static ip addresss
|
||||||
if self.params['customize'] is True:
|
if self.params['customize'] is True:
|
||||||
ip_settings = list()
|
ip_settings = list()
|
||||||
if self.params['ips'] and self.params['network']:
|
if self.params['ips']:
|
||||||
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 network:
|
||||||
if ip in IPNetwork(network):
|
if ip in IPNetwork(network):
|
||||||
self.params['networks'][network]['ip'] = str(ip)
|
self.params['networks'][network]['ip'] = str(ip)
|
||||||
ipnet = IPNetwork(network)
|
ipnet = IPNetwork(network)
|
||||||
|
@ -837,15 +843,28 @@ class PyVmomiHelper(object):
|
||||||
nic.device.addressType = 'assigned'
|
nic.device.addressType = 'assigned'
|
||||||
nic.device.deviceInfo = vim.Description()
|
nic.device.deviceInfo = vim.Description()
|
||||||
nic.device.deviceInfo.label = 'Network Adapter %s' % (key + 1)
|
nic.device.deviceInfo.label = 'Network Adapter %s' % (key + 1)
|
||||||
|
|
||||||
nic.device.deviceInfo.summary = ip_settings[key]['network']
|
nic.device.deviceInfo.summary = ip_settings[key]['network']
|
||||||
|
|
||||||
|
if hasattr(get_obj(self.content, [vim.Network], ip_settings[key]['network']), 'portKeys'):
|
||||||
|
# VDS switch
|
||||||
|
pg_obj = get_obj(self.content, [vim.dvs.DistributedVirtualPortgroup], ip_settings[key]['network'])
|
||||||
|
dvs_port_connection = vim.dvs.PortConnection()
|
||||||
|
dvs_port_connection.portgroupKey= pg_obj.key
|
||||||
|
dvs_port_connection.switchUuid= pg_obj.config.distributedVirtualSwitch.uuid
|
||||||
|
nic.device.backing = vim.vm.device.VirtualEthernetCard.DistributedVirtualPortBackingInfo()
|
||||||
|
nic.device.backing.port = dvs_port_connection
|
||||||
|
|
||||||
|
else:
|
||||||
|
# vSwitch
|
||||||
nic.device.backing = vim.vm.device.VirtualEthernetCard.NetworkBackingInfo()
|
nic.device.backing = vim.vm.device.VirtualEthernetCard.NetworkBackingInfo()
|
||||||
nic.device.backing.network = get_obj(self.content, [vim.Network], ip_settings[key]['network'])
|
nic.device.backing.network = get_obj(self.content, [vim.Network], ip_settings[key]['network'])
|
||||||
|
|
||||||
nic.device.backing.deviceName = ip_settings[key]['network']
|
nic.device.backing.deviceName = ip_settings[key]['network']
|
||||||
|
|
||||||
nic.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()
|
nic.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()
|
||||||
nic.device.connectable.startConnected = True
|
nic.device.connectable.startConnected = True
|
||||||
nic.device.connectable.allowGuestControl = True
|
nic.device.connectable.allowGuestControl = True
|
||||||
|
nic.device.connectable.connected = True
|
||||||
|
nic.device.connectable.allowGuestControl = True
|
||||||
devices.append(nic)
|
devices.append(nic)
|
||||||
|
|
||||||
# Update the spec with the added NIC
|
# Update the spec with the added NIC
|
||||||
|
@ -881,12 +900,11 @@ class PyVmomiHelper(object):
|
||||||
ident.hostName.name = self.params['name']
|
ident.hostName.name = self.params['name']
|
||||||
|
|
||||||
customspec = vim.vm.customization.Specification()
|
customspec = vim.vm.customization.Specification()
|
||||||
customspec.nicSettingMap = adaptermaps
|
clonespec_kwargs['customization'] = customspec
|
||||||
customspec.globalIPSettings = globalip
|
|
||||||
customspec.identity = ident
|
|
||||||
|
|
||||||
clonespec = vim.vm.CloneSpec(**clonespec_kwargs)
|
clonespec_kwargs['customization'].nicSettingMap = adaptermaps
|
||||||
clonespec.customization = customspec
|
clonespec_kwargs['customization'].globalIPSettings = globalip
|
||||||
|
clonespec_kwargs['customization'].identity = ident
|
||||||
|
|
||||||
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)
|
||||||
|
@ -898,7 +916,13 @@ class PyVmomiHelper(object):
|
||||||
return ({'changed': False, 'failed': True, 'msg': task.info.error.msg})
|
return ({'changed': False, 'failed': True, 'msg': task.info.error.msg})
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
# set annotation
|
||||||
vm = task.info.result
|
vm = task.info.result
|
||||||
|
if self.params['annotation']:
|
||||||
|
annotation_spec = vim.vm.ConfigSpec()
|
||||||
|
annotation_spec.annotation = str(self.params['annotation'])
|
||||||
|
task = vm.ReconfigVM_Task(annotation_spec)
|
||||||
|
self.wait_for_task(task)
|
||||||
if wait_for_ip:
|
if wait_for_ip:
|
||||||
self.set_powerstate(vm, 'poweredon', force=False)
|
self.set_powerstate(vm, 'poweredon', force=False)
|
||||||
self.wait_for_vm_ip(vm)
|
self.wait_for_vm_ip(vm)
|
||||||
|
@ -1238,6 +1262,7 @@ def main():
|
||||||
default='present'),
|
default='present'),
|
||||||
validate_certs=dict(required=False, type='bool', default=True),
|
validate_certs=dict(required=False, type='bool', default=True),
|
||||||
template_src=dict(required=False, type='str', aliases=['template']),
|
template_src=dict(required=False, type='str', aliases=['template']),
|
||||||
|
annotation=dict(required=False, type='str', aliases=['notes']),
|
||||||
name=dict(required=True, type='str'),
|
name=dict(required=True, type='str'),
|
||||||
name_match=dict(required=False, type='str', default='first'),
|
name_match=dict(required=False, type='str', default='first'),
|
||||||
snapshot_op=dict(required=False, type='dict', default={}),
|
snapshot_op=dict(required=False, type='dict', default={}),
|
||||||
|
|
Loading…
Reference in a new issue