Skip to content
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_vm_config_option: add more properties in output when getting VM configurations #1202

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/vmware_vm_config_option.yml
@@ -0,0 +1,2 @@
minor_changes:
- vmware_vm_config_option - Add support_usb_controller, support_ethernet_card, support_disk_controller properties in output of getting VM default configs (https://github.com/ansible-collections/community.vmware/pull/1202).
Tomorrow9 marked this conversation as resolved.
Show resolved Hide resolved
47 changes: 34 additions & 13 deletions plugins/modules/vmware_vm_config_option.py
Expand Up @@ -167,17 +167,29 @@ def get_config_option_by_spec(self, env_browser, guest_id=None, key=''):

def get_config_option_recommended(self, guest_os_desc, hwv_version=''):
guest_os_option_dict = {}
support_usb_controller = []
support_disk_controller = []
support_ethernet_card = []
if guest_os_desc and len(guest_os_desc) != 0:
default_disk_ctl = default_ethernet = default_cdrom_ctl = default_usb_ctl = ''
for name, type in self.ctl_device_type.items():
if type == guest_os_desc[0].recommendedDiskController:
default_disk_ctl = name
if type == guest_os_desc[0].recommendedEthernetCard:
default_ethernet = name
if type == guest_os_desc[0].recommendedCdromController:
default_cdrom_ctl = name
if type == guest_os_desc[0].recommendedUSBController:
default_usb_ctl = name
for name, dev_type in self.ctl_device_type.items():
for supported_type in guest_os_desc[0].supportedUSBControllerList:
if supported_type == dev_type:
support_usb_controller = support_usb_controller + [name]
if dev_type == guest_os_desc[0].recommendedUSBController:
default_usb_ctl = name
for supported_type in guest_os_desc[0].supportedEthernetCard:
if supported_type == dev_type:
support_ethernet_card = support_ethernet_card + [name]
if dev_type == guest_os_desc[0].recommendedEthernetCard:
default_ethernet = name
for supported_type in guest_os_desc[0].supportedDiskControllerList:
if supported_type == dev_type:
support_disk_controller = support_disk_controller + [name]
if dev_type == guest_os_desc[0].recommendedDiskController:
default_disk_ctl = name
if dev_type == guest_os_desc[0].recommendedCdromController:
default_cdrom_ctl = name
guest_os_option_dict = {
'Hardware version': hwv_version,
'Guest ID': guest_os_desc[0].id,
Expand All @@ -192,7 +204,15 @@ def get_config_option_recommended(self, guest_os_desc, hwv_version=''):
'Default disk size in MB': guest_os_desc[0].recommendedDiskSizeMB,
'Default network adapter': default_ethernet,
'Default CDROM controller': default_cdrom_ctl,
'Default USB controller': default_usb_ctl
'Default USB controller': default_usb_ctl,
'support_tpm_20': guest_os_desc[0].supportsTPM20,
'support_persistent_memory': guest_os_desc[0].persistentMemorySupported,
'rec_persistent_memory': guest_os_desc[0].recommendedPersistentMemoryMB,
'support_min_persistent_mem_mb': guest_os_desc[0].supportedMinPersistentMemoryMB,
'rec_vram_kb': guest_os_desc[0].vRAMSizeInKB.defaultValue,
'support_usb_controller': support_usb_controller,
'support_disk_controller': support_disk_controller,
'support_ethernet_card': support_ethernet_card
}

return guest_os_option_dict
Expand All @@ -208,7 +228,6 @@ def get_guest_id_list(self, guest_os_desc):
def get_config_option_for_guest(self):
results = {}
guest_id = []
host = None
datacenter_name = self.params.get('datacenter')
cluster_name = self.params.get('cluster_name')
esxi_host_name = self.params.get('esxi_hostname')
Expand Down Expand Up @@ -259,8 +278,7 @@ def get_config_option_for_guest(self):
vm_config_option_all = self.get_config_option_by_spec(env_browser=env_browser, key=hardware_version)
supported_gos_list = self.get_guest_id_list(guest_os_desc=vm_config_option_all)
if self.params.get('get_guest_os_ids'):
info_key = 'Supported guest IDs for %s' % vm_config_option_all.version
results.update({info_key: supported_gos_list})
results.update({vm_config_option_all.version: supported_gos_list})

if self.params.get('get_config_options') and len(guest_id) != 0:
if supported_gos_list and guest_id[0] not in supported_gos_list:
Expand Down Expand Up @@ -295,6 +313,9 @@ def main():
['cluster_name', 'esxi_hostname'],
]
)
module.deprecate(msg="Dict item names in 'instance' result will be changed from strings joined with spaces to"
" strings joined with underlines, e.g., 'Guest fullname' will be changed to 'guest_fullname'.",
version='3.0.0', collection_name="community.vmware")
vm_config_option_guest = VmConfigOption(module)
vm_config_option_guest.get_config_option_for_guest()

Expand Down
39 changes: 39 additions & 0 deletions tests/integration/targets/vmware_vm_config_option/tasks/main.yml
Expand Up @@ -58,6 +58,7 @@
assert:
that:
- "'instance' in guest_ids_1"
- guest_ids_1.instance | length != 0
when:
- "'failed' in guest_ids_1"
- not guest_ids_1.failed
Expand All @@ -84,6 +85,7 @@
assert:
that:
- "'instance' in guest_ids_2"
- guest_ids_2.instance | length != 0
when:
- "'failed' in guest_ids_2"
- not guest_ids_2.failed
Expand Down Expand Up @@ -112,6 +114,43 @@
assert:
that:
- "'instance' in recommended_configs"
- recommended_configs.instance | length != 0
when:
- "'failed' in recommended_configs"
- not recommended_configs.failed

- name: get list of config option keys by connecting to ESXi host
community.vmware.vmware_vm_config_option:
validate_certs: false
hostname: "{{ esxi_hosts[0] }}"
username: "{{ esxi_user }}"
password: "{{ esxi_password }}"
esxi_hostname: "{{ esxi_hosts[0] }}"
get_hardware_versions: true
register: config_option_keys_3

- debug:
var: config_option_keys_3

- name: get list of supported guest IDs by connecting to ESXi host with config option key
community.vmware.vmware_vm_config_option:
validate_certs: false
hostname: "{{ esxi_hosts[0] }}"
username: "{{ esxi_user }}"
password: "{{ esxi_password }}"
esxi_hostname: "{{ esxi_hosts[0] }}"
get_guest_os_ids: true
hardware_version: "{{ config_option_keys_3['instance']['Supported hardware versions'][2] }}"
register: guest_ids_3
ignore_errors: true

- debug:
var: guest_ids_3
- name: check guest ID list returned when task not failed
assert:
that:
- "'instance' in guest_ids_3"
- guest_ids_3.instance | length != 0
when:
- "'failed' in guest_ids_3"
- not guest_ids_3.failed