Debian Codegraph @

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

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