Skip to content

Commit aa8b24c

Browse files
akinrosslhercot
authored andcommitted
[minor_change] Add support for management epg configuration in aci_dns_profile module
1 parent fe4ba0d commit aa8b24c

3 files changed

Lines changed: 157 additions & 3 deletions

File tree

plugins/module_utils/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,3 +439,5 @@
439439
]
440440

441441
MATCH_ACCESS_POLICIES_SELECTOR_TYPE = dict(range="range", all="ALL")
442+
443+
MANAGEMENT_EPG_TYPE = dict(ooband="oob", inband="inb")

plugins/modules/aci_dns_profile.py

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# -*- coding: utf-8 -*-
33

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

78
from __future__ import absolute_import, division, print_function
@@ -22,6 +23,19 @@
2223
- Name of the DNS profile.
2324
type: str
2425
aliases: [ name, profile_name ]
26+
management_epg:
27+
description:
28+
- Name of the management EPG.
29+
- Specify C("") to remove the management EPG configuration.
30+
type: str
31+
aliases: [ epg ]
32+
management_epg_type:
33+
description:
34+
- The type of the management EPG.
35+
type: str
36+
choices: [ inband, ooband ]
37+
aliases: [ type ]
38+
default: ooband
2539
state:
2640
description:
2741
- Use C(present) or C(absent) for adding or removing.
@@ -39,6 +53,7 @@
3953
link: https://developer.cisco.com/docs/apic-mim-ref/
4054
author:
4155
- Tim Cragg (@timcragg)
56+
- Akini Ross (@akinross)
4257
"""
4358

4459
EXAMPLES = r"""
@@ -51,13 +66,35 @@
5166
state: present
5267
delegate_to: localhost
5368
54-
- name: Remove a DNS profile
69+
- name: Add a new DNS profile with a inband management EPG
5570
cisco.aci.aci_dns_profile:
5671
host: apic
5772
username: admin
5873
password: SomeSecretPassword
5974
dns_profile: my_dns_prof
60-
state: absent
75+
management_epg: ansible_mgmt_epg_inband
76+
management_epg_type: inband
77+
state: present
78+
delegate_to: localhost
79+
80+
- name: Add a new DNS profile with a out-of-band management EPG
81+
cisco.aci.aci_dns_profile:
82+
host: apic
83+
username: admin
84+
password: SomeSecretPassword
85+
dns_profile: my_dns_prof
86+
management_epg: ansible_mgmt_epg_ooband
87+
state: present
88+
delegate_to: localhost
89+
90+
- name: Remove a management EPG from a DNS profile
91+
cisco.aci.aci_dns_profile:
92+
host: apic
93+
username: admin
94+
password: SomeSecretPassword
95+
dns_profile: my_dns_prof
96+
management_epg: ""
97+
state: present
6198
delegate_to: localhost
6299
63100
- name: Query a DNS profile
@@ -78,6 +115,15 @@
78115
state: query
79116
delegate_to: localhost
80117
register: query_result
118+
119+
- name: Remove a DNS profile
120+
cisco.aci.aci_dns_profile:
121+
host: apic
122+
username: admin
123+
password: SomeSecretPassword
124+
dns_profile: my_dns_prof
125+
state: absent
126+
delegate_to: localhost
81127
"""
82128

83129
RETURN = r"""
@@ -187,13 +233,16 @@
187233

188234
from ansible.module_utils.basic import AnsibleModule
189235
from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
236+
from ansible_collections.cisco.aci.plugins.module_utils.constants import MANAGEMENT_EPG_TYPE
190237

191238

192239
def main():
193240
argument_spec = aci_argument_spec()
194241
argument_spec.update(aci_annotation_spec())
195242
argument_spec.update(
196243
dns_profile=dict(type="str", aliases=["name", "profile_name"]),
244+
management_epg=dict(type="str", aliases=["epg"]),
245+
management_epg_type=dict(type="str", default="ooband", choices=["inband", "ooband"], aliases=["type"]),
197246
state=dict(type="str", default="present", choices=["absent", "present", "query"]),
198247
)
199248

@@ -207,8 +256,10 @@ def main():
207256
)
208257

209258
dns_profile = module.params.get("dns_profile")
259+
management_epg = module.params.get("management_epg")
260+
management_epg_type = MANAGEMENT_EPG_TYPE.get(module.params.get("management_epg_type"))
210261
state = module.params.get("state")
211-
child_classes = ["dnsProv", "dnsDomain"]
262+
child_classes = ["dnsProv", "dnsDomain", "dnsRsProfileToEpg"]
212263

