From e670ca666ae8c0bcde92fdd647c9bff50d0e2eae Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Tue, 4 May 2021 12:43:25 +0200 Subject: [PATCH] OpenNebula one_vm.py: Fix missing keys (#2435) (#2447) * OpenNebula one_vm.py: Fix missing keys * fixup OpenNebula one_vm.py: Fix missing keys (cherry picked from commit aaa561163b705dbf7e1f06b58382e3a072550e31) Co-authored-by: Jan Orel --- .../fragments/2435-one_vm-fix_missing_keys.yml | 2 ++ plugins/modules/cloud/opennebula/one_vm.py | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/2435-one_vm-fix_missing_keys.yml diff --git a/changelogs/fragments/2435-one_vm-fix_missing_keys.yml b/changelogs/fragments/2435-one_vm-fix_missing_keys.yml new file mode 100644 index 0000000000..395c024b26 --- /dev/null +++ b/changelogs/fragments/2435-one_vm-fix_missing_keys.yml @@ -0,0 +1,2 @@ +bugfixes: + - one_vm - Allow missing NIC keys (https://github.com/ansible-collections/community.general/pull/2435). diff --git a/plugins/modules/cloud/opennebula/one_vm.py b/plugins/modules/cloud/opennebula/one_vm.py index 425a1c464a..fa3d4abaab 100644 --- a/plugins/modules/cloud/opennebula/one_vm.py +++ b/plugins/modules/cloud/opennebula/one_vm.py @@ -752,11 +752,20 @@ def get_vm_info(client, vm): if 'NIC' in vm.TEMPLATE: if isinstance(vm.TEMPLATE['NIC'], list): for nic in vm.TEMPLATE['NIC']: - networks_info.append({'ip': nic['IP'], 'mac': nic['MAC'], 'name': nic['NETWORK'], 'security_groups': nic['SECURITY_GROUPS']}) + networks_info.append({ + 'ip': nic.get('IP', ''), + 'mac': nic.get('MAC', ''), + 'name': nic.get('NETWORK', ''), + 'security_groups': nic.get('SECURITY_GROUPS', '') + }) else: - networks_info.append( - {'ip': vm.TEMPLATE['NIC']['IP'], 'mac': vm.TEMPLATE['NIC']['MAC'], - 'name': vm.TEMPLATE['NIC']['NETWORK'], 'security_groups': vm.TEMPLATE['NIC']['SECURITY_GROUPS']}) + networks_info.append({ + 'ip': vm.TEMPLATE['NIC'].get('IP', ''), + 'mac': vm.TEMPLATE['NIC'].get('MAC', ''), + 'name': vm.TEMPLATE['NIC'].get('NETWORK', ''), + 'security_groups': + vm.TEMPLATE['NIC'].get('SECURITY_GROUPS', '') + }) import time current_time = time.localtime()