Skip to content

Commit

Permalink
[minor_change] Add support for management epg configuration in aci_dn…
Browse files Browse the repository at this point in the history
…s_profile module
  • Loading branch information
akinross authored and lhercot committed Oct 17, 2024
1 parent fe4ba0d commit aa8b24c
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 3 deletions.
2 changes: 2 additions & 0 deletions plugins/module_utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,3 +439,5 @@
]

MATCH_ACCESS_POLICIES_SELECTOR_TYPE = dict(range="range", all="ALL")

MANAGEMENT_EPG_TYPE = dict(ooband="oob", inband="inb")
83 changes: 80 additions & 3 deletions plugins/modules/aci_dns_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

# Copyright: (c) 2022, Tim Cragg (@timcragg)
# Copyright: (c) 2024, Akini Ross (@akinross)
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
Expand All @@ -22,6 +23,19 @@
- Name of the DNS profile.
type: str
aliases: [ name, profile_name ]
management_epg:
description:
- Name of the management EPG.
- Specify C("") to remove the management EPG configuration.
type: str
aliases: [ epg ]
management_epg_type:
description:
- The type of the management EPG.
type: str
choices: [ inband, ooband ]
aliases: [ type ]
default: ooband
state:
description:
- Use C(present) or C(absent) for adding or removing.
Expand All @@ -39,6 +53,7 @@
link: https://developer.cisco.com/docs/apic-mim-ref/
author:
- Tim Cragg (@timcragg)
- Akini Ross (@akinross)
"""

EXAMPLES = r"""
Expand All @@ -51,13 +66,35 @@
state: present
delegate_to: localhost
- name: Remove a DNS profile
- name: Add a new DNS profile with a inband management EPG
cisco.aci.aci_dns_profile:
host: apic
username: admin
password: SomeSecretPassword
dns_profile: my_dns_prof
state: absent
management_epg: ansible_mgmt_epg_inband
management_epg_type: inband
state: present
delegate_to: localhost
- name: Add a new DNS profile with a out-of-band management EPG
cisco.aci.aci_dns_profile:
host: apic
username: admin
password: SomeSecretPassword
dns_profile: my_dns_prof
management_epg: ansible_mgmt_epg_ooband
state: present
delegate_to: localhost
- name: Remove a management EPG from a DNS profile
cisco.aci.aci_dns_profile:
host: apic
username: admin
password: SomeSecretPassword
dns_profile: my_dns_prof
management_epg: ""
state: present
delegate_to: localhost
- name: Query a DNS profile
Expand All @@ -78,6 +115,15 @@
state: query
delegate_to: localhost
register: query_result
- name: Remove a DNS profile
cisco.aci.aci_dns_profile:
host: apic
username: admin
password: SomeSecretPassword
dns_profile: my_dns_prof
state: absent
delegate_to: localhost
"""

RETURN = r"""
Expand Down Expand Up @@ -187,13 +233,16 @@

from ansible.module_utils.basic import AnsibleModule
from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
from ansible_collections.cisco.aci.plugins.module_utils.constants import MANAGEMENT_EPG_TYPE


def main():
argument_spec = aci_argument_spec()
argument_spec.update(aci_annotation_spec())
argument_spec.update(
dns_profile=dict(type="str", aliases=["name", "profile_name"]),
management_epg=dict(type="str", aliases=["epg"]),
management_epg_type=dict(type="str", default="ooband", choices=["inband", "ooband"], aliases=["type"]),
state=dict(type="str", default="present", choices=["absent", "present", "query"]),
)

Expand All @@ -207,8 +256,10 @@ def main():
)

dns_profile = module.params.get("dns_profile")
management_epg = module.params.get("management_epg")
management_epg_type = MANAGEMENT_EPG_TYPE.get(module.params.get("management_epg_type"))
state = module.params.get("state")
child_classes = ["dnsProv", "dnsDomain"]
child_classes = ["dnsProv", "dnsDomain", "dnsRsProfileToEpg"]

