Skip to content

Commit

Permalink
stable-4.x: Improve vmware_vm_info performance (#2202)
Browse files Browse the repository at this point in the history
SUMMARY
Improve the performance of retrieving custom attributes.
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
vmware_vm_info
ADDITIONAL INFORMATION
Backport of #2194
cc @eddiehavila
  • Loading branch information
mariolenz authored Oct 9, 2024
1 parent 7595a06 commit d7c19bb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/2194-vmware_vm_info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- vmware_vm_info - Improve performance when parsing custom attributes information (https://github.com/ansible-collections/community.vmware/pull/2194)
10 changes: 8 additions & 2 deletions plugins/modules/vmware_vm_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,14 @@ def get_tag_info(self, vm_dynamic_obj):
return self.vmware_client.get_tags_for_vm(vm_mid=vm_dynamic_obj._moId)

def get_vm_attributes(self, vm):
return dict((x.name, v.value) for x in self.custom_field_mgr
for v in vm.customValue if x.key == v.key)
custom_field_values = vm.customValue
custom_field_mgr = self.custom_field_mgr
vm_attributes = {}
for custom_field in custom_field_mgr:
for custom_value in custom_field_values:
if custom_field.key == custom_value.key:
vm_attributes[custom_field.name] = custom_value.value
return vm_attributes

# https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/getallvms.py
def get_virtual_machines(self):
Expand Down

0 comments on commit d7c19bb

Please sign in to comment.