Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for inventory to get all entities if length is > 500 #276

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion plugins/inventory/ntnx_prism_vm_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class InventoryModule(BaseInventoryPlugin):
"""Nutanix VM dynamic invetory module for ansible"""

NAME = "nutanix.ncp.ntnx_prism_vm_inventory"
max_length = 500

def verify_file(self, path):
"""Verify inventory configuration file"""
Expand Down Expand Up @@ -126,7 +127,20 @@ def parse(self, inventory, loader, path, cache=True):
self.validate_certs,
)
vm = vms.VM(module)
Gevorg-Khachatryan-97 marked this conversation as resolved.
Show resolved Hide resolved
resp = vm.list(self.data)
if self.data["length"] > self.max_length:
resp = {"entities": []}
total_length = self.data["length"]
while True:
self.data["length"] = self.max_length
Gevorg-Khachatryan-97 marked this conversation as resolved.
Show resolved Hide resolved
sub_resp = vm.list(self.data)
resp["entities"].append(sub_resp["entities"])
Gevorg-Khachatryan-97 marked this conversation as resolved.
Show resolved Hide resolved
total_length -= self.max_length
if total_length <= 0:
break
self.data["length"] = total_length if total_length < self.max_length else self.max_length
self.data["offset"] += self.max_length
else:
resp = vm.list(self.data)
keys_to_strip_from_resp = [
"disk_list",
"vnuma_config",
Expand Down