New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VMware: Allow user to specify VM version to latest #56391
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,6 +149,8 @@ | |
- ' - 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.9. | ||
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' | ||
|
@@ -1105,42 +1107,49 @@ def configure_hardware_params(self, vm_obj): | |
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) | ||
if temp_version == 'latest': | ||
if vm_obj is not None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If 'template' parameter is set, and 'version' is also set, then 'vm_obj' is template, it's upgrade is not supported? |
||
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 | ||
if task.info.state == 'error' and 'already' not in task.info.error.msg: | ||
self.module.fail_json(msg="Failed to upgrade hardware version to latest %s " % task.info.error.msg) | ||
else: | ||
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': | ||
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 | ||
|
||
if 'virt_based_security' in self.params['hardware']: | ||
host_version = self.select_host().summary.config.product.version | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.