diff --git a/examples/clusters_info.yml b/examples/clusters_info.yml index 12c0ec7c2..7eab579f3 100644 --- a/examples/clusters_info.yml +++ b/examples/clusters_info.yml @@ -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: + custom_filter: + external_ip: + register: result diff --git a/examples/fip_info.yml b/examples/fip_info.yml index ac17a5231..804e9ebd4 100644 --- a/examples/fip_info.yml +++ b/examples/fip_info.yml @@ -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: + custom_filter: + private_ip: + register: result diff --git a/examples/hosts_info.yml b/examples/hosts_info.yml index ea7483968..1984cc41c 100644 --- a/examples/hosts_info.yml +++ b/examples/hosts_info.yml @@ -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: + custom_filter: + serial_number: + register: result diff --git a/examples/subnet_info.yml b/examples/subnet_info.yml index dd6790857..1d9d93314 100644 --- a/examples/subnet_info.yml +++ b/examples/subnet_info.yml @@ -29,3 +29,12 @@ check_mode: true register: result ignore_errors: True + + - name: List subnets filter and custom_filter + ntnx_subnets_info: + filter: + name: + custom_filter: + adapter_type: + vswitch_name: + register: result diff --git a/examples/vm_info.yml b/examples/vm_info.yml index 53e1e01ea..f1c834fae 100644 --- a/examples/vm_info.yml +++ b/examples/vm_info.yml @@ -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: + custom_filter: + num_sockets: + + register: result diff --git a/plugins/module_utils/entity.py b/plugins/module_utils/entity.py index a1dc79461..fe3b144ed 100644 --- a/plugins/module_utils/entity.py +++ b/plugins/module_utils/entity.py @@ -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") diff --git a/tests/integration/targets/nutanix_subnets_info/tasks/list_subnets.yml b/tests/integration/targets/nutanix_subnets_info/tasks/list_subnets.yml index b6b9890cc..cb7478a72 100644 --- a/tests/integration/targets/nutanix_subnets_info/tasks/list_subnets.yml +++ b/tests/integration/targets/nutanix_subnets_info/tasks/list_subnets.yml @@ -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 " +######################################################### \ No newline at end of file