Debian Codegraph @

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