Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_bd_rogue_exception_mac.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2024, Samita Bhattacharjee (@samitab) <[email protected]>
5 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8
9 __metaclass__ = type
10
11 ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "certified"}
12
13 DOCUMENTATION = r"""
14 ---
15 module: aci_bd_rogue_exception_mac
16 short_description: Manage Rogue Exception MAC (fv:RogueExceptionMac)
17 description:
18 - Manage Rogue Exception MACs in BD's on Cisco ACI fabrics.
19 - Only available in APIC version 5.2 or later.
20 options:
21 bd:
22 description:
23 - The name of the Bridge Domain.
24 type: str
25 aliases: [ bd_name, bridge_domain ]
26 tenant:
27 description:
28 - The name of the Tenant.
29 type: str
30 aliases: [ tenant_name ]
31 mac:
32 description:
33 - MAC address to except from Rogue processing.
34 type: str
35 description:
36 description:
37 - The description for the Rogue Exception MAC.
38 type: str
39 aliases: [ descr ]
40 state:
41 description:
42 - Use C(present) or C(absent) for adding or removing.
43 - Use C(query) for listing an object or multiple objects.
44 type: str
45 choices: [ absent, present, query ]
46 default: present
47 extends_documentation_fragment:
48 - cisco.aci.aci
49 - cisco.aci.annotation
50
51 notes:
52 - The C(tenant) and C(bd) used must exist before using this module in your playbook.
53 The M(cisco.aci.aci_tenant) module and M(cisco.aci.aci_bd) can be used for these.
54 seealso:
55 - module: cisco.aci.aci_bd
56 - module: cisco.aci.aci_tenant
57 - name: APIC Management Information Model reference
58 description: More information about the internal APIC class B(fv:RogueExceptionMac).
59 link: https://developer.cisco.com/docs/apic-mim-ref/
60 author:
61 - Samita Bhattacharjee (@samitab)
62 """
63
64 EXAMPLES = r"""
65 - name: Create a Rogue Exception MAC
66 cisco.aci.aci_bd_rogue_exception_mac:
67 host: apic
68 username: admin
69 password: SomeSecretPassword
70 tenant: production
71 bd: database
72 mac: "AA:BB:CC:DD:EE:11"
73 description: 1st MAC
74 state: present
75 delegate_to: localhost
76
77 - name: Get all Rogue Exception MACs
78 cisco.aci.aci_bd_rogue_exception_mac:
79 host: apic
80 username: admin
81 password: SomeSecretPassword
82 state: query
83 delegate_to: localhost
84
85 - name: Get all Rogue Exception MACs in specified Tenant
86 cisco.aci.aci_bd_rogue_exception_mac:
87 host: apic
88 username: admin
89 password: SomeSecretPassword
90 tenant: production
91 state: query
92 delegate_to: localhost
93 register: query_result
94
95 - name: Get specific Rogue Exception MAC
96 cisco.aci.aci_bd_rogue_exception_mac:
97 host: apic
98 username: admin
99 password: SomeSecretPassword
100 tenant: production
101 bd: database
102 mac: "AA:BB:CC:DD:EE:11"
103 state: query
104 delegate_to: localhost
105 register: query_result
106
107 - name: Remove a Rogue Exception MAC from a Bridge Domain
108 cisco.aci.aci_bd_rogue_exception_mac:
109 host: apic
110 username: admin
111 password: SomeSecretPassword
112 tenant: production
113 bd: database
114 mac: "AA:BB:CC:DD:EE:11"
115 state: absent
116 delegate_to: localhost
117 """
118
119 RETURN = r"""
120 current:
121 description: The existing configuration from the APIC after the module has finished
122 returned: success
123 type: list
124 sample:
125 [
126 {
127 "fvTenant": {
128 "attributes": {
129 "descr": "Production environment",
130 "dn": "uni/tn-production",
131 "name": "production",
132 "nameAlias": "",
133 "ownerKey": "",
134 "ownerTag": ""
135 }
136 }
137 }
138 ]
139 error:
140 description: The error information as returned from the APIC
141 returned: failure
142 type: dict
143 sample:
144 {
145 "code": "122",
146 "text": "unknown managed object class foo"
147 }
148 raw:
149 description: The raw output returned by the APIC REST API (xml or json)
150 returned: parse error
151 type: str
152 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
153 sent:
154 description: The actual/minimal configuration pushed to the APIC
155 returned: info
156 type: list
157 sample:
158 {
159 "fvTenant": {
160 "attributes": {
161 "descr": "Production environment"
162 }
163 }
164 }
165 previous:
166 description: The original configuration from the APIC before the module has started
167 returned: info
168 type: list
169 sample:
170 [
171 {
172 "fvTenant": {
173 "attributes": {
174 "descr": "Production",
175 "dn": "uni/tn-production",
176 "name": "production",
177 "nameAlias": "",
178 "ownerKey": "",
179 "ownerTag": ""
180 }
181 }
182 }
183 ]
184 proposed:
185 description: The assembled configuration from the user-provided parameters
186 returned: info
187 type: dict
188 sample:
189 {
190 "fvTenant": {
191 "attributes": {
192 "descr": "Production environment",
193 "name": "production"
194 }
195 }
196 }
197 filter_string:
198 description: The filter string used for the request
199 returned: failure or debug
200 type: str
201 sample: ?rsp-prop-include=config-only
202 method:
203 description: The HTTP method used for the request to the APIC
204 returned: failure or debug
205 type: str
206 sample: POST
207 response:
208 description: The HTTP response from the APIC
209 returned: failure or debug
210 type: str
211 sample: OK (30 bytes)
212 status:
213 description: The HTTP status from the APIC
214 returned: failure or debug
215 type: int
216 sample: 200
217 url:
218 description: The HTTP url used for the request to the APIC
219 returned: failure or debug
220 type: str
221 sample: https://10.11.12.13/api/mo/uni/tn-production.json
222 """
223
224 from ansible.module_utils.basic import AnsibleModule
225 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
226
227
228 def main():
229 argument_spec = aci_argument_spec()
230 argument_spec.update(aci_annotation_spec())
231 argument_spec.update(
232 bd=dict(type="str", aliases=["bd_name", "bridge_domain"]), # Not required for querying all objects
233 tenant=dict(type="str", aliases=["tenant_name"]), # Not required for querying all objects
234 mac=dict(type="str"), # Not required for querying all objects
235 description=dict(type="str", aliases=["descr"]),
236 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
237 )
238
239 module = AnsibleModule(
240 argument_spec=argument_spec,
241 supports_check_mode=True,
242 required_if=[
243 ["state", "present", ["bd", "mac", "tenant"]],
244 ["state", "absent", ["bd", "mac", "tenant"]],
245 ],
246 )
247
248 aci = ACIModule(module)
249
250 description = module.params.get("description")
251 tenant = module.params.get("tenant")
252 bd = module.params.get("bd")
253 mac = module.params.get("mac")
254 state = module.params.get("state")
255
256 aci.construct_url(
257 root_class=dict(
258 aci_class="fvTenant",
259 aci_rn="tn-{0}".format(tenant),
260 module_object=tenant,
261 target_filter={"name": tenant},
262 ),
263 subclass_1=dict(
264 aci_class="fvBD",
265 aci_rn="BD-{0}".format(bd),
266 module_object=bd,
267 target_filter={"name": bd},
268 ),
269 subclass_2=dict(
270 aci_class="fvRogueExceptionMac",
271 aci_rn="rgexpmac-{0}".format(mac),
272 module_object=mac,
273 target_filter={"mac": mac},
274 ),
275 )
276
277 aci.get_existing()
278
279 if state == "present":
280 aci.payload(
281 aci_class="fvRogueExceptionMac",
282 class_config=dict(
283 descr=description,
284 mac=mac,
285 ),
286 )
287
288 aci.get_diff(aci_class="fvRogueExceptionMac")
289
290 aci.post_config()
291
292 elif state == "absent":
293 aci.delete_config()
294
295 aci.exit_json()
296
297
298 if __name__ == "__main__":
299 main()