Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_radius_server.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # © Copyright 2025 Dell Inc. or its subsidiaries. All Rights Reserved.
4 # GNU General Public License v3.0+
5 # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 """
8 The module file for sonic_radius_server
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_radius_server
17 version_added: 1.0.0
18 notes:
19 - Tested against Enterprise SONiC Distribution by Dell Technologies.
20 - Supports C(check_mode).
21 author: Niraimadaiselvam M (@niraimadaiselvamm)
22 short_description: Manage RADIUS server configuration on SONiC
23 description:
24 - This module provides configuration management of radius server for devices running Enterprise SONiC.
25 options:
26 config:
27 description:
28 - Specifies the radius server related configuration.
29 type: dict
30 suboptions:
31 auth_type:
32 description:
33 - Specifies the authentication type of the radius server.
34 - The default is C(pap).
35 type: str
36 choices:
37 - pap
38 - chap
39 - mschapv2
40 key:
41 description:
42 - Specifies the key of the radius server.
43 type: str
44 nas_ip:
45 description:
46 - Specifies the network access server of the radius server.
47 type: str
48 statistics:
49 description:
50 - Specifies the statistics flag of the radius server.
51 type: bool
52 timeout:
53 description:
54 - Specifies the timeout of the radius server.
55 - The range is 3 to 60.
56 - The default is 5.
57 type: int
58 retransmit:
59 description:
60 - Specifies the re-transmit value of the radius server.
61 - The range is 0 to 10.
62 type: int
63 servers:
64 description:
65 - Specifies the servers list of the radius server.
66 type: dict
67 suboptions:
68 host:
69 description:
70 - Specifies the host details of the radius servers list.
71 type: list
72 elements: dict
73 suboptions:
74 name:
75 description:
76 - Specifies the IP address or name of the radius server host.
77 type: str
78 required: true
79 auth_type:
80 description:
81 - Specifies the authentication type of the radius server host.
82 type: str
83 choices:
84 - pap
85 - chap
86 - mschapv2
87 key:
88 description:
89 - Specifies the key of the radius server host.
90 type: str
91 priority:
92 description:
93 - Specifies the priority of the radius server host.
94 - The range is 1 to 64.
95 type: int
96 protocol:
97 version_added: 4.0.0
98 description:
99 - Specifies the protocol of the radius server host.
100 - The functional default is C(UDP).
101 type: str
102 choices:
103 - TLS
104 - UDP
105 port:
106 description:
107 - Specifies the port of the radius server host.
108 - The range is 1 to 65535.
109 - The default is 1812.
110 type: int
111 timeout:
112 description:
113 - Specifies the timeout of the radius server host.
114 - The range is 3 to 60.
115 type: int
116 retransmit:
117 description:
118 - Specifies the retransmit of the radius server host.
119 - The range is 0 to 10.
120 type: int
121 security_profile:
122 version_added: 4.0.0
123 description:
124 - Specifies the security profile for the radius server host.
125 type: str
126 source_interface:
127 description:
128 - Specifies the source interface of the radius server host.
129 type: str
130 vrf:
131 description:
132 - Specifies the vrf of the radius server host.
133 type: str
134 state:
135 description:
136 - Specifies the operation to be performed on the radius server configured on the device.
137 - In case of merged, the input mode configuration will be merged with the existing radius server configuration on the device.
138 - In case of deleted the existing radius server mode configuration will be removed from the device.
139 - In case of replaced, the existing radius server configuration will be replaced with provided configuration.
140 - In case of overridden, the existing radius server configuration will be overridden with the provided configuration.
141 default: merged
142 choices: ['merged', 'replaced', 'overridden', 'deleted']
143 type: str
144 """
145
146 EXAMPLES = """
147 # Using "deleted" state
148 #
149 # Before state:
150 # -------------
151 #
152 # sonic# show running-configuration | grep radius-server
153 # radius-server nas-ip 10.11.12.13
154 # radius-server statistics enable
155 # radius-server timeout 12
156 # radius-server retransmit 5
157 # radius-server auth-type chap
158 # radius-server host 10.10.10.10 protocol TLS security-profile rad-sec-prof
159 # radius-server host my-host1.dell auth-port 55 timeout 12 retransmit 7 auth-type chap priority 3 vrf VrfAnsibleTest source-interface Ethernet100
160
161 - name: Delete specified radius server configuration
162 dellemc.enterprise_sonic.sonic_radius_server:
163 config:
164 auth_type: chap
165 nas_ip: 10.11.12.13
166 timeout: 12
167 servers:
168 host:
169 - name: 10.10.10.10
170 state: deleted
171
172 # After state:
173 # ------------
174 #
175 # sonic# show running-configuration | grep radius-server
176 # radius-server statistics enable
177 # radius-server retransmit 5
178 # radius-server host my-host1.dell auth-port 55 timeout 12 retransmit 7 auth-type chap priority 3 vrf VrfAnsibleTest source-interface Ethernet100
179
180
181 # Using "deleted" state
182 #
183 # Before state:
184 # -------------
185 #
186 # sonic# show running-configuration | grep radius-server
187 # radius-server nas-ip 10.11.12.13
188 # radius-server statistics enable
189 # radius-server timeout 12
190 # radius-server retransmit 5
191 # radius-server auth-type chap
192 # radius-server host 10.10.10.10 protocol TLS security-profile rad-sec-prof
193 # radius-server host my-host1.dell auth-port 55 timeout 12 retransmit 7 auth-type chap priority 3 vrf VrfAnsibleTest source-interface Ethernet100
194
195 - name: Delete all radius server configuration
196 dellemc.enterprise_sonic.sonic_radius_server:
197 config:
198 state: deleted
199
200 # After state:
201 # ------------
202 #
203 # sonic# show running-configuration | grep radius-server
204 # (No radius-server configuration present)
205
206
207 # Using "merged" state
208 #
209 # Before state:
210 # -------------
211 #
212 # sonic# show running-configuration | grep radius-server
213 # (No radius-server configuration present)
214
215 - name: Merge radius server configuration
216 dellemc.enterprise_sonic.sonic_radius_server:
217 config:
218 auth_type: chap
219 timeout: 12
220 nas_ip: 10.11.12.13
221 retransmit: 5
222 statistics: true
223 servers:
224 host:
225 - name: my-host1.dell
226 auth_type: chap
227 priority: 3
228 vrf: VrfAnsibleTest
229 timeout: 12
230 port: 55
231 source_interface: Ethernet100
232 retransmit: 7
233 - name: "10.10.10.10"
234 protocol: "TLS"
235 security_profile: "rad-sec-prof"
236 state: merged
237
238 # After state:
239 # ------------
240 #
241 # sonic# show running-configuration | grep radius-server
242 # radius-server nas-ip 10.11.12.13
243 # radius-server statistics enable
244 # radius-server timeout 12
245 # radius-server retransmit 5
246 # radius-server auth-type chap
247 # radius-server host 10.10.10.10 protocol TLS security-profile rad-sec-prof
248 # radius-server host my-host1.dell auth-port 55 timeout 12 retransmit 7 auth-type chap priority 3 vrf VrfAnsibleTest source-interface Ethernet100
249
250
251 # Using "replaced" state
252 #
253 # Before state:
254 # -------------
255 #
256 # sonic# show running-configuration | grep radius-server
257 # radius-server nas-ip 10.11.12.13
258 # radius-server statistics enable
259 # radius-server timeout 12
260 # radius-server retransmit 5
261 # radius-server auth-type chap
262 # radius-server host 10.10.10.10 protocol TLS security-profile rad-sec-prof
263 # radius-server host my-host1.dell auth-port 55 timeout 12 retransmit 7 auth-type chap priority 3 vrf VrfAnsibleTest source-interface Ethernet100
264
265 - name: Replace specified radius server host configuration
266 sonic_radius_server:
267 config:
268 servers:
269 - host:
270 name: my-host1.dell
271 auth_type: mschapv2
272 source_interface: Ethernet12
273 state: replaced
274
275 # After state:
276 # ------------
277 #
278 # sonic# show running-configuration | grep radius-server
279 # radius-server nas-ip 10.11.12.13
280 # radius-server statistics enable
281 # radius-server timeout 12
282 # radius-server retransmit 5
283 # radius-server auth-type chap
284 # radius-server host 10.10.10.10 protocol TLS security-profile rad-sec-prof
285 # radius-server host my-host1.dell auth-type mschapv2 source-interface Ethernet12
286
287 # Using "overridden" state
288 #
289 # Before state:
290 # -------------
291 #
292 # sonic# show running-configuration | grep radius-server
293 # radius-server nas-ip 10.11.12.13
294 # radius-server statistics enable
295 # radius-server timeout 12
296 # radius-server retransmit 5
297 # radius-server auth-type chap
298 # radius-server host 10.10.10.10 protocol TLS security-profile rad-sec-prof
299 # radius-server host my-host1.dell auth-type mschapv2 source-interface Ethernet12
300
301 - name: Override radius server configuration
302 sonic_radius_server:
303 config:
304 servers:
305 - host:
306 name: 20.20.20.20
307 protocol: TLS
308 security_profile: rad-sec-prof
309 state: overridden
310
311 # After state:
312 # ------------
313 #
314 # sonic# show running-configuration | grep radius-server
315 # radius-server host 20.20.20.20 protocol TLS security-profile rad-sec-prof
316 """
317
318 RETURN = """
319 before:
320 description: The configuration prior to the module invocation.
321 returned: always
322 type: dict
323 after:
324 description: The resulting configuration module invocation.
325 returned: when changed
326 type: dict
327 after_generated:
328 description: The generated configuration from module invocation.
329 returned: when C(check_mode)
330 type: dict
331 commands:
332 description: The set of commands pushed to the remote device.
333 returned: always
334 type: list
335 sample: ['command 1', 'command 2', 'command 3']
336 """
337
338 from ansible.module_utils.basic import AnsibleModule
339 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.radius_server.radius_server import Radius_serverArgs
340 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.radius_server.radius_server import Radius_server
341
342
343 def main():
344 """
345 Main entry point for module execution
346
347 :returns: the result form module invocation
348 """
349 module = AnsibleModule(argument_spec=Radius_serverArgs.argument_spec,
350 supports_check_mode=True)
351
352 result = Radius_server(module).execute_module()
353 module.exit_json(**result)
354
355
356 if __name__ == '__main__':
357 main()