Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_login_lockout.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_login_lockout
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_login_lockout
17 version_added: 2.5.0
18 short_description: Manage Global Login Lockout configurations on SONiC
19 description:
20 - This module provides configuration management of login lockout parameters.
21 - Login Lockout feature is to lock out the user account for user-lockout-period
22 after the max-retry failed attempts. Console exempt option can be enabled
23 to skip the login lockout validations for console users.
24 author: 'Arul Kumar Shankara Narayanan(@arulkumar9690)'
25 options:
26 config:
27 description: The set of login lockout attribute configurations
28 type: dict
29 suboptions:
30 console_exempt:
31 description:
32 - Exempt console logins from account lockout.
33 type: bool
34 period:
35 description:
36 - Account lockout period in minutes
37 - The range is from 0 to 43200
38 type: int
39 max_retries:
40 description:
41 - The number of maximum password retries.
42 - The range is from 0 to 16
43 type: int
44 state:
45 description:
46 - Specifies the operation to be performed on the login attributes configured on the device.
47 - If the state is "merged", merge specified attributes with existing configured login attributes.
48 - For "deleted", delete the specified login attributes from existing configuration.
49 - For "overridden", Overrides all on-device login lockout configurations with the provided configuration.
50 - For "replaced", Replaces on-device login lockout configurations with the provided configuration.
51 type: str
52 choices:
53 - merged
54 - deleted
55 - overridden
56 - replaced
57 default: merged
58 """
59
60 EXAMPLES = """
61 # Using "deleted" state
62 #
63 # Before state:
64 # -------------
65 #
66 # sonic# show running-configuration | grep lockout
67 # !
68 # login lockout period 12
69 # login lockout max-retries 5
70 # login lockout console-exempt
71 # !
72
73 - name: Delete Login Lockout configurations
74 dellemc.enterprise_sonic.sonic_login_lockout:
75 config:
76 period: 12
77 max_retries: 5
78 state: deleted
79
80 # After state:
81 # ------------
82 # sonic# show running-configuration | grep lockout
83 # !
84 # login lockout console-exempt
85 # !
86 # sonic#
87
88
89 # Using "merged" state
90 #
91 # Before state:
92 # -------------
93 #
94 # sonic# show running-configuration | grep lockout
95 # sonic#
96
97 - name: Modify Login Lockout configurations
98 dellemc.enterprise_sonic.sonic_login_lockout:
99 config:
100 console_exempt: true
101 period: 12
102 max_retries: 5
103 state: merged
104
105 # After state:
106 # ------------
107 # sonic# show running-configuration | grep lockout
108 # !
109 # login lockout period 12
110 # login lockout max-retries 5
111 # login lockout console-exempt
112 # !
113
114 # Using "overridden" state
115 #
116 # Before state:
117 # -------------
118 #
119 # sonic# show running-configuration | grep lockout
120 # !
121 # login lockout period 10
122 # login lockout max-retries 2
123 # !
124 # sonic#
125
126 - name: Override Login Lockout configurations
127 dellemc.enterprise_sonic.sonic_login_lockout:
128 config:
129 console_exempt: true
130 period: 11
131 max_retries: 3
132 state: overridden
133
134 # After state:
135 # ------------
136 # sonic# show running-configuration | grep lockout
137 # !
138 # login lockout period 11
139 # login lockout max-retries 3
140 # login lockout console-exempt
141 # !
142
143 # Using "replaced" state
144 #
145 # Before state:
146 # -------------
147 #
148 # sonic# show running-configuration | grep lockout
149 # !
150 # login lockout period 10
151 # login lockout max-retries 2
152 # !
153 # sonic#
154
155 - name: Replace Login Lockout configurations
156 dellemc.enterprise_sonic.sonic_login_lockout:
157 config:
158 period: 15
159 state: replaced
160
161 # After state:
162 # ------------
163 # sonic# show running-configuration | grep lockout
164 # !
165 # login lockout period 15
166 # !
167 """
168
169 RETURN = """
170 before:
171 description: The configuration prior to the module invocation.
172 returned: always
173 type: dict
174 sample: >
175 The configuration returned will always be in the same format
176 as the parameters above.
177 after:
178 description: The resulting configuration module invocation.
179 returned: when changed
180 type: dict
181 sample: >
182 The configuration returned will always be in the same format
183 as the parameters above.
184 commands:
185 description: The set of commands pushed to the remote device.
186 returned: always
187 type: list
188 sample: ['command 1', 'command 2', 'command 3']
189 """
190
191 from ansible.module_utils.basic import AnsibleModule
192 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.login_lockout.login_lockout import Login_lockoutArgs
193 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.login_lockout.login_lockout import Login_lockout
194
195
196 def main():
197 """
198 Main entry point for module execution
199
200 :returns: the result form module invocation
201 """
202 module = AnsibleModule(argument_spec=Login_lockoutArgs.argument_spec,
203 supports_check_mode=True)
204
205 result = Login_lockout(module).execute_module()
206 module.exit_json(**result)
207
208
209 if __name__ == '__main__':
210 main()