Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7
8 __metaclass__ = type
9
10 ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "certified"}
11
12 DOCUMENTATION = r"""
13 ---
14 module: aci_interface_policy_port_channel
15 short_description: Manage port channel interface policies (lacp:LagPol)
16 description:
17 - Manage port channel interface policies on Cisco ACI fabrics.
18 options:
19 port_channel:
20 description:
21 - Name of the port channel.
22 type: str
23 aliases: [ name ]
24 description:
25 description:
26 - The description of the port channel.
27 type: str
28 aliases: [ descr ]
29 max_links:
30 description:
31 - Maximum links.
32 - Accepted values range between 1 and 16.
33 - The APIC defaults to C(16) when unset during creation.
34 type: int
35 min_links:
36 description:
37 - Minimum links.
38 - Accepted values range between 1 and 16.
39 - The APIC defaults to C(1) when unset during creation.
40 type: int
41 mode:
42 description:
43 - Port channel interface policy mode.
44 - Determines the LACP method to use for forming port-channels.
45 - The APIC defaults to C(off) when unset during creation.
46 type: str
47 choices: [ active, mac-pin, mac-pin-nicload, 'off', passive ]
48 fast_select:
49 description:
50 - Determines if Fast Select is enabled for Hot Standby Ports.
51 - This makes up the LACP Policy Control Policy; if one setting is defined, then all other Control Properties
52 left undefined or set to false will not exist after the task is ran.
53 - The APIC defaults to C(true) when unset during creation.
54 type: bool
55 graceful_convergence:
56 description:
57 - Determines if Graceful Convergence is enabled.
58 - This makes up the LACP Policy Control Policy; if one setting is defined, then all other Control Properties
59 left undefined or set to false will not exist after the task is ran.
60 - The APIC defaults to C(true) when unset during creation.
61 type: bool
62 load_defer:
63 description:
64 - Determines if Load Defer is enabled.
65 - This makes up the LACP Policy Control Policy; if one setting is defined, then all other Control Properties
66 left undefined or set to false will not exist after the task is ran.
67 - The APIC defaults to C(false) when unset during creation.
68 type: bool
69 suspend_individual:
70 description:
71 - Determines if Suspend Individual is enabled.
72 - This makes up the LACP Policy Control Policy; if one setting is defined, then all other Control Properties
73 left undefined or set to false will not exist after the task is ran.
74 - The APIC defaults to C(true) when unset during creation.
75 type: bool
76 symmetric_hash:
77 description:
78 - Determines if Symmetric Hashing is enabled.
79 - This makes up the LACP Policy Control Policy; if one setting is defined, then all other Control Properties
80 left undefined or set to false will not exist after the task is ran.
81 - The APIC defaults to C(false) when unset during creation.
82 type: bool
83 state:
84 description:
85 - Use C(present) or C(absent) for adding or removing.
86 - Use C(query) for listing an object or multiple objects.
87 type: str
88 choices: [ absent, present, query ]
89 default: present
90 name_alias:
91 description:
92 - The alias for the current object. This relates to the nameAlias field in ACI.
93 type: str
94 extends_documentation_fragment:
95 - cisco.aci.aci
96 - cisco.aci.annotation
97 - cisco.aci.owner
98
99 seealso:
100 - name: APIC Management Information Model reference
101 description: More information about the internal APIC class B(lacp:LagPol).
102 link: https://developer.cisco.com/docs/apic-mim-ref/
103 author:
104 - Dag Wieers (@dagwieers)
105 """
106
107 EXAMPLES = r"""
108 - name: Create a Port Channel interface policy
109 cisco.aci.aci_interface_policy_port_channel:
110 host: apic
111 username: admin
112 password: SomeSecretPassword
113 port_channel: LACP_ACTIVE
114 mode: active
115 min_links: 1
116 max_links: 16
117 state: present
118 delegate_to: localhost
119
120 - name: Delete a Port Channel interface policy
121 cisco.aci.aci_interface_policy_port_channel:
122 host: apic
123 username: admin
124 password: SomeSecretPassword
125 port_channel: LACP_ACTIVE
126 state: absent
127 delegate_to: localhost
128
129 - name: Query all Port Channel interface policies
130 cisco.aci.aci_interface_policy_port_channel:
131 host: apic
132 username: admin
133 password: SomeSecretPassword
134 state: query
135 delegate_to: localhost
136 register: query_result
137
138 - name: Query a specific Port Channel interface policy
139 cisco.aci.aci_interface_policy_port_channel:
140 host: apic
141 username: admin
142 password: SomeSecretPassword
143 port_channel: LACP_ACTIVE
144 state: query
145 delegate_to: localhost
146 register: query_result
147 """
148
149 RETURN = r"""
150 current:
151 description: The existing configuration from the APIC after the module has finished
152 returned: success
153 type: list
154 sample:
155 [
156 {
157 "fvTenant": {
158 "attributes": {
159 "descr": "Production environment",
160 "dn": "uni/tn-production",
161 "name": "production",
162 "nameAlias": "",
163 "ownerKey": "",
164 "ownerTag": ""
165 }
166 }
167 }
168 ]
169 error:
170 description: The error information as returned from the APIC
171 returned: failure
172 type: dict
173 sample:
174 {
175 "code": "122",
176 "text": "unknown managed object class foo"
177 }
178 raw:
179 description: The raw output returned by the APIC REST API (xml or json)
180 returned: parse error
181 type: str
182 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
183 sent:
184 description: The actual/minimal configuration pushed to the APIC
185 returned: info
186 type: list
187 sample:
188 {
189 "fvTenant": {
190 "attributes": {
191 "descr": "Production environment"
192 }
193 }
194 }
195 previous:
196 description: The original configuration from the APIC before the module has started
197 returned: info
198 type: list
199 sample:
200 [
201 {
202 "fvTenant": {
203 "attributes": {
204 "descr": "Production",
205 "dn": "uni/tn-production",
206 "name": "production",
207 "nameAlias": "",
208 "ownerKey": "",
209 "ownerTag": ""
210 }
211 }
212 }
213 ]
214 proposed:
215 description: The assembled configuration from the user-provided parameters
216 returned: info
217 type: dict
218 sample:
219 {
220 "fvTenant": {
221 "attributes": {
222 "descr": "Production environment",
223 "name": "production"
224 }
225 }
226 }
227 filter_string:
228 description: The filter string used for the request
229 returned: failure or debug
230 type: str
231 sample: ?rsp-prop-include=config-only
232 method:
233 description: The HTTP method used for the request to the APIC
234 returned: failure or debug
235 type: str
236 sample: POST
237 response:
238 description: The HTTP response from the APIC
239 returned: failure or debug
240 type: str
241 sample: OK (30 bytes)
242 status:
243 description: The HTTP status from the APIC
244 returned: failure or debug
245 type: int
246 sample: 200
247 url:
248 description: The HTTP url used for the request to the APIC
249 returned: failure or debug
250 type: str
251 sample: https://10.11.12.13/api/mo/uni/tn-production.json
252 """
253
254 from ansible.module_utils.basic import AnsibleModule
255 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
256
257
258 def main():
259 argument_spec = aci_argument_spec()
260 argument_spec.update(aci_annotation_spec())
261 argument_spec.update(aci_owner_spec())
262 argument_spec.update(
263 port_channel=dict(type="str", aliases=["name"]), # Not required for querying all objects
264 description=dict(type="str", aliases=["descr"]),
265 min_links=dict(type="int"),
266 max_links=dict(type="int"),
267 mode=dict(type="str", choices=["active", "mac-pin", "mac-pin-nicload", "off", "passive"]),
268 fast_select=dict(type="bool"),
269 graceful_convergence=dict(type="bool"),
270 load_defer=dict(type="bool"),
271 suspend_individual=dict(type="bool"),
272 symmetric_hash=dict(type="bool"),
273 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
274 name_alias=dict(type="str"),
275 )
276
277 module = AnsibleModule(
278 argument_spec=argument_spec,
279 supports_check_mode=True,
280 required_if=[
281 ["state", "absent", ["port_channel"]],
282 ["state", "present", ["port_channel"]],
283 ],
284 )
285
286 port_channel = module.params.get("port_channel")
287 description = module.params.get("description")
288 min_links = module.params.get("min_links")
289 if min_links is not None and min_links not in range(1, 17):
290 module.fail_json(msg='The "min_links" must be a value between 1 and 16')
291 max_links = module.params.get("max_links")
292 if max_links is not None and max_links not in range(1, 17):
293 module.fail_json(msg='The "max_links" must be a value between 1 and 16')
294 mode = module.params.get("mode")
295 state = module.params.get("state")
296 name_alias = module.params.get("name_alias")
297
298 # Build ctrl value for request
299 ctrl = []
300 if module.params.get("fast_select") is True:
301 ctrl.append("fast-sel-hot-stdby")
302 if module.params.get("graceful_convergence") is True:
303 ctrl.append("graceful-conv")
304 if module.params.get("load_defer") is True:
305 ctrl.append("load-defer")
306 if module.params.get("suspend_individual") is True:
307 ctrl.append("susp-individual")
308 if module.params.get("symmetric_hash") is True:
309 ctrl.append("symmetric-hash")
310 if not ctrl:
311 ctrl = None
312 else:
313 ctrl = ",".join(ctrl)
314
315 aci = ACIModule(module)
316 aci.construct_url(
317 root_class=dict(
318 aci_class="lacpLagPol",
319 aci_rn="infra/lacplagp-{0}".format(port_channel),
320 module_object=port_channel,
321 target_filter={"name": port_channel},
322 ),
323 )
324
325 aci.get_existing()
326
327 if state == "present":
328 aci.payload(
329 aci_class="lacpLagPol",
330 class_config=dict(
331 name=port_channel,
332 ctrl=ctrl,
333 descr=description,
334 minLinks=min_links,
335 maxLinks=max_links,
336 mode=mode,
337 nameAlias=name_alias,
338 ),
339 )
340
341 aci.get_diff(aci_class="lacpLagPol")
342
343 aci.post_config()
344
345 elif state == "absent":
346 aci.delete_config()
347
348 aci.exit_json()
349
350
351 if __name__ == "__main__":
352 main()