Skip to content

Commit

Permalink
vmware_vm_config_option: add more properties in output when getting V…
Browse files Browse the repository at this point in the history
…M configurations (#1202)

vmware_vm_config_option: add more properties in output when getting VM configurations

Depends-On: ansible/ansible-zuul-jobs#1420
Signed-off-by: dianew dianew@vmware.com
SUMMARY

Add supported disk controller types, supported network adapter types, supported USB controller types in the recommended_config_options output.

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

vmware_vm_config_option
ADDITIONAL INFORMATION



ok: [localhost] => {
    "vm_default_config": {
        "changed": false,
        "failed": false,
        "instance": {
            "guest_id": "amazonlinux2_64Guest",
            "hardware_version": "vmx-15",
            "recommended_config_options": {
                "default_cdrom_controller": "sata",
                "default_disk_controller": "paravirtual",
                "default_ethernet": "vmxnet3",
                "default_firmware": "efi",
                "default_secure_boot": false,
                "default_usb_controller": "",
                "guest_fullname": "Amazon Linux 2 (64-bit)",
                "rec_cpu_cores_per_socket": 2,
                "rec_cpu_socket": 1,
                "rec_disk_mb": 16384,
                "rec_memory_mb": 2048,
                "rec_persistent_memory": 8192,
                "rec_vram_kb": 8192,
                "support_disk_controller": [
                    "lsilogic",
                    "paravirtual",
                    "lsilogicsas",
                    "sata",
                    "nvme"
                ],
                "support_ethernet_card": [
                    "vmxnet3",
                    "e1000e",
                    "sriov"
                ],
                "support_min_persistent_mem_mb": 4,
                "support_persistent_memory": true,
                "support_secure_boot": true,
                "support_tpm_20": false,
                "support_usb_controller": [
                    "usb2",
                    "usb3"
                ]
            }
        }
    }
}

Reviewed-by: Mario Lenz <m@riolenz.de>
Reviewed-by: Diane Wang <None>
  • Loading branch information
Tomorrow9 committed Mar 25, 2022
1 parent 31082c5 commit e0f14ba
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 13 deletions.
4 changes: 4 additions & 0 deletions changelogs/fragments/vmware_vm_config_option.yml
@@ -0,0 +1,4 @@
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).
deprecated_features:
- vmware_vm_config_option - Dict item names in result will be changed from strings joined with spaces to strings joined with underlines, e.g. `Guest fullname` will be changed to `guest_fullname` in version 3.
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

0 comments on commit e0f14ba

Please sign in to comment.