Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright: (c) 2022, Akini Ross (@akinross)
4
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_tenant_span_src_group_src
16 short_description: Manage SPAN source group sources (span:Src)
17 description:
18 - Manage SPAN source group sources on Cisco ACI fabrics.
19 options:
20 name:
21 description:
22 - The name of the Span source.
23 type: str
24 description:
25 description:
26 - The description for Span source.
27 type: str
28 aliases: [ descr ]
29 src_group:
30 description:
31 - The name of the Span source group.
32 type: str
33 tenant:
34 description:
35 - The name of the Tenant.
36 type: str
37 aliases: [ tenant_name ]
38 direction:
39 description:
40 - The direction of the SPAN source.
41 type: str
42 choices: [ incoming, outgoing, both ]
43 src_epg:
44 description:
45 - The name of the Span source epg.
46 type: str
47 aliases: [ epg ]
48 src_ap:
49 description:
50 - The name of the Span source ap.
51 type: str
52 aliases: [ ap ]
53 state:
54 description:
55 - Use C(present) or C(absent) for adding or removing.
56 - Use C(query) for listing an object or multiple objects.
57 type: str
58 choices: [ absent, present, query ]
59 default: present
60
61 extends_documentation_fragment:
62 - cisco.aci.aci
63 - cisco.aci.annotation
64 - cisco.aci.owner
65
66 notes:
67 - The C(tenant) used must exist before using this module in your playbook.
68 The M(cisco.aci.aci_tenant) module can be used for this.
69 seealso:
70 - module: cisco.aci.aci_tenant
71 - name: APIC Management Information Model reference
72 description: More information about the internal APIC class B(span:SrcGrp).
73 link: https://developer.cisco.com/docs/apic-mim-ref/
74 author:
75 - Akini Ross (@akinross)
76 """
77
78 EXAMPLES = r"""
79 - name: Create a SPAN source
80 cisco.aci.aci_tenant_span_src_group_src:
81 host: apic
82 username: admin
83 password: SomeSecretPassword
84 src_group: my_span_source_group
85 tenant: prod
86 name: test
87 direction: incoming
88 src_epg: epg1
89 state: present
90 delegate_to: localhost
91
92 - name: Delete a SPAN source
93 cisco.aci.aci_tenant_span_src_group_src:
94 host: apic
95 username: admin
96 password: SomeSecretPassword
97 src_group: my_span_source_group
98 tenant: prod
99 name: test
100 state: absent
101 delegate_to: localhost
102
103 - name: Query all SPAN sources
104 cisco.aci.aci_tenant_span_src_group_src:
105 host: apic
106 username: admin
107 password: SomeSecretPassword
108 state: query
109 delegate_to: localhost
110 register: query_result
111
112 - name: Query a specific SPAN source
113 cisco.aci.aci_tenant_span_src_group_src:
114 host: apic
115 username: admin
116 password: SomeSecretPassword
117 name: test
118 state: query
119 delegate_to: localhost
120 register: query_result
121 """
122
123 RETURN = r"""
124 current:
125 description: The existing configuration from the APIC after the module has finished
126 returned: success
127 type: list
128 sample:
129 [
130 {
131 "fvTenant": {
132 "attributes": {
133 "descr": "Production environment",
134 "dn": "uni/tn-production",
135 "name": "production",
136 "nameAlias": "",
137 "ownerKey": "",
138 "ownerTag": ""
139 }
140 }
141 }
142 ]
143 error:
144 description: The error information as returned from the APIC
145 returned: failure
146 type: dict
147 sample:
148 {
149 "code": "122",
150 "text": "unknown managed object class foo"
151 }
152 raw:
153 description: The raw output returned by the APIC REST API (xml or json)
154 returned: parse error
155 type: str
156 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
157 sent:
158 description: The actual/minimal configuration pushed to the APIC
159 returned: info
160 type: list
161 sample:
162 {
163 "fvTenant": {
164 "attributes": {
165 "descr": "Production environment"
166 }
167 }
168 }
169 previous:
170 description: The original configuration from the APIC before the module has started
171 returned: info
172 type: list
173 sample:
174 [
175 {
176 "fvTenant": {
177 "attributes": {
178 "descr": "Production",
179 "dn": "uni/tn-production",
180 "name": "production",
181 "nameAlias": "",
182 "ownerKey": "",
183 "ownerTag": ""
184 }
185 }
186 }
187 ]
188 proposed:
189 description: The assembled configuration from the user-provided parameters
190 returned: info
191 type: dict
192 sample:
193 {
194 "fvTenant": {
195 "attributes": {
196 "descr": "Production environment",
197 "name": "production"
198 }
199 }
200 }
201 filter_string:
202 description: The filter string used for the request
203 returned: failure or debug
204 type: str
205 sample: ?rsp-prop-include=config-only
206 method:
207 description: The HTTP method used for the request to the APIC
208 returned: failure or debug
209 type: str
210 sample: POST
211 response:
212 description: The HTTP response from the APIC
213 returned: failure or debug
214 type: str
215 sample: OK (30 bytes)
216 status:
217 description: The HTTP status from the APIC
218 returned: failure or debug
219 type: int
220 sample: 200
221 url:
222 description: The HTTP url used for the request to the APIC
223 returned: failure or debug
224 type: str
225 sample: https://10.11.12.13/api/mo/uni/tn-production.json
226 """
227
228 from ansible.module_utils.basic import AnsibleModule
229 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
230 from ansible_collections.cisco.aci.plugins.module_utils.constants import SPAN_DIRECTION_MAP
231
232
233 def main():
234 argument_spec = aci_argument_spec()
235 argument_spec.update(aci_annotation_spec())
236 argument_spec.update(aci_owner_spec())
237 argument_spec.update(
238 description=dict(type="str", aliases=["descr"]),
239 direction=dict(type="str", choices=list(SPAN_DIRECTION_MAP.keys())),
240 name=dict(type="str"), # Not required for querying all objects
241 src_ap=dict(type="str", aliases=["ap"]),
242 src_epg=dict(type="str", aliases=["epg"]),
243 src_group=dict(type="str"), # Not required for querying all objects
244 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
245 tenant=dict(type="str", aliases=["tenant_name"]), # Not required for querying all objects
246 )
247
248 module = AnsibleModule(
249 argument_spec=argument_spec,
250 supports_check_mode=True,
251 required_if=[
252 ["state", "absent", ["name", "src_group", "tenant"]],
253 ["state", "present", ["name", "direction", "src_group", "tenant"]],
254 ],
255 required_together=[("src_ap", "src_epg")],
256 )
257
258 aci = ACIModule(module)
259
260 description = module.params.get("description")
261 direction = module.params.get("direction")
262 name = module.params.get("name")
263 src_ap = module.params.get("src_ap")
264 src_epg = module.params.get("src_epg")
265 src_group = module.params.get("src_group")
266 state = module.params.get("state")
267 tenant = module.params.get("tenant")
268
269 aci.construct_url(
270 root_class=dict(
271 aci_class="fvTenant",
272 aci_rn="tn-{0}".format(tenant),
273 module_object=tenant,
274 target_filter={"name": tenant},
275 ),
276 subclass_1=dict(
277 aci_class="spanSrcGrp",
278 aci_rn="srcgrp-{0}".format(src_group),
279 module_object=src_group,
280 target_filter={"name": src_group},
281 ),
282 subclass_2=dict(
283 aci_class="spanSrc",
284 aci_rn="src-{0}".format(name),
285 module_object=name,
286 target_filter={"name": name},
287 ),
288 child_classes=["spanRsSrcToEpg"],
289 )
290
291 aci.get_existing()
292
293 if state == "present":
294 tdn = None
295 if src_epg:
296 tdn = "uni/tn-{0}/ap-{1}/epg-{2}".format(tenant, src_ap, src_epg)
297
298 aci.payload(
299 aci_class="spanSrc",
300 class_config=dict(descr=description, name=name, dir=SPAN_DIRECTION_MAP.get(direction)),
301 child_configs=[{"spanRsSrcToEpg": {"attributes": {"tDn": tdn}}}],
302 )
303
304 aci.get_diff(aci_class="spanSrc")
305
306 aci.post_config()
307
308 elif state == "absent":
309 aci.delete_config()
310
311 aci.exit_json()
312
313
314 if __name__ == "__main__":
315 main()