Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_match_as_path_regex_term.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_match_as_path_regex_term
16 short_description: Manage Match Regular Expression AS-Path Term (rtctrl:MatchAsPathRegexTerm)
17 description:
18 - Manage Match Term Based on Route Regular Expression AS-Path for Match Rule Profiles 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 match_rule:
26 description:
27 - The name of an exising match rule profile.
28 type: str
29 aliases: [ match_rule_name ]
30 match_as_path_regex_term:
31 description:
32 - The name of the match regex AS-Path term.
33 type: str
34 aliases: [ name, match_as_path_regex_term_name ]
35 regex:
36 description:
37 - The Regular Expression.
38 type: str
39 description:
40 description:
41 - The description for the match regex AS-Path term.
42 type: str
43 aliases: [ descr ]
44 state:
45 description:
46 - Use C(present) or C(absent) for adding or removing.
47 - Use C(query) for listing an object or multiple objects.
48 type: str
49 choices: [ absent, present, query ]
50 default: present
51 name_alias:
52 description:
53 - The alias for the current object. This relates to the nameAlias field in ACI.
54 type: str
55 extends_documentation_fragment:
56 - cisco.aci.aci
57 - cisco.aci.annotation
58 - cisco.aci.owner
59
60 notes:
61 - The C(tenant) and the C(match_rule) used must exist before using this module in your playbook.
62 The M(cisco.aci.aci_tenant) and the M(cisco.aci.aci_match_rule) modules can be used for this.
63 seealso:
64 - module: cisco.aci.aci_tenant
65 - module: cisco.aci.aci_match_rule
66 - name: APIC Management Information Model reference
67 description: More information about the internal APIC class B(rtctrl:MatchAsPathRegexTerm).
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 match with AS-path regex term
75 cisco.aci.aci_match_as_path_regex_term:
76 host: apic
77 username: admin
78 password: SomeSecretPassword
79 match_rule: prod_match_rule
80 match_as_path_regex_term: prod_match_as_path_regex_term
81 regex: .*
82 tenant: production
83 state: present
84 delegate_to: localhost
85
86 - name: Delete a match with AS-path regex term
87 cisco.aci.aci_match_as_path_regex_term:
88 host: apic
89 username: admin
90 password: SomeSecretPassword
91 match_rule: prod_match_rule
92 tenant: production
93 match_as_path_regex_term: prod_match_as_path_regex_term
94 state: absent
95 delegate_to: localhost
96
97 - name: Query all match with AS-path regex terms
98 cisco.aci.aci_match_as_path_regex_term:
99 host: apic
100 username: admin
101 password: SomeSecretPassword
102 state: query
103 delegate_to: localhost
104 register: query_result
105
106 - name: Query a specific match with AS-path regex term
107 cisco.aci.aci_match_as_path_regex_term:
108 host: apic
109 username: admin
110 password: SomeSecretPassword
111 match_rule: prod_match_rule
112 tenant: production
113 match_as_path_regex_term: prod_match_as_path_regex_term
114 state: query
115 delegate_to: localhost
116 register: query_result
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 "ownerauto_continue": ""
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 "ownerauto_continue": ""
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, aci_owner_spec
226
227
228 def main():
229 argument_spec = aci_argument_spec()
230 argument_spec.update(aci_annotation_spec())
231 argument_spec.update(aci_owner_spec())
232 argument_spec.update(
233 tenant=dict(type="str", aliases=["tenant_name"]), # Not required for querying all objects
234 match_rule=dict(type="str", aliases=["match_rule_name"]), # Not required for querying all objects
235 match_as_path_regex_term=dict(type="str", aliases=["name", "match_as_path_regex_term_name"]),
236 regex=dict(type="str"),
237 description=dict(type="str", aliases=["descr"]),
238 name_alias=dict(type="str"),
239 state=dict(type="str", default="present", choices=["present", "absent", "query"]),
240 )
241
242 module = AnsibleModule(
243 argument_spec=argument_spec,
244 supports_check_mode=True,
245 required_if=[
246 ["state", "absent", ["match_as_path_regex_term", "tenant"]],
247 ["state", "present", ["match_as_path_regex_term", "tenant"]],
248 ],
249 )
250
251 match_as_path_regex_term = module.params.get("match_as_path_regex_term")
252 description = module.params.get("description")
253 regex = module.params.get("regex")
254 state = module.params.get("state")
255 tenant = module.params.get("tenant")
256 match_rule = module.params.get("match_rule")
257 name_alias = module.params.get("name_alias")
258
259 aci = ACIModule(module)
260
261 aci.construct_url(
262 root_class=dict(
263 aci_class="fvTenant",
264 aci_rn="tn-{0}".format(tenant),
265 module_object=tenant,
266 target_filter={"name": tenant},
267 ),
268 subclass_1=dict(
269 aci_class="rtctrlSubjP",
270 aci_rn="subj-{0}".format(match_rule),
271 module_object=match_rule,
272 target_filter={"name": match_rule},
273 ),
274 subclass_2=dict(
275 aci_class="rtctrlMatchAsPathRegexTerm",
276 aci_rn="aspathrxtrm-{0}".format(match_as_path_regex_term),
277 module_object=match_as_path_regex_term,
278 target_filter={"name": match_as_path_regex_term},
279 ),
280 )
281
282 aci.get_existing()
283
284 if state == "present":
285 aci.payload(
286 aci_class="rtctrlMatchAsPathRegexTerm",
287 class_config=dict(
288 name=match_as_path_regex_term,
289 regex=regex,
290 descr=description,
291 nameAlias=name_alias,
292 ),
293 )
294
295 aci.get_diff(aci_class="rtctrlMatchAsPathRegexTerm")
296
297 aci.post_config()
298
299 elif state == "absent":
300 aci.delete_config()
301
302 aci.exit_json()
303
304
305 if __name__ == "__main__":
306 main()