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

Bug/inventory#228 new #278

Merged
merged 8 commits into from
Sep 21, 2022
Merged
20 changes: 19 additions & 1 deletion plugins/inventory/ntnx_prism_vm_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from __future__ import absolute_import, division, print_function

from copy import deepcopy

__metaclass__ = type

DOCUMENTATION = r"""
Expand Down Expand Up @@ -93,6 +95,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 +129,22 @@ def parse(self, inventory, loader, path, cache=True):
self.validate_certs,
)
vm = vms.VM(module)
resp = vm.list(self.data)
self.data["offset"] = self.data.get("offset", 0)
if self.data["length"] > self.max_length:
spec = deepcopy(self.data)
resp = {"entities": []}
total_length = spec["length"]
spec["length"] = self.max_length
while True:
sub_resp = vm.list(spec)
resp["entities"].extend(sub_resp["entities"])
total_length -= self.max_length
if total_length <= 0:
break
spec["length"] = total_length if total_length < self.max_length else self.max_length
spec["offset"] += self.max_length
else:
resp = vm.list(self.data)
keys_to_strip_from_resp = [
"disk_list",
"vnuma_config",
Expand Down