Skip to content

Commit

Permalink
Stable-4.x: vmware_all_snapshots_info: Fix datacenter parameter being…
Browse files Browse the repository at this point in the history
… ignored (#2168)

SUMMARY
The datacenter parameter was ignored in the vmware_all_snapshots_info module, so all VM snapshots were returned.
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

vmware_all_snapshots_info

ADDITIONAL INFORMATION
Backport of #2165
  • Loading branch information
mariolenz committed Sep 15, 2024
1 parent f7cb671 commit 5a71cb5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/2138-vmware_all_snapshots_info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- vmware_all_snapshots_info - fixed the datacenter parameter was ignored(https://github.com/ansible-collections/community.vmware/pull/2165).
13 changes: 8 additions & 5 deletions plugins/modules/vmware_all_snapshots_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,20 @@ def list_snapshots(self, vm):
else []
)

def get_all_vms(self):
def get_all_vms(self, datacenter):
content = self.content

datacenter_obj = self.find_datacenter_by_name(datacenter)
container = content.viewManager.CreateContainerView(
content.rootFolder, [vim.VirtualMachine], True
datacenter_obj, [vim.VirtualMachine], True
)
vms = container.view
container.Destroy()
return vms

def gather_snapshots_info(self, filters, match_type):
def gather_snapshots_info(self, filters, match_type, datacenter=None):
snapshot_data = []
for vm in self.get_all_vms():
for vm in self.get_all_vms(datacenter):
for snapshot in self.list_snapshots(vm):
snapshot_info = {
"vm_name": vm.name,
Expand Down Expand Up @@ -194,9 +196,10 @@ def main():

module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
vmware_snapshot_info = VMwareSnapshotInfo(module)
datacenter = module.params.get("datacenter")
filters = module.params.get("filters")
match_type = module.params.get("match_type")
all_snapshots = vmware_snapshot_info.gather_snapshots_info(filters, match_type)
all_snapshots = vmware_snapshot_info.gather_snapshots_info(filters, match_type, datacenter)
module.exit_json(changed=False, vmware_all_snapshots_info=all_snapshots)


Expand Down

0 comments on commit 5a71cb5

Please sign in to comment.