Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2022, Tim Cragg (@timcragg)
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": "community"}
12
13 DOCUMENTATION = r"""
14 ---
15 module: aci_fabric_pod_policy_group
16 short_description: Manage Fabric Pod Policy Groups (fabric:PodPGrp)
17 description:
18 - Fabric Pod Policy Group (fabric:PodPGrp) configuration on Cisco ACI fabrics.
19 options:
20 name:
21 description:
22 - Name of the policy group
23 type: str
24 aliases: [ policy_group, policy_group_name, pod_policy_group ]
25 date_time_policy:
26 description:
27 - NTP policy to bind to the policy group
28 type: str
29 aliases: [ ntp_policy ]
30 isis_policy:
31 description:
32 - IS-IS policy to bind to the policy group
33 type: str
34 coop_group_policy:
35 description:
36 - COOP group policy to bind to the policy group
37 type: str
38 aliases: [ coop_policy ]
39 bgp_rr_policy:
40 description:
41 - BGP route reflector policy to bind to the policy group
42 type: str
43 management_access_policy:
44 description:
45 - Management access policy to bind to the policy group
46 type: str
47 aliases: [ management_policy, mgmt_policy ]
48 snmp_policy:
49 description:
50 - SNMP policy to bind to the policy group
51 type: str
52 macsec_policy:
53 description:
54 - MACSec policy to bind to the policy group
55 type: str
56 name_alias:
57 description:
58 - The alias for the current object. This relates to the nameAlias field in ACI.
59 type: str
60 state:
61 description:
62 - Use C(present) or C(absent) for adding or removing.
63 - Use C(query) for listing an object or multiple objects.
64 type: str
65 choices: [ absent, present, query ]
66 default: present
67 extends_documentation_fragment:
68 - cisco.aci.aci
69 - cisco.aci.annotation
70 - cisco.aci.owner
71
72 seealso:
73 - name: APIC Management Information Model reference
74 description: More information about the internal APIC class B(fabricPodPGrp).
75 link: https://developer.cisco.com/docs/apic-mim-ref/
76 author:
77 - Tim Cragg (@timcragg)
78 """
79
80 EXAMPLES = r"""
81 - name: Add a new fabric pod policy group
82 cisco.aci.aci_fabric_pod_policy_group:
83 host: apic
84 username: admin
85 password: SomeSecretPassword
86 name: my_pod_pol_grp
87 snmp_policy: my_snmp_pol
88 bgp_rr_policy: my_bgp_rr_pol
89 state: present
90 delegate_to: localhost
91
92 - name: Remove a fabric pod policy group
93 cisco.aci.aci_fabric_pod_policy_group:
94 host: apic
95 username: admin
96 password: SomeSecretPassword
97 name: my_pod_pol_grp
98 state: absent
99 delegate_to: localhost
100
101 - name: Query a fabric pod policy group
102 cisco.aci.aci_fabric_pod_policy_group:
103 host: apic
104 username: admin
105 password: SomeSecretPassword
106 name: my_pod_pol_grp
107 state: query
108 delegate_to: localhost
109 register: query_result
110
111 - name: Query all fabric pod policy groups
112 cisco.aci.aci_fabric_pod_policy_group:
113 host: apic
114 username: admin
115 password: SomeSecretPassword
116 state: query
117 delegate_to: localhost
118 register: query_result
119 """
120
121 RETURN = r"""
122 current:
123 description: The existing configuration from the APIC after the module has finished
124 returned: success
125 type: list
126 sample:
127 [
128 {
129 "fvTenant": {
130 "attributes": {
131 "descr": "Production environment",
132 "dn": "uni/tn-production",
133 "name": "production",
134 "nameAlias": "",
135 "ownerKey": "",
136 "ownerTag": ""
137 }
138 }
139 }
140 ]
141 error:
142 description: The error information as returned from the APIC
143 returned: failure
144 type: dict
145 sample:
146 {
147 "code": "122",
148 "text": "unknown managed object class foo"
149 }
150 raw:
151 description: The raw output returned by the APIC REST API (xml or json)
152 returned: parse error
153 type: str
154 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class "/></imdata>'
155 sent:
156 description: The actual/minimal configuration pushed to the APIC
157 returned: info
158 type: list
159 sample:
160 {
161 "fvTenant": {
162 "attributes": {
163 "descr": "Production environment"
164 }
165 }
166 }
167 previous:
168 description: The original configuration from the APIC before the module has started
169 returned: info
170 type: list
171 sample:
172 [
173 {
174 "fvTenant": {
175 "attributes": {
176 "descr": "Production",
177 "dn": "uni/tn-production",
178 "name": "production",
179 "nameAlias": "",
180 "ownerKey": "",
181 "ownerTag": ""
182 }
183 }
184 }
185 ]
186 proposed:
187 description: The assembled configuration from the user-provided parameters
188 returned: info
189 type: dict
190 sample:
191 {
192 "fvTenant": {
193 "attributes": {
194 "descr": "Production environment",
195 "name": "production"
196 }
197 }
198 }
199 filter_string:
200 description: The filter string used for the request
201 returned: failure or debug
202 type: str
203 sample: ?rsp-prop-include=config-only
204 method:
205 description: The HTTP method used for the request to the APIC
206 returned: failure or debug
207 type: str
208 sample: POST
209 response:
210 description: The HTTP response from the APIC
211 returned: failure or debug
212 type: str
213 sample: OK (30 bytes)
214 status:
215 description: The HTTP status from the APIC
216 returned: failure or debug
217 type: int
218 sample: 200
219 url:
220 description: The HTTP url used for the request to the APIC
221 returned: failure or debug
222 type: str
223 sample: https://10.11.12.13/api/mo/uni/tn-production.json
224 """
225
226 from ansible.module_utils.basic import AnsibleModule
227 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
228
229
230 def main():
231 argument_spec = aci_argument_spec()
232 argument_spec.update(aci_annotation_spec())
233 argument_spec.update(aci_owner_spec())
234 argument_spec.update(
235 name=dict(type="str", aliases=["policy_group", "policy_group_name", "pod_policy_group"]),
236 date_time_policy=dict(type="str", aliases=["ntp_policy"]),
237 isis_policy=dict(type="str"),
238 coop_group_policy=dict(type="str", aliases=["coop_policy"]),
239 bgp_rr_policy=dict(type="str"),
240 management_access_policy=dict(type="str", aliases=["management_policy", "mgmt_policy"]),
241 snmp_policy=dict(type="str"),
242 macsec_policy=dict(type="str"),
243 name_alias=dict(type="str"),
244 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
245 )
246
247 module = AnsibleModule(
248 argument_spec=argument_spec,
249 supports_check_mode=True,
250 required_if=[
251 ["state", "absent", ["name"]],
252 ["state", "present", ["name"]],
253 ],
254 )
255 aci = ACIModule(module)
256
257 name = module.params.get("name")
258 date_time_policy = module.params.get("date_time_policy")
259 isis_policy = module.params.get("isis_policy")
260 coop_group_policy = module.params.get("coop_group_policy")
261 bgp_rr_policy = module.params.get("bgp_rr_policy")
262 management_access_policy = module.params.get("management_access_policy")
263 snmp_policy = module.params.get("snmp_policy")
264 macsec_policy = module.params.get("macsec_policy")
265 name_alias = module.params.get("name_alias")
266 state = module.params.get("state")
267 child_classes = [
268 "fabricRsSnmpPol",
269 "fabricRsPodPGrpIsisDomP",
270 "fabricRsPodPGrpCoopP",
271 "fabricRsPodPGrpBGPRRP",
272 "fabricRsTimePol",
273 "fabricRsMacsecPol",
274 "fabricRsCommPol",
275 ]
276
277 aci.construct_url(
278 root_class=dict(
279 aci_class="fabricPodPGrp",
280 aci_rn="fabric/funcprof/podpgrp-{0}".format(name),
281 module_object=name,
282 target_filter={"name": name},
283 ),
284 child_classes=child_classes,
285 )
286
287 aci.get_existing()
288
289 if state == "present":
290 child_configs = []
291 if date_time_policy is not None:
292 child_configs.append(dict(fabricRsTimePol=dict(attributes=dict(tnDatetimePolName=date_time_policy))))
293 if isis_policy is not None:
294 child_configs.append(dict(fabricRsPodPGrpIsisDomP=dict(attributes=dict(tnIsisDomPolName=isis_policy))))
295 if coop_group_policy is not None:
296 child_configs.append(dict(fabricRsPodPGrpCoopP=dict(attributes=dict(tnCoopPolName=coop_group_policy))))
297 if bgp_rr_policy is not None:
298 child_configs.append(dict(fabricRsPodPGrpBGPRRP=dict(attributes=dict(tnBgpInstPolName=bgp_rr_policy))))
299 if management_access_policy is not None:
300 child_configs.append(dict(fabricRsCommPol=dict(attributes=dict(tnCommPolName=management_access_policy))))
301 if snmp_policy is not None:
302 child_configs.append(dict(fabricRsSnmpPol=dict(attributes=dict(tnSnmpPolName=snmp_policy))))
303 if macsec_policy is not None:
304 child_configs.append(dict(fabricRsMacsecPol=dict(attributes=dict(tnMacsecFabIfPolName=macsec_policy))))
305 aci.payload(
306 aci_class="fabricPodPGrp",
307 class_config=dict(name=name, nameAlias=name_alias),
308 child_configs=child_configs,
309 )
310
311 aci.get_diff(aci_class="fabricPodPGrp")
312
313 aci.post_config()
314
315 elif state == "absent":
316 aci.delete_config()
317
318 aci.exit_json()
319
320
321 if __name__ == "__main__":
322 main()