mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
VMware: Hardware version support (#36562)
This fix adds support for specifying hardware version for virtual machine. Fixes: #35831 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
44332bda78
commit
435649274b
2 changed files with 47 additions and 1 deletions
|
@ -290,6 +290,7 @@ def gather_vm_facts(content, vm):
|
||||||
'hw_guest_ha_state': None,
|
'hw_guest_ha_state': None,
|
||||||
'hw_is_template': vm.config.template,
|
'hw_is_template': vm.config.template,
|
||||||
'hw_folder': None,
|
'hw_folder': None,
|
||||||
|
'hw_version': vm.config.version,
|
||||||
'guest_tools_status': _get_vm_prop(vm, ('guest', 'toolsRunningStatus')),
|
'guest_tools_status': _get_vm_prop(vm, ('guest', 'toolsRunningStatus')),
|
||||||
'guest_tools_version': _get_vm_prop(vm, ('guest', 'toolsVersion')),
|
'guest_tools_version': _get_vm_prop(vm, ('guest', 'toolsVersion')),
|
||||||
'guest_question': vm.summary.runtime.question,
|
'guest_question': vm.summary.runtime.question,
|
||||||
|
|
|
@ -109,6 +109,10 @@ options:
|
||||||
version_added: 2.5'
|
version_added: 2.5'
|
||||||
- ' - C(cpu_reservation) (integer): The amount of CPU resource that is guaranteed available to the virtual machine.
|
- ' - C(cpu_reservation) (integer): The amount of CPU resource that is guaranteed available to the virtual machine.
|
||||||
Unit is MHz. version_added: 2.5'
|
Unit is MHz. version_added: 2.5'
|
||||||
|
- ' - C(version) (integer): The Virtual machine hardware versions. Default is 10 (ESXi 5.5 and onwards).
|
||||||
|
Please check VMware documentation for correct virtual machine hardware version.
|
||||||
|
Incorrect hardware version may lead to failure in deployment. If hardware version is already to given version then no action is taken.
|
||||||
|
version_added: 2.6'
|
||||||
|
|
||||||
guest_id:
|
guest_id:
|
||||||
description:
|
description:
|
||||||
|
@ -292,6 +296,7 @@ EXAMPLES = r'''
|
||||||
hotadd_cpu: True
|
hotadd_cpu: True
|
||||||
hotremove_cpu: True
|
hotremove_cpu: True
|
||||||
hotadd_memory: False
|
hotadd_memory: False
|
||||||
|
version: 12 # Hardware version of VM
|
||||||
cdrom:
|
cdrom:
|
||||||
type: iso
|
type: iso
|
||||||
iso_path: "[datastore1] livecd.iso"
|
iso_path: "[datastore1] livecd.iso"
|
||||||
|
@ -880,9 +885,9 @@ class PyVmomiHelper(PyVmomi):
|
||||||
Args:
|
Args:
|
||||||
vm_obj: virtual machine object
|
vm_obj: virtual machine object
|
||||||
"""
|
"""
|
||||||
# maxMksConnections == max_connections
|
|
||||||
if 'hardware' in self.params:
|
if 'hardware' in self.params:
|
||||||
if 'max_connections' in self.params['hardware']:
|
if 'max_connections' in self.params['hardware']:
|
||||||
|
# maxMksConnections == max_connections
|
||||||
self.configspec.maxMksConnections = int(self.params['hardware']['max_connections'])
|
self.configspec.maxMksConnections = int(self.params['hardware']['max_connections'])
|
||||||
if vm_obj is None or self.configspec.maxMksConnections != vm_obj.config.hardware.maxMksConnections:
|
if vm_obj is None or self.configspec.maxMksConnections != vm_obj.config.hardware.maxMksConnections:
|
||||||
self.change_detected = True
|
self.change_detected = True
|
||||||
|
@ -892,6 +897,46 @@ class PyVmomiHelper(PyVmomi):
|
||||||
if vm_obj is None or self.configspec.nestedHVEnabled != bool(vm_obj.config.nestedHVEnabled):
|
if vm_obj is None or self.configspec.nestedHVEnabled != bool(vm_obj.config.nestedHVEnabled):
|
||||||
self.change_detected = True
|
self.change_detected = True
|
||||||
|
|
||||||
|
if 'version' in self.params['hardware']:
|
||||||
|
hw_version_check_failed = False
|
||||||
|
temp_version = self.params['hardware'].get('version', 10)
|
||||||
|
try:
|
||||||
|
temp_version = int(temp_version)
|
||||||
|
except ValueError:
|
||||||
|
hw_version_check_failed = True
|
||||||
|
|
||||||
|
if temp_version not in range(3, 15):
|
||||||
|
hw_version_check_failed = True
|
||||||
|
|
||||||
|
if hw_version_check_failed:
|
||||||
|
self.module.fail_json(msg="Failed to set hardware.version '%s' value as valid"
|
||||||
|
" values range from 3 (ESX 2.x) to 14 (ESXi 6.5 and greater)." % temp_version)
|
||||||
|
# Hardware version is denoted as "vmx-10"
|
||||||
|
version = "vmx-%02d" % temp_version
|
||||||
|
self.configspec.version = version
|
||||||
|
if vm_obj is None or self.configspec.version != vm_obj.config.version:
|
||||||
|
self.change_detected = True
|
||||||
|
if vm_obj is not None:
|
||||||
|
# VM exists and we need to update the hardware version
|
||||||
|
current_version = vm_obj.config.version
|
||||||
|
# current_version = "vmx-10"
|
||||||
|
version_digit = int(current_version.split("-", 1)[-1])
|
||||||
|
if temp_version < version_digit:
|
||||||
|
self.module.fail_json(msg="Current hardware version '%d' which is greater than the specified"
|
||||||
|
" version '%d'. Downgrading hardware version is"
|
||||||
|
" not supported. Please specify version greater"
|
||||||
|
" than the current version." % (version_digit,
|
||||||
|
temp_version))
|
||||||
|
new_version = "vmx-%02d" % temp_version
|
||||||
|
try:
|
||||||
|
task = vm_obj.UpgradeVM_Task(new_version)
|
||||||
|
self.wait_for_task(task)
|
||||||
|
if task.info.state != 'error':
|
||||||
|
self.change_detected = True
|
||||||
|
except vim.fault.AlreadyUpgraded:
|
||||||
|
# Don't fail if VM is already upgraded.
|
||||||
|
pass
|
||||||
|
|
||||||
def get_vm_cdrom_device(self, vm=None):
|
def get_vm_cdrom_device(self, vm=None):
|
||||||
if vm is None:
|
if vm is None:
|
||||||
return None
|
return None
|
||||||
|
|
Loading…
Reference in a new issue