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 custom filter and examples #417

Merged
merged 4 commits into from
Oct 30, 2023
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
8 changes: 8 additions & 0 deletions examples/clusters_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@
sort_order: "ASCENDING"
sort_attribute: "name"
register: result

- name: List clusters using filter and custom_filter
ntnx_clusters_info:
filter:
name: <name>
custom_filter:
external_ip: <external_ip>
register: result
9 changes: 9 additions & 0 deletions examples/fip_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,12 @@
offset: 0
register: result
ignore_errors: True


- name: List floating_ips using filter and custom_filter
ntnx_floating_ips_info:
filter:
name: <name>
custom_filter:
private_ip: <private_ip>
register: result
8 changes: 8 additions & 0 deletions examples/hosts_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,11 @@
sort_attribute: "name"
register: result
ignore_errors: True

- name: List hosts using filter and custom_filter
ntnx_hosts_info:
filter:
name: <name>
custom_filter:
serial_number: <serial_number>
register: result
9 changes: 9 additions & 0 deletions examples/subnet_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,12 @@
check_mode: true
register: result
ignore_errors: True

- name: List subnets filter and custom_filter
ntnx_subnets_info:
filter:
name: <name>
custom_filter:
adapter_type: <adapter_type>
vswitch_name: <vswitch_name>
register: result
9 changes: 9 additions & 0 deletions examples/vm_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,12 @@
sort_attribute: "vm_name"
register: result
ignore_errors: True

- name: List vms using filter and custom_filter
ntnx_vms_info:
filter:
vm_name: <name>
custom_filter:
num_sockets: <num_sockets>

register: result
11 changes: 11 additions & 0 deletions plugins/module_utils/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ def list(
timeout=timeout,
)
if resp:
custom_filters = self.module.params.get("custom_filter")

if custom_filters:
entities_list = self._filter_entities(
resp[self.entity_type], custom_filters
)
entities_count = len(entities_list)

resp[self.entity_type] = entities_list
resp["metadata"]["length"] = entities_count

return resp
entities_list = []
main_length = data.get("length")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,18 @@
fail_msg: " Unable to list subnets "
success_msg: " Subnets listed successfully "
#########################################################
- name: List subnet using custom_filter
ntnx_subnets_info:
custom_filter:
vswitch_name: br0
register: result
ignore_errors: True

- name: Listing Status
assert:
that:
- result.response is defined
- result.response.entities[0].status.resources.vswitch_name == "br0"
fail_msg: " Unable to List subnet using custom_filter "
success_msg: "List subnet using custom_filter listed successfully "
#########################################################
Loading