From 7decbc3621f1e154b3d216e91bd1ec6c22c741de Mon Sep 17 00:00:00 2001 From: Pradeepsingh Bhati Date: Tue, 21 Mar 2023 11:16:18 +0530 Subject: [PATCH 1/4] Add available IPs in network profiles response as per flag --- .../ndb/profiles/profile_types.py | 5 +++ plugins/modules/ntnx_ndb_profiles_info.py | 13 +++++++ .../ntnx_ndb_profiles_info/tasks/info.yml | 38 +++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/plugins/module_utils/ndb/profiles/profile_types.py b/plugins/module_utils/ndb/profiles/profile_types.py index 19cccbc4d..1aadd8e54 100644 --- a/plugins/module_utils/ndb/profiles/profile_types.py +++ b/plugins/module_utils/ndb/profiles/profile_types.py @@ -96,6 +96,11 @@ def __init__(self, module): super(NetworkProfile, self).__init__(module) self._type = NDB.ProfileTypes.NETWORK + def get_available_ips(self, uuid): + endpoint = "{0}/get-available-ips".format(uuid) + resp = self.read(endpoint=endpoint) + return resp + def get_default_version_update_spec(self, override_spec=None): spec = { "name": "", diff --git a/plugins/modules/ntnx_ndb_profiles_info.py b/plugins/modules/ntnx_ndb_profiles_info.py index cf08eb53a..ed6e6a362 100644 --- a/plugins/modules/ntnx_ndb_profiles_info.py +++ b/plugins/modules/ntnx_ndb_profiles_info.py @@ -46,6 +46,12 @@ - filter as per profile type type: str choices: ["Software","Compute","Network","Database_Parameter",] + include_available_ips: + description: + - include available ips in response + - only to be used for network profiles having NDB managed subnets + default: false + type: bool extends_documentation_fragment: - nutanix.ncp.ntnx_ndb_info_base_module author: @@ -180,6 +186,7 @@ from ..module_utils.ndb.base_info_module import NdbBaseInfoModule # noqa: E402 from ..module_utils.ndb.profiles.profiles import Profile # noqa: E402 from ..module_utils.utils import remove_param_with_none_value # noqa: E402 +from ..module_utils.ndb.profiles.profile_types import NetworkProfile def get_module_spec(): @@ -217,6 +224,7 @@ def get_module_spec(): type="dict", options=filters_spec, ), + include_available_ips=dict(type="bool", default=False), ) return module_args @@ -230,6 +238,11 @@ def get_profile(module, result): result["response"] = resp + if module.params.get("include_available_ips", False): + uuid = resp.get("id") + ntw_profile = NetworkProfile(module) + result["response"]["available_ips"] = ntw_profile.get_available_ips(uuid=uuid) + def get_profiles(module, result): profile = Profile(module) diff --git a/tests/integration/targets/ntnx_ndb_profiles_info/tasks/info.yml b/tests/integration/targets/ntnx_ndb_profiles_info/tasks/info.yml index 9691e884d..e8e3922c8 100644 --- a/tests/integration/targets/ntnx_ndb_profiles_info/tasks/info.yml +++ b/tests/integration/targets/ntnx_ndb_profiles_info/tasks/info.yml @@ -68,6 +68,44 @@ - result.response[0].type == "Network" fail_msg: "Unable to list all Network NDB profile" success_msg: "Network NDB profiles listed successfully" + +################################################################ +- name: get network profile with available IPs + ntnx_ndb_profiles_info: + name: "{{static_network_profile.name}}" + include_available_ips: true + register: result + ignore_errors: true + +- name: check listing status + assert: + that: + - result.response is defined + - result.failed == false + - result.changed == false + - result.response.available_ips | length == 1 + - result.response.id == "{{static_network_profile.uuid}}" + + fail_msg: "Unable to list network profile with available IPs" + success_msg: "Network NDB profiles along with available IPs obtained successfully" + +- name: get network profile with available IPs + ntnx_ndb_profiles_info: + uuid: "{{postgres_ha_profiles.multicluster_network_profile.uuid}}" + include_available_ips: true + register: result + ignore_errors: true + +- name: check listing status + assert: + that: + - result.response is defined + - result.failed == false + - result.changed == false + - result.response.available_ips | length == 2 + - result.response.id == "{{postgres_ha_profiles.multicluster_network_profile.uuid}}" + fail_msg: "Unable to list network profile with available IPs" + success_msg: "Network NDB profiles along with available IPs obtained successfully" ################################################################ - name: List Compute profiles ntnx_ndb_profiles_info: From d0ca98442f73e28d5e50566ea7424da8d7f076e8 Mon Sep 17 00:00:00 2001 From: Pradeepsingh Bhati Date: Tue, 21 Mar 2023 11:20:42 +0530 Subject: [PATCH 2/4] doc fix --- plugins/modules/ntnx_ndb_profiles_info.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/modules/ntnx_ndb_profiles_info.py b/plugins/modules/ntnx_ndb_profiles_info.py index ed6e6a362..8df617823 100644 --- a/plugins/modules/ntnx_ndb_profiles_info.py +++ b/plugins/modules/ntnx_ndb_profiles_info.py @@ -48,8 +48,9 @@ choices: ["Software","Compute","Network","Database_Parameter",] include_available_ips: description: - - include available ips in response + - include available ips for each subnet in response - only to be used for network profiles having NDB managed subnets + - only to be used for fetching profile using C(name) or C(uuid) default: false type: bool extends_documentation_fragment: From 4e8849e89eff9078d28487719ad4f3f65b3668c2 Mon Sep 17 00:00:00 2001 From: Pradeepsingh Bhati Date: Tue, 21 Mar 2023 11:23:54 +0530 Subject: [PATCH 3/4] isort fix --- plugins/modules/ntnx_ndb_profiles_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/ntnx_ndb_profiles_info.py b/plugins/modules/ntnx_ndb_profiles_info.py index 8df617823..0de42259d 100644 --- a/plugins/modules/ntnx_ndb_profiles_info.py +++ b/plugins/modules/ntnx_ndb_profiles_info.py @@ -185,9 +185,9 @@ """ from ..module_utils.ndb.base_info_module import NdbBaseInfoModule # noqa: E402 +from ..module_utils.ndb.profiles.profile_types import NetworkProfile # noqa: E402 from ..module_utils.ndb.profiles.profiles import Profile # noqa: E402 from ..module_utils.utils import remove_param_with_none_value # noqa: E402 -from ..module_utils.ndb.profiles.profile_types import NetworkProfile def get_module_spec(): From 7935e499f8e01571dda26bc4785a78ea00369ff6 Mon Sep 17 00:00:00 2001 From: Pradeepsingh Bhati Date: Tue, 21 Mar 2023 11:31:08 +0530 Subject: [PATCH 4/4] sanity fix --- plugins/modules/ntnx_ndb_profiles_info.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/modules/ntnx_ndb_profiles_info.py b/plugins/modules/ntnx_ndb_profiles_info.py index 0de42259d..f3a354dc3 100644 --- a/plugins/modules/ntnx_ndb_profiles_info.py +++ b/plugins/modules/ntnx_ndb_profiles_info.py @@ -46,13 +46,13 @@ - filter as per profile type type: str choices: ["Software","Compute","Network","Database_Parameter",] - include_available_ips: - description: - - include available ips for each subnet in response - - only to be used for network profiles having NDB managed subnets - - only to be used for fetching profile using C(name) or C(uuid) - default: false - type: bool + include_available_ips: + description: + - include available ips for each subnet in response + - only to be used for network profiles having NDB managed subnets + - only to be used for fetching profile using C(name) or C(uuid) + default: false + type: bool extends_documentation_fragment: - nutanix.ncp.ntnx_ndb_info_base_module author: