diff --git a/plugins/inventory/ntnx_prism_vm_inventory.py b/plugins/inventory/ntnx_prism_vm_inventory.py index 43c0ba216..498a995d7 100644 --- a/plugins/inventory/ntnx_prism_vm_inventory.py +++ b/plugins/inventory/ntnx_prism_vm_inventory.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function + __metaclass__ = type DOCUMENTATION = r""" @@ -126,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) resp = vm.list(self.data) keys_to_strip_from_resp = [ "disk_list", @@ -162,6 +164,7 @@ def parse(self, inventory, loader, path, cache=True): self.inventory.add_host(vm_name, group=cluster) self.inventory.set_variable(vm_name, "ansible_host", vm_ip) self.inventory.set_variable(vm_name, "uuid", vm_uuid) + self.inventory.set_variable(vm_name, "name", vm_name) # Add hostvars for key in keys_to_strip_from_resp: diff --git a/plugins/module_utils/prism/vms.py b/plugins/module_utils/prism/vms.py index 03fc167af..9a08af855 100644 --- a/plugins/module_utils/prism/vms.py +++ b/plugins/module_utils/prism/vms.py @@ -45,6 +45,42 @@ def __init__(self, module): "remove_categories": CategoriesMapping.build_remove_all_categories_spec, } + def list( + self, + data=None, + endpoint=None, + use_base_url=False, + raise_error=True, + no_response=False, + timeout=30, + max_length=500, + ): + if data.get("length", 0) > max_length: + spec = deepcopy(data) + resp = {"entities": []} + total_matches = None + total_length = spec["length"] + spec["length"] = max_length + spec["offset"] = spec.get("offset", 0) + while True: + sub_resp = super(VM, self).list(spec) + resp["entities"].extend(sub_resp["entities"]) + total_matches = sub_resp["metadata"].get("total_matches") + total_length -= max_length + if total_length <= 0: + break + spec["length"] = ( + total_length if total_length < max_length else max_length + ) + spec["offset"] += max_length + + resp["metadata"] = data + resp["metadata"]["total_matches"] = total_matches + resp["metadata"]["length"] = len(resp["entities"]) + else: + resp = super(VM, self).list(data) + return resp + @staticmethod def is_on(payload): return True if payload["spec"]["resources"]["power_state"] == "ON" else False