Skip to content

Commit

Permalink
vmware_guest: Fix vApp property handling
Browse files Browse the repository at this point in the history
The vmware_guest module did not properly handle setting vApp properties if the
VmConfigSpec never contained an active vAppConfig. This resulted in an exception
due to trying to access `property` on `None`. This commit changes the behavior
to default the current list of vApp properties to an empty list if there has
never been any vAppConfig.
  • Loading branch information
ppmathis committed Oct 28, 2024
1 parent 9d51ab9 commit 198e277
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions changelogs/fragments/2220-vmware_guest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bugfixes:
- vmware_guest - setting vApp properties on virtual machines without vApp options raised an AttributeError.
Fix now gracefully handles a `None` value for vApp options when retrieving current vApp properties
(https://github.com/ansible-collections/community.vmware/pull/2220).
5 changes: 3 additions & 2 deletions plugins/modules/vmware_guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2067,13 +2067,14 @@ def configure_vapp_properties(self, vm_obj):
if vm_obj:
# VM exists
orig_spec = vm_obj.config.vAppConfig
orig_properties = orig_spec.property if orig_spec is not None else []

vapp_properties_current = dict((x.id, x) for x in orig_spec.property)
vapp_properties_current = dict((x.id, x) for x in orig_properties)
vapp_properties_to_change = dict((x['id'], x) for x in self.params['vapp_properties'])

# each property must have a unique key
# init key counter with max value + 1
all_keys = [x.key for x in orig_spec.property]
all_keys = [x.key for x in orig_properties]
new_property_index = max(all_keys) + 1 if all_keys else 0

for property_id, property_spec in vapp_properties_to_change.items():
Expand Down

0 comments on commit 198e277

Please sign in to comment.