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
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions plugins/inventory/ntnx_prism_vm_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from __future__ import absolute_import, division, print_function


__metaclass__ = type

DOCUMENTATION = r"""
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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:
Expand Down
36 changes: 36 additions & 0 deletions plugins/module_utils/prism/vms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down