213264
aci = ACIModule(module)
214265
aci.construct_url(
@@ -224,9 +275,35 @@ def main():
224275
aci.get_existing()
225276

226277
if state == "present":
278+
279+
child_configs = []
280+
if management_epg is not None:
281+
if management_epg == "":
282+
child_configs.append(
283+
dict(
284+
dnsRsProfileToEpg=dict(
285+
attributes=dict(
286+
tDn="",
287+
status="deleted",
288+
)
289+
)
290+
)
291+
)
292+
else:
293+
child_configs.append(
294+
dict(
295+
dnsRsProfileToEpg=dict(
296+
attributes=dict(
297+
tDn="uni/tn-mgmt/mgmtp-default/{0}-{1}".format(management_epg_type, management_epg),
298+
)
299+
)
300+
)
301+
)
302+
227303
aci.payload(
228304
aci_class="dnsProfile",
229305
class_config=dict(name=dns_profile),
306+
child_configs=child_configs,
230307
)
231308

232309
aci.get_diff(aci_class="dnsProfile")

tests/integration/targets/aci_dns_profile/tasks/main.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Test code for the ACI modules
22
# Copyright: (c) 2021, Tim Cragg (@timcragg)
3+
# Copyright: (c) 2024, Akini Ross (@akinross)
34

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

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

24+
# CLEAN DNS PROFILES
25+
- name: Remove DNS profiles before testing
26+
cisco.aci.aci_dns_profile:
27+
<<: *aci_info
28+
profile_name: "{{ item }}"
29+
state: absent
30+
loop:
31+
- ansible_dns_profile
32+
- ansible_dns_profile_mamagement_epg
33+
2334
# ADD DNS PROFILE
2435
- name: Add DNS profile
2536
cisco.aci.aci_dns_profile:
@@ -51,6 +62,70 @@
5162
- add_dns_profile_again.current.0.dnsProfile.attributes.dn == "uni/fabric/dnsp-ansible_dns_profile"
5263
- add_dns_profile_again.current.0.dnsProfile.attributes.name == "ansible_dns_profile"
5364

65+
# ADD MGMT EPG TO DNS PROFILE
66+
67+
- name: Add ooband management EPG to DNS profile (check-mode)
68+
cisco.aci.aci_dns_profile: &aci_dns_profile_ooband
69+
<<: *aci_info
70+
profile_name: ansible_dns_profile_mamagement_epg
71+
management_epg: ansible_mgmt_epg_ooband
72+
state: present
73+
check_mode: yes
74+
register: cm_add_ooband_mgmt_epg_to_dns_profile
75+
76+
- name: Add ooband management EPG to DNS profile
77+
cisco.aci.aci_dns_profile:
78+
<<: *aci_dns_profile_ooband
79+
state: present
80+
register: nm_add_ooband_mgmt_epg_to_dns_profile
81+
82+
- name: Add ooband management EPG to DNS profile again to test idempotence
83+
cisco.aci.aci_dns_profile:
84+
<<: *aci_dns_profile_ooband
85+
state: present
86+
register: nm_add_ooband_mgmt_epg_to_dns_profile_again
87+
88+
- name: Update ooband management EPG to inband management EPG
89+
cisco.aci.aci_dns_profile:
90+
<<: *aci_dns_profile_ooband
91+
management_epg: ansible_mgmt_epg_inband
92+
management_epg_type: inband
93+
state: present
94+
register: nm_update_ooband_mgmt_epg_to_inband_mgmt_epg
95+
96+
- name: Remove management EPG from DNS profile
97+
cisco.aci.aci_dns_profile:
98+
<<: *aci_dns_profile_ooband
99+
management_epg: ""
100+
state: present
101+
register: nm_remove_inband_mgmt_epg_from_dns_profile
102+
103+
- name: Verify DNS profile with management EPGs
104+
ansible.builtin.assert:
105+
that:
106+
- cm_add_ooband_mgmt_epg_to_dns_profile is changed
107+
- cm_add_ooband_mgmt_epg_to_dns_profile.previous == []
108+
- cm_add_ooband_mgmt_epg_to_dns_profile.proposed.dnsProfile.attributes.name == "ansible_dns_profile_mamagement_epg"
109+
- 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"
110+
- nm_add_ooband_mgmt_epg_to_dns_profile is changed
111+
- nm_add_ooband_mgmt_epg_to_dns_profile.previous == []
112+
- nm_add_ooband_mgmt_epg_to_dns_profile.current.0.dnsProfile.attributes.name == "ansible_dns_profile_mamagement_epg"
113+
- 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"
114+
- nm_add_ooband_mgmt_epg_to_dns_profile_again is not changed
115+
- nm_add_ooband_mgmt_epg_to_dns_profile_again.previous.0.dnsProfile.attributes.name == "ansible_dns_profile_mamagement_epg"
116+
- 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"
117+
- nm_add_ooband_mgmt_epg_to_dns_profile_again.current.0.dnsProfile.attributes.name == "ansible_dns_profile_mamagement_epg"
118+
- 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"
119+
- nm_update_ooband_mgmt_epg_to_inband_mgmt_epg is changed
120+
- nm_update_ooband_mgmt_epg_to_inband_mgmt_epg.previous.0.dnsProfile.attributes.name == "ansible_dns_profile_mamagement_epg"
121+
- 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"
122+
- nm_update_ooband_mgmt_epg_to_inband_mgmt_epg.current.0.dnsProfile.attributes.name == "ansible_dns_profile_mamagement_epg"
123+
- 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"
124+
- nm_remove_inband_mgmt_epg_from_dns_profile is changed
125+
- nm_remove_inband_mgmt_epg_from_dns_profile.previous.0.dnsProfile.attributes.name == "ansible_dns_profile_mamagement_epg"
126+
- 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"
127+
- nm_remove_inband_mgmt_epg_from_dns_profile.current.0.dnsProfile.children.0.dnsRsProfileToEpg is not defined
128+
54129
# QUERY DNS PROFILE
55130
- name: Query the DNS profile
56131
cisco.aci.aci_dns_profile:

0 commit comments

Comments
 (0)