Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2023, Tim Cragg (@timcragg) <[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_igmp_interface_policy
16 short_description: Manage IGMP Interface Policies (igmp:IfPol)
17 description:
18 - Manage IGMP Interface Policies on Cisco ACI fabrics.
19 options:
20 name:
21 description:
22 - The name of the IGMP Interface Policy.
23 type: str
24 tenant:
25 description:
26 - The tenant to build the IGMP Interface Policy under.
27 type: str
28 description:
29 description:
30 - The description of the IGMP Interface Policy.
31 type: str
32 group_timeout:
33 description:
34 - The IGMP group timeout in seconds.
35 - The APIC defaults to 260 when unset during creation.
36 type: int
37 query_interval:
38 description:
39 - The IGMP query interval in seconds.
40 - The APIC defaults to 125 when unset during creation.
41 type: int
42 query_response_interval:
43 description:
44 - The IGMP query response interval in seconds.
45 - The APIC defaults to 10 when unset during creation.
46 type: int
47 last_member_count:
48 description:
49 - The last member query count.
50 - The APIC defaults to 2 when unset during creation.
51 type: int
52 last_member_response:
53 description:
54 - The last member response time in seconds.
55 - The APIC defaults to 1 when unset during creation.
56 type: int
57 startup_query_count:
58 description:
59 - The Startup Query Count.
60 - The APIC defaults to 2 when unset during creation.
61 type: int
62 startup_query_interval:
63 description:
64 - The startup query interval in seconds.
65 - The APIC defaults to 31 when unset during creation.
66 type: int
67 querier_timeout:
68 description:
69 - The querier timeout in seconds.
70 - The APIC defaults to 255 when unset during creation.
71 type: int
72 robustness_variable:
73 description:
74 - The robustness factor.
75 - The APIC defaults to 2 when unset during creation.
76 type: int
77 igmp_version:
78 description:
79 - The IGMP version to run.
80 - The APIC defaults to v2 when unset during creation.
81 type: str
82 choices: [ v2, v3 ]
83 allow_v3_asm:
84 description:
85 - Enable the Allow v3 ASM option.
86 - The APIC defaults to False when unset during creation.
87 - If this parameter is set, fast_leave and report_link_local_groups must also be set.
88 type: bool
89 fast_leave:
90 description:
91 - Enable the Fast Leave option.
92 - The APIC defaults to False when unset during creation.
93 - If this parameter is set, allow_v3_asm and report_link_local_groups must also be set.
94 type: bool
95 report_link_local_groups:
96 description:
97 - Enable the Report Link Local Groups option.
98 - The APIC defaults to False when unset during creation.
99 - If this parameter is set, allow_v3_asm and fast_leave must also be set.
100 type: bool
101 state:
102 description:
103 - Use C(present) or C(absent) for adding or removing.
104 - Use C(query) for listing an object or multiple objects.
105 type: str
106 choices: [ absent, present, query ]
107 default: present
108 extends_documentation_fragment:
109 - cisco.aci.aci
110 - cisco.aci.annotation
111 - cisco.aci.owner
112
113 seealso:
114 - name: APIC Management Information Model reference
115 description: More information about the internal APIC class B(igmp:IfPol).
116 link: https://developer.cisco.com/docs/apic-mim-ref/
117
118 author:
119 - Tim Cragg (@timcragg)
120 """
121
122 EXAMPLES = r"""
123 - name: Add an IGMP Interface Policy
124 cisco.aci.aci_igmp_interface_policy:
125 host: apic
126 username: admin
127 password: SomeSecretPassword
128 name: ans_igmp_intf_pol
129 query_interval: 200
130 state: present
131 delegate_to: localhost
132
133 - name: Query an IGMP Interface Policy
134 cisco.aci.aci_igmp_interface_policy:
135 host: apic
136 username: admin
137 password: SomeSecretPassword
138 name: ans_igmp_intf_pol
139 state: query
140 delegate_to: localhost
141
142 - name: Query all IGMP Interface Policies
143 cisco.aci.aci_igmp_interface_policy:
144 host: apic
145 username: admin
146 password: SomeSecretPassword
147 state: query
148 delegate_to: localhost
149
150 - name: Remove an IGMP Interface Policy
151 cisco.aci.aci_igmp_interface_policy:
152 host: apic
153 username: admin
154 password: SomeSecretPassword
155 name: ans_igmp_intf_pol
156 state: absent
157 delegate_to: localhost
158 """
159
160 RETURN = r"""
161 current:
162 description: The existing configuration from the APIC after the module has finished
163 returned: success
164 type: list
165 sample:
166 [
167 {
168 "fvTenant": {
169 "attributes": {
170 "descr": "Production environment",
171 "dn": "uni/tn-production",
172 "name": "production",
173 "nameAlias": "",
174 "ownerKey": "",
175 "ownerTag": ""
176 }
177 }
178 }
179 ]
180 error:
181 description: The error information as returned from the APIC
182 returned: failure
183 type: dict
184 sample:
185 {
186 "code": "122",
187 "text": "unknown managed object class foo"
188 }
189 raw:
190 description: The raw output returned by the APIC REST API (xml or json)
191 returned: parse error
192 type: str
193 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
194 sent:
195 description: The actual/minimal configuration pushed to the APIC
196 returned: info
197 type: list
198 sample:
199 {
200 "fvTenant": {
201 "attributes": {
202 "descr": "Production environment"
203 }
204 }
205 }
206 previous:
207 description: The original configuration from the APIC before the module has started
208 returned: info
209 type: list
210 sample:
211 [
212 {
213 "fvTenant": {
214 "attributes": {
215 "descr": "Production",
216 "dn": "uni/tn-production",
217 "name": "production",
218 "nameAlias": "",
219 "ownerKey": "",
220 "ownerTag": ""
221 }
222 }
223 }
224 ]
225 proposed:
226 description: The assembled configuration from the user-provided parameters
227 returned: info
228 type: dict
229 sample:
230 {
231 "fvTenant": {
232 "attributes": {
233 "descr": "Production environment",
234 "name": "production"
235 }
236 }
237 }
238 filter_string:
239 description: The filter string used for the request
240 returned: failure or debug
241 type: str
242 sample: ?rsp-prop-include=config-only
243 method:
244 description: The HTTP method used for the request to the APIC
245 returned: failure or debug
246 type: str
247 sample: POST
248 response:
249 description: The HTTP response from the APIC
250 returned: failure or debug
251 type: str
252 sample: OK (30 bytes)
253 status:
254 description: The HTTP status from the APIC
255 returned: failure or debug
256 type: int
257 sample: 200
258 url:
259 description: The HTTP url used for the request to the APIC
260 returned: failure or debug
261 type: str
262 sample: https://10.11.12.13/api/mo/uni/tn-production.json
263 """
264
265 from ansible.module_utils.basic import AnsibleModule
266 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
267
268
269 def main():
270 argument_spec = aci_argument_spec()
271 argument_spec.update(aci_annotation_spec())
272 argument_spec.update(aci_owner_spec())
273 argument_spec.update(
274 name=dict(type="str"),
275 tenant=dict(type="str"),
276 description=dict(type="str"),
277 group_timeout=dict(type="int"),
278 query_interval=dict(type="int"),
279 query_response_interval=dict(type="int"),
280 last_member_count=dict(type="int"),
281 last_member_response=dict(type="int"),
282 startup_query_count=dict(type="int"),
283 startup_query_interval=dict(type="int"),
284 querier_timeout=dict(type="int"),
285 robustness_variable=dict(type="int"),
286 igmp_version=dict(type="str", choices=["v2", "v3"]),
287 allow_v3_asm=dict(type="bool"),
288 fast_leave=dict(type="bool"),
289 report_link_local_groups=dict(type="bool"),
290 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
291 )
292
293 module = AnsibleModule(
294 argument_spec=argument_spec,
295 supports_check_mode=True,
296 required_if=[
297 ["state", "present", ["name", "tenant"]],
298 ["state", "absent", ["name", "tenant"]],
299 ],
300 required_together=[
301 ["allow_v3_asm", "fast_leave", "report_link_local_groups"],
302 ],
303 )
304
305 aci = ACIModule(module)
306
307 name = module.params.get("name")
308 tenant = module.params.get("tenant")
309 description = module.params.get("description")
310 group_timeout = module.params.get("group_timeout")
311 query_interval = module.params.get("query_interval")
312 query_response_interval = module.params.get("query_response_interval")
313 last_member_count = module.params.get("last_member_count")
314 last_member_response = module.params.get("last_member_response")
315 startup_query_count = module.params.get("startup_query_count")
316 startup_query_interval = module.params.get("startup_query_interval")
317 querier_timeout = module.params.get("querier_timeout")
318 robustness_variable = module.params.get("robustness_variable")
319 igmp_version = module.params.get("igmp_version")
320 allow_v3_asm = module.params.get("allow_v3_asm")
321 fast_leave = module.params.get("fast_leave")
322 report_link_local_groups = module.params.get("report_link_local_groups")
323 state = module.params.get("state")
324
325 aci.construct_url(
326 root_class=dict(
327 aci_class="fvTenant",
328 aci_rn="tn-{0}".format(tenant),
329 module_object=tenant,
330 target_filter={"name": tenant},
331 ),
332 subclass_1=dict(
333 aci_class="igmpIfPol",
334 aci_rn="igmpIfPol-{0}".format(name),
335 module_object=name,
336 target_filter={"name": name},
337 ),
338 )
339 aci.get_existing()
340
341 if state == "present":
342 if allow_v3_asm is not None:
343 if_ctrl_list = []
344 if allow_v3_asm:
345 if_ctrl_list.append("allow-v3-asm")
346 if fast_leave:
347 if_ctrl_list.append("fast-leave")
348 if report_link_local_groups:
349 if_ctrl_list.append("rep-ll")
350 if_ctrl = ",".join(if_ctrl_list)
351 else:
352 if_ctrl = None
353
354 aci.payload(
355 aci_class="igmpIfPol",
356 class_config=dict(
357 name=name,
358 descr=description,
359 grpTimeout=group_timeout,
360 ifCtrl=if_ctrl,
361 lastMbrCnt=last_member_count,
362 lastMbrRespTime=last_member_response,
363 querierTimeout=querier_timeout,
364 queryIntvl=query_interval,
365 robustFac=robustness_variable,
366 rspIntvl=query_response_interval,
367 startQueryCnt=startup_query_count,
368 startQueryIntvl=startup_query_interval,
369 ver=igmp_version,
370 ),
371 )
372
373 aci.get_diff(aci_class="igmpIfPol")
374 aci.post_config()
375
376 elif state == "absent":
377 aci.delete_config()
378
379 aci.exit_json()
380
381
382 if __name__ == "__main__":
383 main()