Debian Codegraph @

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

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