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..f3a354dc3 100644 --- a/plugins/modules/ntnx_ndb_profiles_info.py +++ b/plugins/modules/ntnx_ndb_profiles_info.py @@ -46,6 +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 extends_documentation_fragment: - nutanix.ncp.ntnx_ndb_info_base_module author: @@ -178,6 +185,7 @@ """ 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 @@ -217,6 +225,7 @@ def get_module_spec(): type="dict", options=filters_spec, ), + include_available_ips=dict(type="bool", default=False), ) return module_args @@ -230,6 +239,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: