From c7c1e434e5159eb7d3326053ba3c6a8948160f0c Mon Sep 17 00:00:00 2001 From: Gevorg-Khachatryaan Date: Wed, 14 Sep 2022 13:55:17 +0400 Subject: [PATCH 1/3] fix for inventory to get all entities --- plugins/inventory/ntnx_prism_vm_inventory.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/inventory/ntnx_prism_vm_inventory.py b/plugins/inventory/ntnx_prism_vm_inventory.py index 43c0ba216..b167dc8bb 100644 --- a/plugins/inventory/ntnx_prism_vm_inventory.py +++ b/plugins/inventory/ntnx_prism_vm_inventory.py @@ -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""" @@ -126,7 +127,20 @@ def parse(self, inventory, loader, path, cache=True): self.validate_certs, ) vm = vms.VM(module) - 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 + sub_resp = vm.list(self.data) + resp["entities"].append(sub_resp["entities"]) + 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", From 61909203a8027dd83e4136bc323cf80b85bcc9ba Mon Sep 17 00:00:00 2001 From: Gevorg Khachatryan <95351366+Gevorg-Khachatryan-97@users.noreply.github.com> Date: Mon, 19 Sep 2022 12:17:15 +0400 Subject: [PATCH 2/3] Update plugins/inventory/ntnx_prism_vm_inventory.py Co-authored-by: Pradeepsingh Bhati --- plugins/inventory/ntnx_prism_vm_inventory.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/inventory/ntnx_prism_vm_inventory.py b/plugins/inventory/ntnx_prism_vm_inventory.py index b167dc8bb..176ad6bee 100644 --- a/plugins/inventory/ntnx_prism_vm_inventory.py +++ b/plugins/inventory/ntnx_prism_vm_inventory.py @@ -127,6 +127,7 @@ def parse(self, inventory, loader, path, cache=True): self.validate_certs, ) vm = vms.VM(module) + self.data["offset"]=self.data.get("offset", 0) if self.data["length"] > self.max_length: resp = {"entities": []} total_length = self.data["length"] From 27a56e62fe7ec987948e28183a27ebefad34d2d2 Mon Sep 17 00:00:00 2001 From: Gevorg Khachatryan <95351366+Gevorg-Khachatryan-97@users.noreply.github.com> Date: Mon, 19 Sep 2022 12:17:41 +0400 Subject: [PATCH 3/3] Update plugins/inventory/ntnx_prism_vm_inventory.py Co-authored-by: Pradeepsingh Bhati --- plugins/inventory/ntnx_prism_vm_inventory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inventory/ntnx_prism_vm_inventory.py b/plugins/inventory/ntnx_prism_vm_inventory.py index 176ad6bee..5434c40ad 100644 --- a/plugins/inventory/ntnx_prism_vm_inventory.py +++ b/plugins/inventory/ntnx_prism_vm_inventory.py @@ -134,7 +134,7 @@ def parse(self, inventory, loader, path, cache=True): while True: self.data["length"] = self.max_length sub_resp = vm.list(self.data) - resp["entities"].append(sub_resp["entities"]) + resp["entities"].extend(sub_resp["entities"]) total_length -= self.max_length if total_length <= 0: break