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..734eeda69 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..b93365a23 100644 --- a/plugins/module_utils/entity.py +++ b/plugins/module_utils/entity.py @@ -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")