aci = ACIModule(module)
aci.construct_url(
Expand All @@ -224,9 +275,35 @@ def main():
aci.get_existing()

if state == "present":

child_configs = []
if management_epg is not None:
if management_epg == "":
child_configs.append(
dict(
dnsRsProfileToEpg=dict(
attributes=dict(
tDn="",
status="deleted",
)
)
)
)
else:
child_configs.append(
dict(
dnsRsProfileToEpg=dict(
attributes=dict(
tDn="uni/tn-mgmt/mgmtp-default/{0}-{1}".format(management_epg_type, management_epg),
)
)
)
)

aci.payload(
aci_class="dnsProfile",
class_config=dict(name=dns_profile),
child_configs=child_configs,
)

aci.get_diff(aci_class="dnsProfile")
Expand Down
75 changes: 75 additions & 0 deletions tests/integration/targets/aci_dns_profile/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Test code for the ACI modules
# Copyright: (c) 2021, Tim Cragg (@timcragg)
# Copyright: (c) 2024, Akini Ross (@akinross)

# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)

Expand All @@ -20,6 +21,16 @@
use_proxy: '{{ aci_use_proxy | default(true) }}'
output_level: debug

# CLEAN DNS PROFILES
- name: Remove DNS profiles before testing
cisco.aci.aci_dns_profile:
<<: *aci_info
profile_name: "{{ item }}"
state: absent
loop:
- ansible_dns_profile
- ansible_dns_profile_mamagement_epg

# ADD DNS PROFILE
- name: Add DNS profile
cisco.aci.aci_dns_profile:
Expand Down Expand Up @@ -51,6 +62,70 @@
- add_dns_profile_again.current.0.dnsProfile.attributes.dn == "uni/fabric/dnsp-ansible_dns_profile"
- add_dns_profile_again.current.0.dnsProfile.attributes.name == "ansible_dns_profile"

# ADD MGMT EPG TO DNS PROFILE

- name: Add ooband management EPG to DNS profile (check-mode)
cisco.aci.aci_dns_profile: &aci_dns_profile_ooband
<<: *aci_info
profile_name: ansible_dns_profile_mamagement_epg
management_epg: ansible_mgmt_epg_ooband
state: present
check_mode: yes
register: cm_add_ooband_mgmt_epg_to_dns_profile

- name: Add ooband management EPG to DNS profile
cisco.aci.aci_dns_profile:
<<: *aci_dns_profile_ooband
state: present
register: nm_add_ooband_mgmt_epg_to_dns_profile

- name: Add ooband management EPG to DNS profile again to test idempotence
cisco.aci.aci_dns_profile:
<<: *aci_dns_profile_ooband
state: present
register: nm_add_ooband_mgmt_epg_to_dns_profile_again

- name: Update ooband management EPG to inband management EPG
cisco.aci.aci_dns_profile:
<<: *aci_dns_profile_ooband
management_epg: ansible_mgmt_epg_inband
management_epg_type: inband
state: present
register: nm_update_ooband_mgmt_epg_to_inband_mgmt_epg

- name: Remove management EPG from DNS profile
cisco.aci.aci_dns_profile:
<<: *aci_dns_profile_ooband
management_epg: ""
state: present
register: nm_remove_inband_mgmt_epg_from_dns_profile

- name: Verify DNS profile with management EPGs
ansible.builtin.assert:
that:
- cm_add_ooband_mgmt_epg_to_dns_profile is changed
- cm_add_ooband_mgmt_epg_to_dns_profile.previous == []
- cm_add_ooband_mgmt_epg_to_dns_profile.proposed.dnsProfile.attributes.name == "ansible_dns_profile_mamagement_epg"
- cm_add_ooband_mgmt_epg_to_dns_profile.proposed.dnsProfile.children.0.dnsRsProfileToEpg.attributes.tDn == "uni/tn-mgmt/mgmtp-default/oob-ansible_mgmt_epg_ooband"
- nm_add_ooband_mgmt_epg_to_dns_profile is changed
- nm_add_ooband_mgmt_epg_to_dns_profile.previous == []
- nm_add_ooband_mgmt_epg_to_dns_profile.current.0.dnsProfile.attributes.name == "ansible_dns_profile_mamagement_epg"
- nm_add_ooband_mgmt_epg_to_dns_profile.current.0.dnsProfile.children.0.dnsRsProfileToEpg.attributes.tDn == "uni/tn-mgmt/mgmtp-default/oob-ansible_mgmt_epg_ooband"
- nm_add_ooband_mgmt_epg_to_dns_profile_again is not changed
- nm_add_ooband_mgmt_epg_to_dns_profile_again.previous.0.dnsProfile.attributes.name == "ansible_dns_profile_mamagement_epg"
- nm_add_ooband_mgmt_epg_to_dns_profile_again.previous.0.dnsProfile.children.0.dnsRsProfileToEpg.attributes.tDn == "uni/tn-mgmt/mgmtp-default/oob-ansible_mgmt_epg_ooband"
- nm_add_ooband_mgmt_epg_to_dns_profile_again.current.0.dnsProfile.attributes.name == "ansible_dns_profile_mamagement_epg"
- nm_add_ooband_mgmt_epg_to_dns_profile_again.current.0.dnsProfile.children.0.dnsRsProfileToEpg.attributes.tDn == "uni/tn-mgmt/mgmtp-default/oob-ansible_mgmt_epg_ooband"
- nm_update_ooband_mgmt_epg_to_inband_mgmt_epg is changed
- nm_update_ooband_mgmt_epg_to_inband_mgmt_epg.previous.0.dnsProfile.attributes.name == "ansible_dns_profile_mamagement_epg"
- nm_update_ooband_mgmt_epg_to_inband_mgmt_epg.previous.0.dnsProfile.children.0.dnsRsProfileToEpg.attributes.tDn == "uni/tn-mgmt/mgmtp-default/oob-ansible_mgmt_epg_ooband"
- nm_update_ooband_mgmt_epg_to_inband_mgmt_epg.current.0.dnsProfile.attributes.name == "ansible_dns_profile_mamagement_epg"
- nm_update_ooband_mgmt_epg_to_inband_mgmt_epg.current.0.dnsProfile.children.0.dnsRsProfileToEpg.attributes.tDn == "uni/tn-mgmt/mgmtp-default/inb-ansible_mgmt_epg_inband"
- nm_remove_inband_mgmt_epg_from_dns_profile is changed
- nm_remove_inband_mgmt_epg_from_dns_profile.previous.0.dnsProfile.attributes.name == "ansible_dns_profile_mamagement_epg"
- nm_remove_inband_mgmt_epg_from_dns_profile.previous.0.dnsProfile.children.0.dnsRsProfileToEpg.attributes.tDn == "uni/tn-mgmt/mgmtp-default/inb-ansible_mgmt_epg_inband"
- nm_remove_inband_mgmt_epg_from_dns_profile.current.0.dnsProfile.children.0.dnsRsProfileToEpg is not defined

# QUERY DNS PROFILE
- name: Query the DNS profile
cisco.aci.aci_dns_profile:
Expand Down

0 comments on commit aa8b24c

Please sign in to comment.