ansible  2.9.27
About: Ansible is an IT Configuration Management, Deployment \
About: Ansible (2.x) is an IT Configuration Management, Deployment & Orchestration tool.
ansible download page.
  Fossies Dox: ansible-2.9.27.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

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