Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2017, Bruno Calogero <[email protected]>
5 # Copyright: (c) 2025, Eric Girard @netgirard
6 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
7
8 from __future__ import absolute_import, division, print_function
9
10 __metaclass__ = type
11
12 ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "certified"}
13
14 DOCUMENTATION = r"""
15 ---
16 module: aci_switch_policy_vpc_protection_group
17 short_description: Manage switch policy explicit vPC protection groups (fabric:ExplicitGEp and fabric:NodePEp).
18 description:
19 - Manage switch policy explicit vPC protection groups on Cisco ACI fabrics.
20 options:
21 protection_group:
22 description:
23 - The name of the Explicit vPC Protection Group.
24 type: str
25 aliases: [ name, protection_group_name ]
26 protection_group_id:
27 description:
28 - The Explicit vPC Protection Group ID.
29 type: int
30 aliases: [ id ]
31 vpc_domain_policy:
32 description:
33 - The vPC domain policy to be associated with the Explicit vPC Protection Group.
34 type: str
35 aliases: [ vpc_domain_policy_name ]
36 switch_1_id:
37 description:
38 - The ID of the first Leaf Switch for the Explicit vPC Protection Group.
39 type: int
40 switch_2_id:
41 description:
42 - The ID of the Second Leaf Switch for the Explicit vPC Protection Group.
43 type: int
44 pod_id:
45 description:
46 - The pod id of the VPC member nodes.
47 - Accepted values range between C(1) and C(255).
48 - The APIC defaults to C(1) when unset during creation.
49 type: int
50 state:
51 description:
52 - Use C(present) or C(absent) for adding or removing.
53 - Use C(query) for listing an object or multiple objects.
54 type: str
55 choices: [ absent, present, query ]
56 default: present
57 name_alias:
58 description:
59 - The alias for the current object. This relates to the nameAlias field in ACI.
60 type: str
61 extends_documentation_fragment:
62 - cisco.aci.aci
63 - cisco.aci.annotation
64
65 seealso:
66 - module: cisco.aci.aci_switch_policy_leaf_profile
67 - name: APIC Management Information Model reference
68 description: More information about the internal APIC classes B(fabric:ExplicitGEp) and B(fabric:NodePEp).
69 link: https://developer.cisco.com/docs/apic-mim-ref/
70 author:
71 - Bruno Calogero (@brunocalogero)
72 - Eric Girard (@netgirard)
73 """
74
75 EXAMPLES = r"""
76 - name: Add vPC Protection Group
77 cisco.aci.aci_switch_policy_vpc_protection_group:
78 host: apic
79 username: admin
80 password: SomeSecretPassword
81 protection_group: leafPair101-vpcGrp
82 protection_group_id: 6
83 switch_1_id: 1011
84 switch_2_id: 1012
85 state: present
86 delegate_to: localhost
87
88 - name: Remove Explicit vPC Protection Group
89 cisco.aci.aci_switch_policy_vpc_protection_group:
90 host: apic
91 username: admin
92 password: SomeSecretPassword
93 protection_group: leafPair101-vpcGrp
94 state: absent
95 delegate_to: localhost
96
97 - name: Query vPC Protection Groups
98 cisco.aci.aci_switch_policy_vpc_protection_group:
99 host: apic
100 username: admin
101 password: SomeSecretPassword
102 state: query
103 delegate_to: localhost
104 register: query_result
105
106 - name: Query our vPC Protection Group
107 cisco.aci.aci_switch_policy_vpc_protection_group:
108 host: apic
109 username: admin
110 password: SomeSecretPassword
111 protection_group: leafPair101-vpcGrp
112 state: query
113 delegate_to: localhost
114 register: query_result
115 """
116
117 RETURN = r"""
118 current:
119 description: The existing configuration from the APIC after the module has finished
120 returned: success
121 type: list
122 sample:
123 [
124 {
125 "fvTenant": {
126 "attributes": {
127 "descr": "Production environment",
128 "dn": "uni/tn-production",
129 "name": "production",
130 "nameAlias": "",
131 "ownerKey": "",
132 "ownerTag": ""
133 }
134 }
135 }
136 ]
137 error:
138 description: The error information as returned from the APIC
139 returned: failure
140 type: dict
141 sample:
142 {
143 "code": "122",
144 "text": "unknown managed object class foo"
145 }
146 raw:
147 description: The raw output returned by the APIC REST API (xml or json)
148 returned: parse error
149 type: str
150 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
151 sent:
152 description: The actual/minimal configuration pushed to the APIC
153 returned: info
154 type: list
155 sample:
156 {
157 "fvTenant": {
158 "attributes": {
159 "descr": "Production environment"
160 }
161 }
162 }
163 previous:
164 description: The original configuration from the APIC before the module has started
165 returned: info
166 type: list
167 sample:
168 [
169 {
170 "fvTenant": {
171 "attributes": {
172 "descr": "Production",
173 "dn": "uni/tn-production",
174 "name": "production",
175 "nameAlias": "",
176 "ownerKey": "",
177 "ownerTag": ""
178 }
179 }
180 }
181 ]
182 proposed:
183 description: The assembled configuration from the user-provided parameters
184 returned: info
185 type: dict
186 sample:
187 {
188 "fvTenant": {
189 "attributes": {
190 "descr": "Production environment",
191 "name": "production"
192 }
193 }
194 }
195 filter_string:
196 description: The filter string used for the request
197 returned: failure or debug
198 type: str
199 sample: ?rsp-prop-include=config-only
200 method:
201 description: The HTTP method used for the request to the APIC
202 returned: failure or debug
203 type: str
204 sample: POST
205 response:
206 description: The HTTP response from the APIC
207 returned: failure or debug
208 type: str
209 sample: OK (30 bytes)
210 status:
211 description: The HTTP status from the APIC
212 returned: failure or debug
213 type: int
214 sample: 200
215 url:
216 description: The HTTP url used for the request to the APIC
217 returned: failure or debug
218 type: str
219 sample: https://10.11.12.13/api/mo/uni/tn-production.json
220 """
221
222 from ansible.module_utils.basic import AnsibleModule
223 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
224
225
226 def main():
227 argument_spec = aci_argument_spec()
228 argument_spec.update(aci_annotation_spec())
229 argument_spec.update(
230 protection_group=dict(type="str", aliases=["name", "protection_group_name"]), # Not required for querying all objects
231 protection_group_id=dict(type="int", aliases=["id"]),
232 vpc_domain_policy=dict(type="str", aliases=["vpc_domain_policy_name"]),
233 switch_1_id=dict(type="int"),
234 switch_2_id=dict(type="int"),
235 pod_id=dict(type="int"),
236 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
237 name_alias=dict(type="str"),
238 )
239
240 module = AnsibleModule(
241 argument_spec=argument_spec,
242 supports_check_mode=True,
243 required_if=[
244 ["state", "absent", ["protection_group"]],
245 ["state", "present", ["protection_group", "protection_group_id", "switch_1_id", "switch_2_id"]],
246 ],
247 )
248
249 protection_group = module.params.get("protection_group")
250 protection_group_id = module.params.get("protection_group_id")
251 vpc_domain_policy = module.params.get("vpc_domain_policy")
252 switch_1_id = module.params.get("switch_1_id")
253 switch_2_id = module.params.get("switch_2_id")
254 pod_id = module.params.get("pod_id")
255 state = module.params.get("state")
256 name_alias = module.params.get("name_alias")
257
258 aci = ACIModule(module)
259 aci.construct_url(
260 root_class=dict(
261 aci_class="fabricExplicitGEp",
262 aci_rn="fabric/protpol/expgep-{0}".format(protection_group),
263 module_object=protection_group,
264 target_filter={"name": protection_group},
265 ),
266 child_classes=["fabricNodePEp", "fabricNodePEp", "fabricRsVpcInstPol"],
267 )
268
269 aci.get_existing()
270
271 if state == "present":
272 aci.payload(
273 aci_class="fabricExplicitGEp",
274 class_config=dict(
275 name=protection_group,
276 id=protection_group_id,
277 nameAlias=name_alias,
278 ),
279 child_configs=[
280 dict(
281 fabricNodePEp=dict(
282 attributes=dict(
283 id="{0}".format(switch_1_id),
284 podId=pod_id,
285 ),
286 ),
287 ),
288 dict(
289 fabricNodePEp=dict(
290 attributes=dict(
291 id="{0}".format(switch_2_id),
292 podId=pod_id,
293 ),
294 ),
295 ),
296 dict(
297 fabricRsVpcInstPol=dict(
298 attributes=dict(
299 tnVpcInstPolName=vpc_domain_policy,
300 ),
301 ),
302 ),
303 ],
304 )
305
306 aci.get_diff(aci_class="fabricExplicitGEp")
307
308 aci.post_config()
309
310 elif state == "absent":
311 aci.delete_config()
312
313 aci.exit_json()
314
315
316 if __name__ == "__main__":
317 main()