Skip to content

Commit

Permalink
fix for custom filter and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Gevorg-Khachatryaan authored and Gevorg-Khachatryaan committed Oct 16, 2023
1 parent 923e9c7 commit d219554
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 0 deletions.
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
9 changes: 9 additions & 0 deletions plugins/module_utils/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ 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

0 comments on commit d219554

Please sign in to comment.