VMware: add support for boot option firmware (#42730)

This fix adds support for the boot option 'firmware'

Fixes: #42541

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2018-07-27 09:18:04 +05:30 committed by GitHub
parent dce0a8d052
commit 604fcb55ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 163 additions and 1 deletions

View file

@ -144,6 +144,8 @@ options:
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'
- ' - C(boot_firmware) (string): Choose which firmware should be used to boot the virtual machine.
Allowed values are "bios" and "efi". version_added: 2.7'
guest_id:
description:
@ -387,6 +389,7 @@ EXAMPLES = r'''
hotremove_cpu: True
hotadd_memory: False
version: 12 # Hardware version of virtual machine
boot_firmware: "efi"
cdrom:
type: iso
iso_path: "[datastore1] livecd.iso"
@ -946,6 +949,15 @@ class PyVmomiHelper(PyVmomi):
if vm_obj is None or self.configspec.memoryReservationLockedToMax != vm_obj.config.memoryReservationLockedToMax:
self.change_detected = True
if 'boot_firmware' in self.params['hardware']:
boot_firmware = self.params['hardware']['boot_firmware'].lower()
if boot_firmware not in ('bios', 'efi'):
self.module.fail_json(msg="hardware.boot_firmware value is invalid [%s]."
" Need one of ['bios', 'efi']." % boot_firmware)
self.configspec.firmware = boot_firmware
if vm_obj is None or self.configspec.firmware != vm_obj.config.firmware:
self.change_detected = True
def configure_cdrom(self, vm_obj):
# Configure the VM CD-ROM
if "cdrom" in self.params and self.params["cdrom"]:

View file

@ -0,0 +1,149 @@
# Test code for the vmware_guest module.
# Copyright: (c) 2018, Abhijeet Kasurde <akasurde@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
- name: Wait for Flask controller to come up online
wait_for:
host: "{{ vcsim }}"
port: 5000
state: started
- name: kill vcsim
uri:
url: http://{{ vcsim }}:5000/killall
- name: start vcsim with no folders
uri:
url: http://{{ vcsim }}:5000/spawn?datacenter=1&cluster=1&folder=0
register: vcsim_instance
- name: Wait for Flask controller to come up online
wait_for:
host: "{{ vcsim }}"
port: 443
state: started
- name: get a list of VMS from vcsim
uri:
url: http://{{ vcsim }}:5000/govc_find?filter=VM
register: vmlist
- debug: var=vcsim_instance
- debug: var=vmlist
- name: create new VMs with boot_firmware as 'bios'
vmware_guest:
validate_certs: False
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance['json']['username'] }}"
password: "{{ vcsim_instance['json']['password'] }}"
name: "{{ 'newvm_' + item|basename }}"
guest_id: centos64Guest
datacenter: "{{ (item|basename).split('_')[0] }}"
hardware:
num_cpus: 4
boot_firmware: "bios"
memory_mb: 512
disk:
- size: 1gb
type: thin
autoselect_datastore: True
state: poweredoff
folder: "{{ item|dirname }}"
with_items: "{{ vmlist['json'] }}"
register: clone_d1_c1_f0
- debug: var=clone_d1_c1_f0
- name: assert that changes were made
assert:
that:
- "clone_d1_c1_f0.results|map(attribute='changed')|unique|list == [true]"
# VCSIM does not recognizes existing VMs boot firmware
#- name: create new VMs again with boot_firmware as 'bios'
# vmware_guest:
# validate_certs: False
# hostname: "{{ vcsim }}"
# username: "{{ vcsim_instance['json']['username'] }}"
# password: "{{ vcsim_instance['json']['password'] }}"
# name: "{{ 'newvm_' + item|basename }}"
# guest_id: centos64Guest
# datacenter: "{{ (item|basename).split('_')[0] }}"
# hardware:
# num_cpus: 4
# boot_firmware: "bios"
# memory_mb: 512
# disk:
# - size: 1gb
# type: thin
# autoselect_datastore: True
# state: poweredoff
# folder: "{{ item|dirname }}"
# with_items: "{{ vmlist['json'] }}"
# register: clone_d1_c1_f0
#- debug: var=clone_d1_c1_f0
#- name: assert that changes were not made
# assert:
# that:
# - "clone_d1_c1_f0.results|map(attribute='changed')|unique|list == [false]"
- name: create new VMs with boot_firmware as 'efi'
vmware_guest:
validate_certs: False
hostname: "{{ vcsim }}"
username: "{{ vcsim_instance['json']['username'] }}"
password: "{{ vcsim_instance['json']['password'] }}"
name: "{{ 'newvm_efi_' + item|basename }}"
guest_id: centos64Guest
datacenter: "{{ (item|basename).split('_')[0] }}"
hardware:
num_cpus: 4
boot_firmware: "efi"
memory_mb: 512
disk:
- size: 1gb
type: thin
autoselect_datastore: True
state: poweredoff
folder: "{{ item|dirname }}"
with_items: "{{ vmlist['json'] }}"
register: clone_d1_c1_f0
- debug: var=clone_d1_c1_f0
- name: assert that changes were made
assert:
that:
- "clone_d1_c1_f0.results|map(attribute='changed')|unique|list == [true]"
# VCSIM does not recognizes existing VMs boot firmware
#- name: create new VMs again with boot_firmware as 'efi'
# vmware_guest:
# validate_certs: False
# hostname: "{{ vcsim }}"
# username: "{{ vcsim_instance['json']['username'] }}"
# password: "{{ vcsim_instance['json']['password'] }}"
# name: "{{ 'newvm_efi_' + item|basename }}"
# guest_id: centos64Guest
# datacenter: "{{ (item|basename).split('_')[0] }}"
# hardware:
# num_cpus: 4
# boot_firmware: "efi"
# memory_mb: 512
# disk:
# - size: 1gb
# type: thin
# autoselect_datastore: True
# state: poweredoff
# folder: "{{ item|dirname }}"
# with_items: "{{ vmlist['json'] }}"
# register: clone_d1_c1_f0
#- debug: var=clone_d1_c1_f0
#- name: assert that changes were not made
# assert:
# that:
# - "clone_d1_c1_f0.results|map(attribute='changed')|unique|list == [false]"

View file

@ -31,3 +31,4 @@
- include: network_with_device.yml
- include: disk_mode_d1_c1_f0.yml
- include: linked_clone_d1_c1_f0.yml
- include: boot_firmware_d1_c1_f0.yml