Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_lldp_global.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_lldp_global
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14
15 DOCUMENTATION = """
16 ---
17 module: sonic_lldp_global
18 version_added: '2.1.0'
19 notes:
20 - Tested against Enterprise SONiC Distribution by Dell Technologies.
21 - Supports C(check_mode).
22 short_description: Manage Global LLDP configurations on SONiC
23 description:
24 - This module provides configuration management of global LLDP parameters
25 for use on LLDP enabled Layer 2 interfaces of devices running SONiC.
26 - It is intended for use in conjunction with LLDP Layer 2 interface
27 configuration applied on participating interfaces.
28 author: 'Divya Balasubramanian(@divya-balasubramania)'
29 options:
30 config:
31 description: The set of link layer discovery protocol global attribute configurations
32 type: dict
33 suboptions:
34 enable:
35 description:
36 - This argument is a boolean value to enable or disable LLDP.
37 type: bool
38 multiplier:
39 description:
40 - Multiplier value is used to determine the timeout interval (i.e. hello-time x multiplier value)
41 - The range is from 1 to 10
42 type: int
43 system_description:
44 description:
45 - Description of this system to be sent in LLDP advertisements.
46 - When configured, this value is used in the advertisements
47 instead of the default system description.
48 type: str
49 system_name:
50 description:
51 - Specifying a descriptive system name using this command, user may find it easier to distinguish the device with LLDP.
52 - By default, the host name is used.
53 type: str
54 mode:
55 description:
56 - By default both transmit and receive of LLDP frames is enabled.
57 - This command can be used to configure either in receive only or transmit only mode.
58 type: str
59 choices:
60 - receive
61 - transmit
62 hello_time:
63 description:
64 - Frequency at which LLDP advertisements are sent (in seconds).
65 - The range is from 5 to 254 sec
66 type: int
67 tlv_select:
68 description:
69 - By default, management address and system capabilities TLV are advertised in LLDP frames.
70 - This configuration option can be used to selectively suppress sending of these TLVs
71 to the Peer.
72 type: dict
73 suboptions:
74 management_address:
75 description:
76 - Enable or disable management address TLV.
77 type: bool
78 system_capabilities:
79 description:
80 - Enable or disable system capabilities TLV.
81 type: bool
82 state:
83 description:
84 - The state specifies the type of configuration update to be performed on the device.
85 - If the state is "merged", merge specified attributes with existing configured attributes.
86 - For "deleted", delete the specified attributes from existing configuration.
87 type: str
88 choices:
89 - merged
90 - deleted
91 default: merged
92 """
93
94 EXAMPLES = """
95 # Using "deleted" state
96 #
97 # Before state:
98 # -------------
99 #
100 # sonic# show running-configuration
101 # !
102 # lldp receive
103 # lldp timer 200
104 # lldp multiplier 1
105 # lldp system-name 8999_System
106 # lldp system-description sonic_system
107 # !
108
109 - name: Delete LLDP configurations
110 dellemc.enterprise_sonic.sonic_lldp_global:
111 config:
112 hello_time: 200
113 system_description: sonic_system
114 mode: receive
115 multiplier: 1
116 state: deleted
117
118 # After state:
119 # ------------
120 # sonic# show running-configuration | grep lldp
121 # !
122 # lldp system-name 8999_System
123 # !
124 # sonic#
125
126
127 # Using "deleted" state
128 #
129 # Before state:
130 # -------------
131 #
132 # sonic# show running-configuration | grep lldp
133 # sonic#
134
135 - name: Delete default LLDP configurations
136 dellemc.enterprise_sonic.sonic_lldp_global:
137 config:
138 tlv_select:
139 system_capabilities: true
140 state: deleted
141
142 # After state:
143 # ------------
144 # sonic# show running-configuration
145 # !
146 # no lldp tlv-select system-capabilities
147 # !
148
149
150 # Using "deleted" state
151 #
152 # Before state:
153 # -------------
154 #
155 # sonic# show running-configuration | grep lldp
156 # !
157 # lldp receive
158 # lldp timer 200
159 # lldp multiplier 1
160 # lldp system-name 8999_System
161 # lldp system-description sonic_system
162 # !
163
164 - name: Delete all LLDP configuration
165 dellemc.enterprise_sonic.sonic_lldp_global:
166 config:
167 state: deleted
168
169 # After state: (No LLDP global configuration present.)
170 # ------------
171 # sonic# show running-configuration | grep lldp
172 # sonic#
173
174
175 # Using "merged" state
176 #
177 # Before state:
178 # -------------
179 #
180 # sonic# show running-configuration | grep lldp
181 # sonic#
182
183 - name: Modify LLDP configurations
184 dellemc.enterprise_sonic.sonic_lldp_global:
185 config:
186 enable: false
187 multiplier: 9
188 system_name: CR_sonic
189 hello_time: 18
190 mode: receive
191 system_description: Sonic_System
192 tlv_select:
193 management_address: true
194 system_capabilities: false
195 state: merged
196
197 # After state:
198 # ------------
199 # sonic# show running-configuration | grep lldp
200 # !
201 # no lldp enable
202 # no lldp tlv-select system_capabilities
203 # lldp receive
204 # lldp timer 18
205 # lldp multiplier 9
206 # lldp system-name CR_sonic
207 # lldp system-description Sonic_System
208 # !
209
210
211 # Using "merged" state
212 #
213 # Before state:
214 # -------------
215 #
216 # sonic# show running-configuration | grep lldp
217 # !
218 # lldp receive
219 # lldp timer 200
220 # lldp multiplier 1
221 # lldp system-name 8999_System
222 # lldp system-description sonic_system
223 # !
224
225 - name: Modify LLDP configurations
226 dellemc.enterprise_sonic.sonic_lldp_global:
227 config:
228 multiplier: 9
229 system_name: CR_sonic
230 state: merged
231
232 # After state:
233 # ------------
234 # sonic# show running-configuration | grep lldp
235 # !
236 # lldp receive
237 # lldp timer 200
238 # lldp multiplier 9
239 # lldp system-name CR_sonic
240 # lldp system-description sonic_system
241 # !
242 """
243
244 RETURN = """
245 before:
246 description: The configuration prior to the module invocation.
247 returned: always
248 sample: >
249 The configuration returned will always be in the same format
250 as the parameters above.
251 type: list
252 after:
253 description: The resulting configuration module invocation.
254 returned: when changed
255 sample: >
256 The configuration returned will always be in the same format
257 as the parameters above.
258 type: list
259 after_generated:
260 description: The generated configuration module invocation.
261 returned: when C(check_mode)
262 sample: >
263 The configuration returned will always be in the same format
264 as the parameters above.
265 type: list
266 commands:
267 description: The set of commands pushed to the remote device.
268 returned: always
269 type: list
270 sample: ['command 1', 'command 2', 'command 3']
271 """
272
273
274 from ansible.module_utils.basic import AnsibleModule
275 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.lldp_global.lldp_global import Lldp_globalArgs
276 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.lldp_global.lldp_global import Lldp_global
277
278
279 def main():
280 """
281 Main entry point for module execution
282
283 :returns: the result form module invocation
284 """
285 module = AnsibleModule(argument_spec=Lldp_globalArgs.argument_spec,
286 supports_check_mode=True)
287
288 result = Lldp_global(module).execute_module()
289 module.exit_json(**result)
290
291
292 if __name__ == '__main__':
293 main()