Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch available IPs for network profiles in NDB #346

Merged
merged 4 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions plugins/module_utils/ndb/profiles/profile_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
14 changes: 14 additions & 0 deletions plugins/modules/ntnx_ndb_profiles_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -217,6 +225,7 @@ def get_module_spec():
type="dict",
options=filters_spec,
),
include_available_ips=dict(type="bool", default=False),
)

return module_args
Expand All @@ -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)
Expand Down
38 changes: 38 additions & 0 deletions tests/integration/targets/ntnx_ndb_profiles_info/tasks/info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down