Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_ptp_port_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
9 """
10 The module file for sonic_ptp_port_ds
11 """
12
13 from __future__ import absolute_import, division, print_function
14 __metaclass__ = type
15
16 DOCUMENTATION = """
17 ---
18 module: sonic_ptp_port_ds
19 version_added: '3.1.0'
20 notes:
21 - Supports C(check_mode).
22 short_description: Manage port specific PTP configurations on SONiC
23 description:
24 - This module provides configuration management of port-specific
25 PTP parameters for devices running SONiC.
26 author: 'Vidya Chidambaram (@vidyac86)'
27 options:
28 config:
29 description:
30 - Specifies port-specific PTP configurations.
31 type: list
32 elements: dict
33 suboptions:
34 interface:
35 description:
36 - Specifies the name of the interface.
37 required: true
38 type: str
39 role:
40 description:
41 - Specifies the role of interface.
42 type: str
43 choices: ['dynamic', 'master', 'slave']
44 local_priority:
45 description:
46 - Specifies the local-priority attribute used for the profile G8275-1 and G8275-2.
47 - The range is from 1 to 255.
48 type: int
49 default:
50 unicast_table:
51 description:
52 - List of ip addresses to use for PTP master.
53 type: list
54 elements: str
55 state:
56 description:
57 - The state of the configuration after module completion.
58 - C(merged) - Merges provided interface-specific PTP configuration with on-device configuration.
59 - C(replaced) - Replaces on-device PTP configuration of the specified interfaces with provided configuration.
60 - C(overridden) - Overrides all on-device interface-specific PTP configurations with the provided configuration.
61 - C(deleted) - Deletes on-device interface-specific PTP configuration.
62 type: str
63 choices:
64 - merged
65 - deleted
66 - replaced
67 - overridden
68 default: merged
69 """
70 EXAMPLES = """
71 # Using deleted
72 #
73 # Before State:
74 # -------------
75 #
76 # sonic# show running-configuration ptp | grep "ptp port"
77 # ptp port add Ethernet0 role slave local-priority 100
78 # ptp port add Ethernet4 role master local-priority 90
79 # ptp port master-table Ethernet0 add 1.1.1.1
80 # ptp port master-table Ethernet0 add 1.1.1.2
81 # sonic#
82
83 - name: Delete specified PTP port configurations
84 dellemc.enterprise_sonic.sonic_ptp_port_ds:
85 config:
86 - interface: 'Ethernet4'
87 role: 'master'
88 local_priority: 90
89 - interface: 'Ethernet0'
90 role: 'slave'
91 local_priority: 100
92 unicast_table:
93 - '1.1.1.1'
94 - '1.1.1.2'
95 state: deleted
96
97 # After State:
98 # ------------
99 #
100 # sonic# show running-configuration ptp
101 # ptp port add Ethernet4 role master local-priority 90
102 # sonic#
103
104
105 # Using deleted
106 #
107 # Before State:
108 # -------------
109 #
110 # sonic# show running-configuration ptp | grep "ptp port"
111 # ptp port add Ethernet0 role slave local-priority 100
112 # ptp port add Ethernet4 role master local-priority 90
113 # ptp port master-table Ethernet0 add 1.1.1.1
114 # ptp port master-table Ethernet0 add 1.1.1.2
115 # sonic#
116
117 - name: Delete all PTP configurations in the specified port
118 dellemc.enterprise_sonic.sonic_ptp_port_ds:
119 config:
120 - interface: 'Ethernet0'
121 state: deleted
122
123 # After State:
124 # ------------
125 #
126 # sonic# show running-configuration ptp
127 # ptp port add Ethernet4 role master local-priority 90
128 # sonic#
129
130
131 # Using deleted
132 #
133 # Before State:
134 # -------------
135 #
136 # sonic# show running-configuration ptp | grep "ptp port"
137 # ptp port add Ethernet0 role slave local-priority 100
138 # ptp port add Ethernet4 role master local-priority 90
139 # ptp port master-table Ethernet0 add 1.1.1.1
140 # ptp port master-table Ethernet0 add 1.1.1.2
141 # sonic#
142
143 - name: Delete all PTP port configurations
144 dellemc.enterprise_sonic.sonic_ptp_port_ds:
145 config:
146 state: deleted
147
148 # After State:
149 # ------------
150 #
151 # sonic# show running-configuration ptp
152 # sonic#
153
154 # Using merged
155 #
156 # Before State:
157 # -------------
158 #
159 # sonic# show running-configuration ptp | grep "ptp port"
160 # ptp port add Ethernet0
161 # sonic#
162
163 - name: Merge provided PTP port configurations
164 dellemc.enterprise_sonic.sonic_ptp_port_ds:
165 config:
166 - interface: 'Ethernet0'
167 role: 'slave'
168 local_priority: 100
169 state: merged
170
171 # After State:
172 # ------------
173 #
174 # sonic# show running-configuration ptp | grep "ptp port"
175 # ptp port add Ethernet0 role slave local-priority 100
176 # sonic#
177
178
179 # Using replaced
180 #
181 # Before State:
182 # -------------
183 #
184 # sonic# do show running-configuration | grep "ptp port"
185 # ptp port add Ethernet0 role master local-priority 10
186 # ptp port add Ethernet1 local-priority 100
187 # ptp port add Ethernet2 role slave
188 # ptp port master-table Ethernet1 add 1.1.1.1
189 # sonic#
190
191 - name: Replace PTP configurations for specified port
192 dellemc.enterprise_sonic.sonic_ptp_port_ds:
193 config:
194 - interface: 'Ethernet0'
195 role: 'slave'
196 unicast_table:
197 - '2.2.2.2'
198 state: replaced
199
200 # After State:
201 # ------------
202 #
203 # sonic# do show running-configuration | grep "ptp port"
204 # ptp port add Ethernet0 role slave
205 # ptp port add Ethernet1 local-priority 100
206 # ptp port add Ethernet2 role slave
207 # ptp port master-table Ethernet0 add 2.2.2.2
208 # ptp port master-table Ethernet1 add 1.1.1.1
209 # sonic#
210
211
212 # Using overridden
213 #
214 # Before State:
215 # -------------
216 #
217 # sonic# show running-configuration ptp | grep "ptp port"
218 # ptp port add Ethernet0 role slave local-priority 100
219 # ptp port master-table Ethernet0 add 1.1.1.1
220 # sonic#
221
222 - name: Override device PTP port configuration with provided configuration
223 dellemc.enterprise_sonic.sonic_ptp_port_ds:
224 config:
225 - interface: 'Ethernet4'
226 role: 'master'
227 local_priority: 90
228 state: overridden
229
230 # After State:
231 # ------------
232 #
233 # sonic# show running-configuration ptp | grep "ptp port"
234 # ptp port add Ethernet4 role master local-priority 90
235 # sonic#
236 """
237 RETURN = """
238 before:
239 description: The configuration prior to the model invocation.
240 returned: always
241 sample: >
242 The configuration returned will always be in the same format
243 of the parameters above.
244 type: dict
245 after:
246 description: The resulting configuration model invocation.
247 returned: when changed
248 sample: >
249 The configuration returned will always be in the same format
250 of the parameters above.
251 type: dict
252 after_generated:
253 description: The generated configuration on module invocation.
254 returned: when C(check_mode)
255 type: list
256 sample: >
257 The configuration returned will always be in the same format
258 as the parameters above.
259 commands:
260 description: The set of commands pushed to the remote device.
261 returned: always
262 type: list
263 sample: ['command 1', 'command 2', 'command 3']
264 """
265
266
267 from ansible.module_utils.basic import AnsibleModule
268 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.ptp_port_ds.ptp_port_ds import Ptp_port_dsArgs
269 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.ptp_port_ds.ptp_port_ds import Ptp_port_ds
270
271
272 def main():
273 """
274 Main entry point for module execution
275
276 :returns: the result form module invocation
277 """
278 module = AnsibleModule(argument_spec=Ptp_port_dsArgs.argument_spec,
279 supports_check_mode=True)
280
281 result = Ptp_port_ds(module).execute_module()
282 module.exit_json(**result)
283
284
285 if __name__ == '__main__':
286 main()