Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2023, Anvitha Jain <[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_interface_policy_spine_policy_group
16 short_description: Manage spine access interface policy groups (infra:SpAccPortGrp)
17 description:
18 - Manage spine access interface policy groups on Cisco ACI fabrics.
19 options:
20 policy_group:
21 description:
22 - The name of the spine access interface policy group.
23 type: str
24 aliases: [ name, policy_group_name, spine_policy_group_name ]
25 description:
26 description:
27 - Description of the spine access interface
28 type: str
29 aliases: [ descr ]
30 name_alias:
31 description:
32 - The alias of the current object. This relates to the nameAlias field in ACI.
33 type: str
34 link_level_policy:
35 description:
36 - The name of the link level policy used by the spine access interface
37 type: str
38 aliases: [ link_level_policy_name ]
39 link_flap_policy:
40 description:
41 - The name of the link flap policy used by the spine access interface
42 type: str
43 aliases: [ link_flap_policy_name ]
44 cdp_policy:
45 description:
46 - The name of the cdp policy used by the spine access interface
47 type: str
48 aliases: [ cdp_policy_name ]
49 mac_sec_policy:
50 description:
51 - The name of the mac sec policy used by the spine access interface
52 type: str
53 aliases: [ mac_sec_policy_name ]
54 attached_entity_profile:
55 description:
56 - The name of the attached entity profile used by the spine access interface
57 type: str
58 aliases: [ aep_name, aep ]
59 state:
60 description:
61 - Use C(present) or C(absent) for adding or removing.
62 - Use C(query) for listing an object or multiple objects.
63 type: str
64 choices: [ absent, present, query ]
65 default: present
66 extends_documentation_fragment:
67 - cisco.aci.aci
68 - cisco.aci.annotation
69 - cisco.aci.owner
70
71 notes:
72 seealso:
73 - name: APIC Management Information Model reference
74 description: More information about the internal APIC classes B(infra:SpAccPortGrp).
75 link: https://developer.cisco.com/docs/apic-mim-ref/
76 author:
77 - Anvitha Jain (@anvjain)
78 """
79
80 EXAMPLES = r"""
81 - name: Create a Spine Interface Policy Group
82 cisco.aci.aci_interface_policy_spine_policy_group:
83 host: apic
84 username: admin
85 password: SomeSecretPassword
86 name: spinepolicygroupname
87 description: policygroupname description
88 link_level_policy: somelinklevelpolicy
89 link_flap_policy: somelinkflappolicy
90 cdp_policy: somecdppolicy
91 mac_sec_policy: somemacsecpolicy
92 attached_entity_profile: someattachedentityprofile
93 state: present
94 delegate_to: localhost
95
96 - name: Query all Spine Access Port Policy Groups of type link
97 cisco.aci.aci_interface_policy_spine_policy_group:
98 host: apic
99 username: admin
100 password: SomeSecretPassword
101 state: query
102 delegate_to: localhost
103 register: query_result
104
105 - name: Query a specific Lead Access Port Policy Group
106 cisco.aci.aci_interface_policy_spine_policy_group:
107 host: apic
108 username: admin
109 password: SomeSecretPassword
110 name: spinepolicygroupname
111 state: query
112 delegate_to: localhost
113 register: query_result
114
115 - name: Delete an Interface policy Spine Policy Group
116 cisco.aci.aci_interface_policy_spine_policy_group:
117 host: apic
118 username: admin
119 password: SomeSecretPassword
120 name: spinepolicygroupname
121 state: absent
122 delegate_to: localhost
123 """
124
125 RETURN = r"""
126 current:
127 description: The existing configuration from the APIC after the module has finished
128 returned: success
129 type: list
130 sample:
131 [
132 {
133 "fvTenant": {
134 "attributes": {
135 "descr": "Production environment",
136 "dn": "uni/tn-production",
137 "name": "production",
138 "nameAlias": "",
139 "ownerKey": "",
140 "ownerTag": ""
141 }
142 }
143 }
144 ]
145 error:
146 description: The error information as returned from the APIC
147 returned: failure
148 type: dict
149 sample:
150 {
151 "code": "122",
152 "text": "unknown managed object class foo"
153 }
154 raw:
155 description: The raw output returned by the APIC REST API (xml or json)
156 returned: parse error
157 type: str
158 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
159 sent:
160 description: The actual/minimal configuration pushed to the APIC
161 returned: info
162 type: list
163 sample:
164 {
165 "fvTenant": {
166 "attributes": {
167 "descr": "Production environment"
168 }
169 }
170 }
171 previous:
172 description: The original configuration from the APIC before the module has started
173 returned: info
174 type: list
175 sample:
176 [
177 {
178 "fvTenant": {
179 "attributes": {
180 "descr": "Production",
181 "dn": "uni/tn-production",
182 "name": "production",
183 "nameAlias": "",
184 "ownerKey": "",
185 "ownerTag": ""
186 }
187 }
188 }
189 ]
190 proposed:
191 description: The assembled configuration from the user-provided parameters
192 returned: info
193 type: dict
194 sample:
195 {
196 "fvTenant": {
197 "attributes": {
198 "descr": "Production environment",
199 "name": "production"
200 }
201 }
202 }
203 filter_string:
204 description: The filter string used for the request
205 returned: failure or debug
206 type: str
207 sample: ?rsp-prop-include=config-only
208 method:
209 description: The HTTP method used for the request to the APIC
210 returned: failure or debug
211 type: str
212 sample: POST
213 response:
214 description: The HTTP response from the APIC
215 returned: failure or debug
216 type: str
217 sample: OK (30 bytes)
218 status:
219 description: The HTTP status from the APIC
220 returned: failure or debug
221 type: int
222 sample: 200
223 url:
224 description: The HTTP url used for the request to the APIC
225 returned: failure or debug
226 type: str
227 sample: https://10.11.12.13/api/mo/uni/tn-production.json
228 """
229
230 from ansible.module_utils.basic import AnsibleModule
231 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
232
233
234 def main():
235 argument_spec = aci_argument_spec()
236 argument_spec.update(aci_annotation_spec())
237 argument_spec.update(aci_owner_spec())
238 argument_spec.update(
239 policy_group=dict(type="str", aliases=["policy_group_name", "spine_policy_group_name", "name"]), # Not required for querying all objects
240 description=dict(type="str", aliases=["descr"]),
241 name_alias=dict(type="str"),
242 link_level_policy=dict(type="str", aliases=["link_level_policy_name"]),
243 link_flap_policy=dict(type="str", aliases=["link_flap_policy_name"]),
244 cdp_policy=dict(type="str", aliases=["cdp_policy_name"]),
245 mac_sec_policy=dict(type="str", aliases=["mac_sec_policy_name"]),
246 attached_entity_profile=dict(type="str", aliases=["aep_name", "aep"]),
247 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
248 )
249
250 module = AnsibleModule(
251 argument_spec=argument_spec,
252 supports_check_mode=True,
253 required_if=[
254 ["state", "absent", ["policy_group"]],
255 ["state", "present", ["policy_group"]],
256 ],
257 )
258
259 policy_group = module.params.get("policy_group")
260 description = module.params.get("description")
261 name_alias = module.params.get("name_alias")
262 link_level_policy = module.params.get("link_level_policy")
263 link_flap_policy = module.params.get("link_flap_policy")
264 cdp_policy = module.params.get("cdp_policy")
265 mac_sec_policy = module.params.get("mac_sec_policy")
266 attached_entity_profile = module.params.get("attached_entity_profile")
267 state = module.params.get("state")
268
269 aci = ACIModule(module)
270
271 class_config = dict(
272 name=policy_group,
273 descr=description,
274 nameAlias=name_alias,
275 )
276
277 child_configs = [
278 dict(
279 infraRsHIfPol=dict(
280 attributes=dict(
281 tnFabricHIfPolName=link_level_policy,
282 ),
283 ),
284 ),
285 dict(
286 infraRsLinkFlapPol=dict(
287 attributes=dict(
288 tnFabricLinkFlapPolName=link_flap_policy,
289 ),
290 ),
291 ),
292 dict(
293 infraRsCdpIfPol=dict(
294 attributes=dict(
295 tnCdpIfPolName=cdp_policy,
296 ),
297 ),
298 ),
299 dict(
300 infraRsMacsecIfPol=dict(
301 attributes=dict(
302 tnMacsecIfPolName=mac_sec_policy,
303 ),
304 ),
305 ),
306 ]
307
308 if attached_entity_profile is not None:
309 child_configs.append(
310 dict(
311 infraRsAttEntP=dict(
312 attributes=dict(
313 tDn="uni/infra/attentp-{0}".format(attached_entity_profile),
314 ),
315 ),
316 )
317 )
318
319 aci.construct_url(
320 root_class=dict(
321 aci_class="infraSpAccPortGrp",
322 aci_rn="infra/funcprof/spaccportgrp-{0}".format(policy_group),
323 module_object=policy_group,
324 target_filter={"name": policy_group},
325 ),
326 child_classes=[
327 "infraRsHIfPol",
328 "infraRsLinkFlapPol",
329 "infraRsCdpIfPol",
330 "infraRsMacsecIfPol",
331 "infraRsAttEntP",
332 ],
333 )
334
335 aci.get_existing()
336
337 if state == "present":
338 aci.payload(
339 aci_class="infraSpAccPortGrp",
340 class_config=class_config,
341 child_configs=child_configs,
342 )
343
344 aci.get_diff(aci_class="infraSpAccPortGrp")
345
346 aci.post_config()
347
348 elif state == "absent":
349 aci.delete_config()
350
351 aci.exit_json()
352
353
354 if __name__ == "__main__":
355 main()