Support latest version while upgrading VM hardware. (#62188)

Support for the `latest` version during an VM hardware upgrade.
pull/63114/head
Pavan Bidkar 5 years ago committed by Gonéri Le Bouder
parent 4c79f1ec4d
commit 314f9fbd5c

@ -0,0 +1,2 @@
bugfixes:
- vmware_guest - Add ability to upgrade the guest hardware version to latest fix issue #56273.

@ -151,6 +151,8 @@ options:
- ' - C(cpu_reservation) (integer): The amount of CPU resource that is guaranteed available to the virtual machine.
Unit is MHz. version_added: 2.5'
- ' - C(version) (integer): The Virtual machine hardware versions. Default is 10 (ESXi 5.5 and onwards).
If value specified as C(latest), version is set to the most current virtual hardware supported on the host.
C(latest) is added in version 2.10.
Please check VMware documentation for correct virtual machine hardware version.
Incorrect hardware version may lead to failure in deployment. If hardware version is already equal to the given
version then no action is taken. version_added: 2.6'
@ -1246,12 +1248,24 @@ class PyVmomiHelper(PyVmomi):
if 'version' in self.params['hardware']:
hw_version_check_failed = False
temp_version = self.params['hardware'].get('version', 10)
if temp_version.lower() == 'latest':
# Check is to make sure vm_obj is not of type template
if vm_obj and not vm_obj.config.template:
try:
task = vm_obj.UpgradeVM_Task()
self.wait_for_task(task)
if task.info.state == 'error':
return {'changed': self.change_applied, 'failed': True, 'msg': task.info.error.msg, 'op': 'upgrade'}
except vim.fault.AlreadyUpgraded:
# Don't fail if VM is already upgraded.
pass
else:
try:
temp_version = int(temp_version)
except ValueError:
hw_version_check_failed = True
if temp_version not in range(3, 15):
if temp_version not in range(3, 16):
hw_version_check_failed = True
if hw_version_check_failed:
@ -1262,7 +1276,8 @@ class PyVmomiHelper(PyVmomi):
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:
# Check is to make sure vm_obj is not of type template
if vm_obj and not vm_obj.config.template:
# VM exists and we need to update the hardware version
current_version = vm_obj.config.version
# current_version = "vmx-10"

@ -29,3 +29,4 @@ vmware_guest_test_playbooks:
- poweroff_d1_c1_f1.yml
# - template_d1_c1_f0.yml
- vapp_d1_c1_f0.yml
- reconfig_vm_to_latest_version.yml

@ -0,0 +1,27 @@
# Test code for the vmware_guest module.
# Copyright: (c) 2019, Pavan Bidkar <pbidkar@vmware.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Skipping out idepotency test untill issue fixed in reconfigure_vm() become_method
- name: Upgrade VM to latest version
vmware_guest:
validate_certs: False
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
name: test_vm1
guest_id: centos7_64Guest
datacenter: "{{ dc1 }}"
folder: "{{ f0 }}"
datastore: '{{ ds2 }}'
hardware:
num_cpus: 4
memory_mb: 1028
version: latest
state: present
register: upgrade_vm
- name: assert that changes were made
assert:
that:
- upgrade_vm is changed
Loading…
Cancel
Save