Skip to content

Commit 95dc8e7

Browse files
gmicollhercot
authored andcommitted
[minor_change] Add Match Rules for aci_route_control_profile as new Modules.
1 parent fbf5c2b commit 95dc8e7

File tree

4 files changed

+1066
-0
lines changed

4 files changed

+1066
-0
lines changed
Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
4+
# Copyright: (c) 2023, Gaspard Micol (@gmicol) <gmicol@cisco.com>
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_subject_profile
16+
short_description: Manage Match Regular Expression AS-Path Term (rtctrl:MatchAsPathRegexTerm)
17+
description:
18+
- Manage Match Rule Based on Route Regular Expression AS-Path for Subject 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+
subject_profile:
26+
description:
27+
- Name of an exising subject profile.
28+
type: str
29+
aliases: [ subject_name ]
30+
match_as_path_regex_term:
31+
description:
32+
- Name of the Match Regular Expression AS-Path Term.
33+
type: str
34+
aliases: [ name, match_rule_name ]
35+
regex:
36+
description:
37+
- The Regular Expression.
38+
type: str
39+
description:
40+
description:
41+
- The description for the Match Regular Expression 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) used must exist before using this module in your playbook.
62+
The M(cisco.aci.aci_tenant) module can be used for this.
63+
seealso:
64+
- module: cisco.aci.aci_tenant
65+
- name: APIC Management Information Model reference
66+
description: More information about the internal APIC class B(rtctrl:MatchAsPathRegexTerm).
67+
link: https://developer.cisco.com/docs/apic-mim-ref/
68+
author:
69+
- Gaspard Micol (@gmicol)
70+
"""
71+
72+
EXAMPLES = r"""
73+
"""
74+
75+
RETURN = r"""
76+
current:
77+
description: The existing configuration from the APIC after the module has finished
78+
returned: success
79+
type: list
80+
sample:
81+
[
82+
{
83+
"fvTenant": {
84+
"attributes": {
85+
"descr": "Production environment",
86+
"dn": "uni/tn-production",
87+
"name": "production",
88+
"nameAlias": "",
89+
"ownerKey": "",
90+
"ownerauto_continue": ""
91+
}
92+
}
93+
}
94+
]
95+
error:
96+
description: The error information as returned from the APIC
97+
returned: failure
98+
type: dict
99+
sample:
100+
{
101+
"code": "122",
102+
"text": "unknown managed object class foo"
103+
}
104+
raw:
105+
description: The raw output returned by the APIC REST API (xml or json)
106+
returned: parse error
107+
type: str
108+
sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
109+
sent:
110+
description: The actual/minimal configuration pushed to the APIC
111+
returned: info
112+
type: list
113+
sample:
114+
{
115+
"fvTenant": {
116+
"attributes": {
117+
"descr": "Production environment"
118+
}
119+
}
120+
}
121+
previous:
122+
description: The original configuration from the APIC before the module has started
123+
returned: info
124+
type: list
125+
sample:
126+
[
127+
{
128+
"fvTenant": {
129+
"attributes": {
130+
"descr": "Production",
131+
"dn": "uni/tn-production",
132+
"name": "production",
133+
"nameAlias": "",
134+
"ownerKey": "",
135+
"ownerauto_continue": ""
136+
}
137+
}
138+
}
139+
]
140+
proposed:
141+
description: The assembled configuration from the user-provided parameters
142+
returned: info
143+
type: dict
144+
sample:
145+
{
146+
"fvTenant": {
147+
"attributes": {
148+
"descr": "Production environment",
149+
"name": "production"
150+
}
151+
}
152+
}
153+
filter_string:
154+
description: The filter string used for the request
155+
returned: failure or debug
156+
type: str
157+
sample: ?rsp-prop-include=config-only
158+
method:
159+
description: The HTTP method used for the request to the APIC
160+
returned: failure or debug
161+
type: str
162+
sample: POST
163+
response:
164+
description: The HTTP response from the APIC
165+
returned: failure or debug
166+
type: str
167+
sample: OK (30 bytes)
168+
status:
169+
description: The HTTP status from the APIC
170+
returned: failure or debug
171+
type: int
172+
sample: 200
173+
url:
174+
description: The HTTP url used for the request to the APIC
175+
returned: failure or debug
176+
type: str
177+
sample: https://10.11.12.13/api/mo/uni/tn-production.json
178+
"""
179+
180+
from ansible.module_utils.basic import AnsibleModule
181+
from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
182+
183+
184+
def main():
185+
argument_spec = aci_argument_spec()
186+
argument_spec.update(aci_annotation_spec())
187+
argument_spec.update(aci_owner_spec())
188+
argument_spec.update(
189+
tenant=dict(type="str", aliases=["tenant_name"]), # Not required for querying all objects
190+
l3out=dict(type="str", aliases=["l3out_name"]), # Not required for querying all objects
191+
subject_profile=dict(type="str", aliases=["subject_name"]), # Not required for querying all objects
192+
match_as_path_regex_term=dict(type="str", aliases=["name", "match_rule_name"]),
193+
regex=dict(type="str"),
194+
description=dict(type="str", aliases=["descr"]),
195+
name_alias=dict(type="str"),
196+
state=dict(type="str", default="present", choices=["present", "absent", "query"]),
197+
)
198+
199+
module = AnsibleModule(
200+
argument_spec=argument_spec,
201+
supports_check_mode=True,
202+
required_if=[
203+
["state", "absent", ["match_as_path_regex_term", "tenant"]],
204+
["state", "present", ["match_as_path_regex_term", "tenant"]],
205+
],
206+
)
207+
208+
match_as_path_regex_term = module.params.get("match_as_path_regex_term")
209+
description = module.params.get("description")
210+
regex = module.params.get("regex")
211+
state = module.params.get("state")
212+
tenant = module.params.get("tenant")
213+
subject_profile = module.params.get("subject_profile")
214+
name_alias = module.params.get("name_alias")
215+
216+
aci = ACIModule(module)
217+
218+
aci.construct_url(
219+
root_class=dict(
220+
aci_class="fvTenant",
221+
aci_rn="tn-{0}".format(tenant),
222+
module_object=tenant,
223+
target_filter={"name": tenant},
224+
),
225+
subclass_1=dict(
226+
aci_class="rtctrlSubjP",
227+
aci_rn="subj-{0}".format(subject_profile),
228+
module_object=subject_profile,
229+
target_filter={"name": subject_profile},
230+
),
231+
subclass_2=dict(
232+
aci_class="rtctrlMatchAsPathRegexTerm",
233+
aci_rn="aspathrxtrm-{0}".format(match_as_path_regex_term),
234+
module_object=match_as_path_regex_term,
235+
target_filter={"name": match_as_path_regex_term},
236+
),
237+
)
238+
239+
aci.get_existing()
240+
241+
if state == "present":
242+
aci.payload(
243+
aci_class="rtctrlMatchAsPathRegexTerm",
244+
class_config=dict(
245+
name=match_as_path_regex_term,
246+
regex=regex,
247+
descr=description,
248+
nameAlias=name_alias,
249+
),
250+
)
251+
252+
aci.get_diff(aci_class="rtctrlMatchAsPathRegexTerm")
253+
254+
aci.post_config()
255+
256+
elif state == "absent":
257+
aci.delete_config()
258+
259+
aci.exit_json()
260+
261+
262+
if __name__ == "__main__":
263+
main()

0 commit comments

Comments
 (0)