Debian Codegraph @

ansible_collections/cisco/ios/plugins/modules/ios_lacp.py

raw
1 #!/usr/bin/python
2 #
3 # This file is part of Ansible
4 #
5 # Ansible is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Ansible is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
17 #
18 """
19 The module file for ios_lacp
20 """
21 from __future__ import absolute_import, division, print_function
22
23
24 __metaclass__ = type
25
26
27 DOCUMENTATION = """
28 module: ios_lacp
29 short_description: Resource module to configure LACP.
30 description:
31 This module provides declarative management of Global LACP on Cisco IOS
32 network devices.
33 version_added: 1.0.0
34 author: Sumit Jaiswal (@justjais)
35 notes:
36 - Tested against Cisco IOSXE Version 17.3 on CML.
37 - This module works with connection C(network_cli).
38 See U(https://docs.ansible.com/ansible/latest/network/user_guide/platform_ios.html)
39 options:
40 config:
41 description: The provided configurations.
42 type: dict
43 suboptions:
44 system:
45 description: This option sets the default system parameters for LACP.
46 type: dict
47 suboptions:
48 priority:
49 description:
50 - LACP priority for the system.
51 - Refer to vendor documentation for valid values.
52 type: int
53 required: true
54 running_config:
55 description:
56 - This option is used only with state I(parsed).
57 - The value of this option should be the output received from the IOS device by
58 executing the command B(show lacp sys-id).
59 - The state I(parsed) reads the configuration from C(running_config) option and
60 transforms it into Ansible structured data as per the resource module's argspec
61 and the value is then returned in the I(parsed) key within the result.
62 type: str
63 state:
64 description:
65 - The state the configuration should be left in
66 - The module have declaratively similar behavior for replaced and overridden state.
67 - The states I(rendered), I(gathered) and I(parsed) does not perform any change
68 on the device.
69 - The state I(rendered) will transform the configuration in C(config) option to
70 platform specific CLI commands which will be returned in the I(rendered) key
71 within the result. For state I(rendered) active connection to remote host is
72 not required.
73 - The state I(gathered) will fetch the running configuration from device and transform
74 it into structured data in the format as per the resource module argspec and
75 the value is returned in the I(gathered) key within the result.
76 - The state I(parsed) reads the configuration from C(running_config) option and
77 transforms it into JSON format as per the resource module parameters and the
78 value is returned in the I(parsed) key within the result. The value of C(running_config)
79 option should be the same format as the output of command I(show running-config
80 | include ip route|ipv6 route) executed on device. For state I(parsed) active
81 connection to remote host is not required.
82 type: str
83 choices:
84 - merged
85 - replaced
86 - overridden
87 - deleted
88 - rendered
89 - parsed
90 - gathered
91 default: merged
92 """
93
94 EXAMPLES = """
95 # Using merged
96 #
97 # Before state:
98 # -------------
99 #
100 # vios#show lacp sys-id
101 # 32768, 5e00.0000.8000
102
103 - name: Merge provided configuration with device configuration
104 cisco.ios.ios_lacp:
105 config:
106 system:
107 priority: 123
108 state: merged
109
110 # After state:
111 # ------------
112 #
113 # vios#show lacp sys-id
114 # 123, 5e00.0000.8000
115
116 # Using replaced
117 #
118 # Before state:
119 # -------------
120 #
121 # vios#show lacp sys-id
122 # 500, 5e00.0000.8000
123
124 - name: Replaces Global LACP configuration
125 cisco.ios.ios_lacp:
126 config:
127 system:
128 priority: 123
129 state: replaced
130
131 # After state:
132 # ------------
133 #
134 # vios#show lacp sys-id
135 # 123, 5e00.0000.8000
136
137 # Using Deleted
138 #
139 # Before state:
140 # -------------
141 #
142 # vios#show lacp sys-id
143 # 500, 5e00.0000.8000
144
145 - name: Delete Global LACP attribute
146 cisco.ios.ios_lacp:
147 state: deleted
148
149 # After state:
150 # -------------
151 #
152 # vios#show lacp sys-id
153 # 32768, 5e00.0000.8000
154
155 # Using Gathered
156
157 # Before state:
158 # -------------
159 #
160 # vios#show lacp sys-id
161 # 123, 5e00.0000.8000
162
163 - name: Gather listed LACP with provided configurations
164 cisco.ios.ios_lacp:
165 config:
166 state: gathered
167
168 # Module Execution Result:
169 # ------------------------
170 #
171 # "gathered": {
172 # "system": {
173 # "priority": 500
174 # }
175 # }
176
177 # After state:
178 # ------------
179 #
180 # vios#show lacp sys-id
181 # 123, 5e00.0000.8000
182
183 # Using Rendered
184
185 - name: Render the commands for provided configuration
186 cisco.ios.ios_lacp:
187 config:
188 system:
189 priority: 123
190 state: rendered
191
192 # Module Execution Result:
193 # ------------------------
194 #
195 # "rendered": [
196 # "lacp system-priority 10"
197 # ]
198
199 # Using Parsed
200
201 # File: parsed.cfg
202 # ----------------
203 #
204 # lacp system-priority 123
205
206 - name: Parse the commands for provided configuration
207 cisco.ios.ios_lacp:
208 running_config: "{{ lookup('file', 'parsed.cfg') }}"
209 state: parsed
210
211 # Module Execution Result:
212 # ------------------------
213 #
214 # "parsed": {
215 # "system": {
216 # "priority": 123
217 # }
218 # }
219 """
220
221 RETURN = """
222 before:
223 description: The configuration as structured data prior to module invocation.
224 returned: always
225 type: list
226 sample: >
227 The configuration returned will always be in the same format
228 of the parameters above.
229 after:
230 description: The configuration as structured data after module completion.
231 returned: when changed
232 type: list
233 sample: >
234 The configuration returned will always be in the same format
235 of the parameters above.
236 commands:
237 description: The set of commands pushed to the remote device.
238 returned: always
239 type: list
240 sample: ['lacp system-priority 10']
241 """
242
243 from ansible.module_utils.basic import AnsibleModule
244
245 from ansible_collections.cisco.ios.plugins.module_utils.network.ios.argspec.lacp.lacp import (
246 LacpArgs,
247 )
248 from ansible_collections.cisco.ios.plugins.module_utils.network.ios.config.lacp.lacp import Lacp
249
250
251 def main():
252 """
253 Main entry point for module execution
254
255 :returns: the result form module invocation
256 """
257 required_if = [
258 ("state", "merged", ("config",)),
259 ("state", "replaced", ("config",)),
260 ("state", "overridden", ("config",)),
261 ("state", "rendered", ("config",)),
262 ("state", "parsed", ("running_config",)),
263 ]
264
265 mutually_exclusive = [("config", "running_config")]
266
267 module = AnsibleModule(
268 argument_spec=LacpArgs.argument_spec,
269 required_if=required_if,
270 mutually_exclusive=mutually_exclusive,
271 supports_check_mode=True,
272 )
273 result = Lacp(module).execute_module()
274 module.exit_json(**result)
275
276
277 if __name__ == "__main__":
278 main()