Debian Codegraph @

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

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