Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2023, Akini Ross <[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_fabric_span_dst_group
16 short_description: Manage Fabric SPAN destination groups (span:DestGrp)
17 description:
18 - Manage Fabric SPAN destination groups on Cisco ACI fabrics.
19 options:
20 destination_group:
21 description:
22 - The name of the Fabric SPAN destination group.
23 type: str
24 aliases: [ name, dst_group ]
25 description:
26 description:
27 - The description of the Fabric SPAN destination group.
28 type: str
29 aliases: [ descr ]
30 destination_epg:
31 description:
32 - The destination end point group.
33 type: dict
34 suboptions:
35 tenant:
36 description:
37 - The name of the tenant.
38 type: str
39 required: true
40 aliases: [ tenant_name ]
41 ap:
42 description:
43 - The name of application profile.
44 type: str
45 required: true
46 aliases: [ ap_name, app_profile, app_profile_name ]
47 epg:
48 description:
49 - The name of the end point group.
50 type: str
51 required: true
52 aliases: [ epg_name ]
53 span_version:
54 description:
55 - The SPAN version.
56 - The APIC defaults to C(version_2) when unset during creation.
57 type: str
58 choices: [ version_1, version_2 ]
59 version_enforced:
60 description:
61 - Enforce SPAN version.
62 type: bool
63 source_ip:
64 description:
65 - The source IP address or prefix.
66 type: str
67 required: true
68 destination_ip:
69 description:
70 - The destination IP address.
71 type: str
72 required: true
73 flow_id:
74 description:
75 - The flow ID of the SPAN packet.
76 - The APIC defaults to C(1) when unset during creation.
77 type: int
78 ttl:
79 description:
80 - The time to live of the SPAN session packets.
81 - The APIC defaults to C(64) when unset during creation.
82 type: int
83 mtu:
84 description:
85 - The MTU truncation size for the packets.
86 - The APIC defaults to C(1518) when unset during creation.
87 type: int
88 dscp:
89 description:
90 - The DSCP value for sending the monitored packets using ERSPAN.
91 - The APIC defaults to C(unspecified) when unset during creation.
92 type: str
93 choices: [ CS0, CS1, CS2, CS3, CS4, CS5, CS6, CS7, EF, VA, AF11, AF12, AF13, AF21, AF22, AF23, AF31, AF32, AF33, AF41, AF42, AF43, unspecified ]
94 state:
95 description:
96 - Use C(present) or C(absent) for adding or removing.
97 - Use C(query) for listing an object or multiple objects.
98 type: str
99 choices: [ absent, present, query ]
100 default: present
101 name_alias:
102 description:
103 - The alias for the current object. This relates to the nameAlias field in ACI.
104 type: str
105 extends_documentation_fragment:
106 - cisco.aci.aci
107 - cisco.aci.annotation
108 - cisco.aci.owner
109
110 seealso:
111 - name: APIC Management Information Model reference
112 description: More information about the internal APIC class B(span:DestGrp).
113 link: https://developer.cisco.com/docs/apic-mim-ref/
114 author:
115 - Akini Ross (@akinross)
116 """
117
118 EXAMPLES = r"""
119 - name: Add a Fabric SPAN destination group
120 cisco.aci.aci_fabric_span_dst_group:
121 host: apic
122 username: admin
123 password: SomeSecretPassword
124 destination_group: group1
125 description: Test span
126 destination_epg:
127 tenant: Test1
128 ap: ap1
129 epg: ep1
130 span_version: version_1
131 version_enforced: false
132 destination_ip: 10.0.0.1
133 source_ip: 10.0.2.1
134 ttl: 2
135 mtu: 1500
136 flow_id: 1
137 dscp: CS1
138 state: present
139 delegate_to: localhost
140
141 - name: Remove a Fabric SPAN destination group
142 cisco.aci.aci_fabric_span_dst_group:
143 host: apic
144 username: admin
145 password: SomeSecretPassword
146 destination_group: group1
147 state: absent
148 delegate_to: localhost
149
150 - name: Query a Fabric SPAN destination group
151 cisco.aci.aci_fabric_span_dst_group:
152 host: apic
153 username: admin
154 password: SomeSecretPassword
155 destination_group: group1
156 state: query
157 delegate_to: localhost
158 register: query_result
159
160 - name: Query all Fabric SPAN destination groups
161 cisco.aci.aci_fabric_span_dst_group:
162 host: apic
163 username: admin
164 password: SomeSecretPassword
165 state: query
166 delegate_to: localhost
167 register: query_result
168 """
169
170 RETURN = r"""
171 current:
172 description: The existing configuration from the APIC after the module has finished
173 returned: success
174 type: list
175 sample:
176 [
177 {
178 "fvTenant": {
179 "attributes": {
180 "descr": "Production environment",
181 "dn": "uni/tn-production",
182 "name": "production",
183 "nameAlias": "",
184 "ownerKey": "",
185 "ownerTag": ""
186 }
187 }
188 }
189 ]
190 error:
191 description: The error information as returned from the APIC
192 returned: failure
193 type: dict
194 sample:
195 {
196 "code": "122",
197 "text": "unknown managed object class foo"
198 }
199 raw:
200 description: The raw output returned by the APIC REST API (xml or json)
201 returned: parse error
202 type: str
203 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
204 sent:
205 description: The actual/minimal configuration pushed to the APIC
206 returned: info
207 type: list
208 sample:
209 {
210 "fvTenant": {
211 "attributes": {
212 "descr": "Production environment"
213 }
214 }
215 }
216 previous:
217 description: The original configuration from the APIC before the module has started
218 returned: info
219 type: list
220 sample:
221 [
222 {
223 "fvTenant": {
224 "attributes": {
225 "descr": "Production",
226 "dn": "uni/tn-production",
227 "name": "production",
228 "nameAlias": "",
229 "ownerKey": "",
230 "ownerTag": ""
231 }
232 }
233 }
234 ]
235 proposed:
236 description: The assembled configuration from the user-provided parameters
237 returned: info
238 type: dict
239 sample:
240 {
241 "fvTenant": {
242 "attributes": {
243 "descr": "Production environment",
244 "name": "production"
245 }
246 }
247 }
248 filter_string:
249 description: The filter string used for the request
250 returned: failure or debug
251 type: str
252 sample: ?rsp-prop-include=config-only
253 method:
254 description: The HTTP method used for the request to the APIC
255 returned: failure or debug
256 type: str
257 sample: POST
258 response:
259 description: The HTTP response from the APIC
260 returned: failure or debug
261 type: str
262 sample: OK (30 bytes)
263 status:
264 description: The HTTP status from the APIC
265 returned: failure or debug
266 type: int
267 sample: 200
268 url:
269 description: The HTTP url used for the request to the APIC
270 returned: failure or debug
271 type: str
272 sample: https://10.11.12.13/api/mo/uni/tn-production.json
273 """
274
275 from ansible.module_utils.basic import AnsibleModule
276 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec, destination_epg_spec
277
278
279 def main():
280 argument_spec = aci_argument_spec()
281 argument_spec.update(aci_annotation_spec())
282 argument_spec.update(aci_owner_spec())
283 argument_spec.update(
284 destination_group=dict(type="str", aliases=["name", "dst_group"]), # Not required for querying all objects
285 description=dict(type="str", aliases=["descr"]),
286 destination_epg=dict(type="dict", options=destination_epg_spec()),
287 name_alias=dict(type="str"),
288 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
289 )
290
291 module = AnsibleModule(
292 argument_spec=argument_spec,
293 supports_check_mode=True,
294 required_if=[
295 ["state", "absent", ["destination_group"]],
296 ["state", "present", ["destination_group", "destination_epg"]],
297 ],
298 )
299
300 aci = ACIModule(module)
301
302 destination_group = module.params.get("destination_group")
303 description = module.params.get("description")
304 destination_epg = module.params.get("destination_epg")
305 state = module.params.get("state")
306 name_alias = module.params.get("name_alias")
307
308 aci.construct_url(
309 root_class=dict(
310 aci_class="fabric",
311 aci_rn="fabric",
312 ),
313 subclass_1=dict(
314 aci_class="spanDestGrp",
315 aci_rn="destgrp-{0}".format(destination_group),
316 module_object=destination_group,
317 target_filter={"name": destination_group},
318 ),
319 child_classes=["spanDest", "spanRsDestEpg", "spanRsDestPathEp"],
320 )
321
322 aci.get_existing()
323
324 if state == "present":
325 attributes = dict(
326 tDn="uni/tn-{0}/ap-{1}/epg-{2}".format(destination_epg.get("tenant"), destination_epg.get("ap"), destination_epg.get("epg")),
327 ip=destination_epg.get("destination_ip"),
328 srcIpPrefix=destination_epg.get("source_ip"),
329 )
330 if destination_epg.get("span_version") is not None:
331 attributes["ver"] = "ver1" if destination_epg.get("span_version") == "version_1" else "ver2"
332 if destination_epg.get("version_enforced") is not None:
333 attributes["verEnforced"] = "yes" if destination_epg.get("version_enforced") else "no"
334 if destination_epg.get("ttl") is not None:
335 attributes["ttl"] = str(destination_epg.get("ttl"))
336 if destination_epg.get("mtu") is not None:
337 attributes["mtu"] = str(destination_epg.get("mtu"))
338 if destination_epg.get("flow_id") is not None:
339 attributes["flowId"] = str(destination_epg.get("flow_id"))
340 if destination_epg.get("dscp") is not None:
341 attributes["dscp"] = destination_epg.get("dscp")
342 span_rs_dest = dict(spanRsDestEpg=dict(attributes=attributes))
343
344 aci.payload(
345 aci_class="spanDestGrp",
346 class_config=dict(name=destination_group, descr=description, nameAlias=name_alias),
347 child_configs=[dict(spanDest=dict(attributes=dict(name=destination_group), children=[span_rs_dest]))],
348 )
349
350 aci.get_diff(aci_class="spanDestGrp")
351
352 aci.post_config()
353
354 elif state == "absent":
355 aci.delete_config()
356
357 aci.exit_json()
358
359
360 if __name__ == "__main__":
361 main()