Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_ptp_default_ds.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_ptp_default_ds
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_ptp_default_ds
17 version_added: '3.1.0'
18 short_description: Manage global PTP configurations on SONiC
19 description:
20 - This module provides configuration management of global PTP
21 parameters for devices running SONiC.
22 - The device should have timing chip support.
23 author: 'Pranesh Raagav S (@PraneshRaagavS)'
24 options:
25 config:
26 description:
27 - Specifies global PTP clock configurations.
28 type: dict
29 suboptions:
30 priority1:
31 description:
32 - The priority1 attribute of the local clock.
33 - The range is from 0 to 255.
34 type: int
35 priority2:
36 description:
37 - The priority2 attribute of the local clock.
38 - The range is from 0 to 255.
39 type: int
40 domain_number:
41 description:
42 - The domain number of the current syntonization domain.
43 - The range is from 0 to 127.
44 type: int
45 log_announce_interval:
46 description:
47 - The base-2 logarithm of the mean announceInterval (mean time
48 interval between successive Announce messages).
49 type: int
50 announce_receipt_timeout:
51 description:
52 - The number of announceIntervals that have to pass
53 without receipt of an Announce message before the
54 occurrence of the event ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES.
55 type: int
56 log_sync_interval:
57 description:
58 - The base-2 logarithm of the mean SyncInterval for multicast messages.
59 type: int
60 log_min_delay_req_interval:
61 description:
62 - The base-2 logarithm of the minDelayReqInterval.
63 - The minimum permitted mean time interval between successive Delay_Req messages.
64 type: int
65 two_step_flag:
66 description:
67 - The clockAccuracy indicates the expected accuracy of the clock.
68 type: int
69 clock_type:
70 description:
71 - Specifies the type of clock configured in the PTP domain.
72 type: str
73 choices: ['BC', 'E2E_TC', 'P2P_TC', 'disable']
74 network_transport:
75 description:
76 - The network transport used for communication.
77 type: str
78 choices: ['L2', 'UDPv4', 'UDPv6']
79 unicast_multicast:
80 description:
81 - Specifies whether the network transport uses unicast or multicast communication.
82 type: str
83 choices: ['unicast', 'multicast']
84 domain_profile:
85 description:
86 - The method to be used when comparing data sets during the Best Master Clock Algorithm.
87 type: str
88 choices: ['ieee1588', 'G.8275.1', 'G.8275.2']
89 source_interface:
90 description:
91 - Source interface whose IP to use as source ip for PTP IPv4
92 and IPv6 multicast transport mode.
93 type: str
94
95 state:
96 description:
97 - The state of the configuration after module completion.
98 - C(merged) - Merges provided PTP configuration with on-device
99 configuration.
100 - C(replaced) - Replaces on-device PTP configuration with provided
101 configuration.
102 - C(overridden) - Overrides all on-device PTP configurations with the
103 provided configuration.
104 - C(deleted) - Deletes on-device PTP configuration.
105 type: str
106 choices:
107 - merged
108 - deleted
109 - replaced
110 - overridden
111 default: merged
112 """
113 EXAMPLES = """
114 # Using deleted
115 #
116 # Before State:
117 # -------------
118 #
119 # sonic# show running-configuration ptp
120 # ptp network-transport l2 multicast
121 # ptp domain 25
122 # ptp domain-profile default
123 # ptp priority1 101
124 # ptp priority2 91
125 # ptp log-announce-interval 1
126 # ptp log-sync-interval -3
127 # sonic#
128
129 - name: Delete specified PTP configurations
130 dellemc.enterprise_sonic.sonic_ptp:
131 config:
132 log-sync-interval: -3
133 log-announce-interval: 1
134 network-transport: 'L2'
135 unicast-multicast: 'multicast'
136 priority1: 101
137 priority2: 91
138 domain-number: 25
139 state: deleted
140
141 # After State:
142 # ------------
143 #
144 # sonic# show running-configuration ptp
145 # ptp domain-profile default
146 # sonic#
147
148
149 # Using deleted
150 #
151 # Before State:
152 # -------------
153 #
154 # sonic# show running-configuration ptp
155 # ptp mode boundary-clock
156 # ptp network-transport ipv6 unicast
157 # ptp domain 45
158 # ptp domain-profile g8275.2
159 # ptp announce-timeout 3
160 # sonic#
161
162 - name: Delete all PTP configurations
163 dellemc.enterprise_sonic.sonic_ptp:
164 config:
165 state: deleted
166
167 # After State:
168 # ------------
169 #
170 # sonic# show running-configuration ptp
171 # sonic#
172
173
174 # Using merged
175 #
176 # Before State:
177 # -------------
178 #
179 # sonic# show running-configuration ptp
180 # ptp domain 35
181 # ptp domain-profile default
182 # ptp priority2 100
183 # sonic#
184
185 - name: Merge provided global PTP configurations
186 dellemc.enterprise_sonic.sonic_ptp:
187 config:
188 domain-profile: 'G.8275.1'
189 log-sync-interval: -4
190 log-announce-interval: -3
191 announce-receipt-timeout: 5
192 log-min-delay-req-interval: -4
193 clock-type: 'BC'
194 network-transport: 'L2'
195 unicast-multicast: 'multicast'
196 state: merged
197
198 # After State:
199 # ------------
200 #
201 # sonic# show running-configuration ptp
202 # ptp mode boundary-clock
203 # ptp network-transport l2 multicast
204 # ptp domain 35
205 # ptp domain-profile g8275.1
206 # ptp priority2 100
207 # ptp log-announce-interval -3
208 # ptp announce-timeout 5
209 # ptp log-sync-interval -4
210 # ptp log-min-delay-req-interval -4
211 # sonic#
212
213
214 # Using replaced
215 #
216 # Before State:
217 # -------------
218 #
219 # sonic# show running-configuration ptp
220 # ptp network-transport ipv4 unicast
221 # ptp domain 44
222 # ptp domain-profile default
223 # ptp priority1 100
224 # ptp priority2 90
225 # ptp log-announce-interval -2
226 # ptp log-sync-interval -4
227 # sonic#
228
229 - name: Replace global PTP configurations
230 dellemc.enterprise_sonic.sonic_ptp:
231 config:
232 log-sync-interval: -3
233 log-announce-interval: 1
234 network-transport: 'L2'
235 unicast-multicast: 'multicast'
236 priority1: 101
237 priority2: 91
238 domain-number: 25
239 state: replaced
240
241 # After State:
242 # ------------
243 #
244 # sonic# show running-configuration ptp
245 # ptp network-transport l2 multicast
246 # ptp domain 25
247 # ptp domain-profile default
248 # ptp priority1 101
249 # ptp priority2 91
250 # ptp log-announce-interval 1
251 # ptp log-sync-interval -3
252 # sonic#
253
254
255 # Using overridden
256 #
257 # Before State:
258 # -------------
259 #
260 # sonic# show running-configuration ptp
261 # ptp mode boundary-clock
262 # ptp network-transport l2 multicast
263 # ptp domain 35
264 # ptp domain-profile g8275.1
265 # ptp priority2 100
266 # ptp log-announce-interval -3
267 # ptp announce-timeout 5
268 # ptp log-sync-interval -4
269 # ptp log-min-delay-req-interval -4
270 # sonic#
271
272 - name: Override device configuration of ptp with provided configuration
273 dellemc.enterprise_sonic.sonic_ptp:
274 config:
275 domain-number: 44
276 domain-profile: 'G.8275.2'
277 network-transport: 'ipv4'
278 unicast-multicast: 'unicast'
279 state: overridden
280
281 # After State:
282 # ------------
283 #
284 # sonic# show running-configuration ptp
285 # ptp network-transport ipv4 unicast
286 # ptp domain 44
287 # ptp domain-profile g8275.2
288 # sonic#
289 """
290 RETURN = """
291 before:
292 description: The configuration prior to the model invocation.
293 returned: always
294 type: dict
295 after:
296 description: The configuration resulting from module invocation.
297 returned: when changed
298 type: dict
299 after_generated:
300 description: The configuration that would be generated by module invocation in non-check mode.
301 returned: when C(check_mode)
302 sample: >
303 The configuration returned will always be in the same format
304 as the parameters above.
305 type: dict
306 commands:
307 description: The set of commands pushed to the remote device.
308 returned: always
309 type: list
310 """
311
312
313 from ansible.module_utils.basic import AnsibleModule
314 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.ptp_default_ds.ptp_default_ds import Ptp_default_dsArgs
315 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.ptp_default_ds.ptp_default_ds import Ptp_default_ds
316
317
318 def main():
319 """
320 Main entry point for module execution
321
322 :returns: the result form module invocation
323 """
324 module = AnsibleModule(argument_spec=Ptp_default_dsArgs.argument_spec,
325 supports_check_mode=True)
326
327 result = Ptp_default_ds(module).execute_module()
328 module.exit_json(**result)
329
330
331 if __name__ == '__main__':
332 main()