Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_drop_counter.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_drop_counter
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_drop_counter
17 version_added: 3.1.0
18 notes:
19 - Tested against Enterprise SONiC Distribution by Dell Technologies
20 - Supports C(check_mode)
21 short_description: Manage drop counter configuration on SONiC
22 description:
23 - This module provides configuration management of drop counter for devices running SONiC
24 author: S. Talabi (@stalabi1)
25 options:
26 config:
27 description:
28 - List of drop counter configurations
29 type: list
30 elements: dict
31 suboptions:
32 name:
33 description:
34 - Name of drop counter
35 type: str
36 required: true
37 alias:
38 description:
39 - Alias of drop counter
40 type: str
41 counter_description:
42 description:
43 - Description of drop counter
44 type: str
45 counter_type:
46 description:
47 - Type of drop counter
48 type: str
49 choices:
50 - PORT_INGRESS_DROPS
51 enable:
52 description:
53 - Enable drop counter
54 type: bool
55 group:
56 description:
57 - Group of drop counter
58 type: str
59 mirror:
60 description:
61 - Mirror session to mirror the drop counter
62 type: str
63 reasons:
64 description:
65 - List of drop counter reasons
66 type: list
67 elements: str
68 choices:
69 - ACL_ANY
70 - ANY
71 - DIP_LINK_LOCAL
72 - EXCEEDS_L3_MTU
73 - FDB_AND_BLACKHOLE_DISCARDS
74 - IP_HEADER_ERROR
75 - L3_EGRESS_LINK_DOWN
76 - MPLS_MISS
77 - SIP_LINK_LOCAL
78 - SMAC_EQUALS_DMAC
79 state:
80 description:
81 - The state of the configuration after module completion
82 type: str
83 choices:
84 - merged
85 - deleted
86 - replaced
87 - overridden
88 default: merged
89 """
90
91 EXAMPLES = """
92 # Using "merged" state
93 #
94 # Before state:
95 # -------------
96 #
97 # sonic# show running-configuration dropcounters
98 # (No 'dropcounters' configuration present)
99
100 - name: Merge drop counter configuration
101 dellemc.enterprise_sonic.sonic_drop_counter:
102 config:
103 - name: counter1
104 alias: c1
105 counter_description: abc
106 counter_type: PORT_INGRESS_DROPS
107 enable: true
108 group: group1
109 mirror: session1
110 reasons:
111 - ANY
112 state: merged
113
114 # After state:
115 # ------------
116 #
117 # sonic# show running-configuration dropcounters
118 # !
119 # dropcounters counter1
120 # enable
121 # type PORT_INGRESS_DROPS
122 # alias c1
123 # group group1
124 # description "abc"
125 # mirror session1
126 # add-reason ANY
127
128
129 # Using "replaced" state
130 #
131 # Before state:
132 # -------------
133 #
134 # sonic# show running-configuration dropcounters
135 # !
136 # dropcounters counter1
137 # enable
138 # type PORT_INGRESS_DROPS
139 # alias c1
140 # group group1
141 # description "abc"
142 # mirror session1
143 # add-reason ANY
144 # !
145 # dropcounters counter2
146 # no enable
147 # type PORT_INGRESS_DROPS
148 # alias drop2
149 # group group2
150 # description "xyz789"
151 # add-reason IP_HEADER_ERROR,L3_EGRESS_LINK_DOWN,SMAC_EQUALS_DMAC
152
153 - name: Replace drop counter configuration
154 dellemc.enterprise_sonic.sonic_drop_counter:
155 config:
156 - name: counter1
157 counter_description: abc123
158 state: replaced
159
160 # After state:
161 # ------------
162 #
163 # sonic# show running-configuration dropcounters
164 # !
165 # dropcounters counter1
166 # description "abc123"
167 # !
168 # dropcounters counter2
169 # no enable
170 # type PORT_INGRESS_DROPS
171 # alias drop2
172 # group group2
173 # description "xyz789"
174 # add-reason IP_HEADER_ERROR,L3_EGRESS_LINK_DOWN,SMAC_EQUALS_DMAC
175
176
177 # Using "overridden" state
178 #
179 # Before state:
180 # -------------
181 #
182 # sonic# show running-configuration dropcounters
183 # !
184 # dropcounters counter1
185 # enable
186 # type PORT_INGRESS_DROPS
187 # alias c1
188 # group group1
189 # description "abc"
190 # mirror session1
191 # add-reason ANY
192 # !
193 # dropcounters counter2
194 # no enable
195 # type PORT_INGRESS_DROPS
196 # alias drop2
197 # group group2
198 # description "xyz789"
199 # add-reason IP_HEADER_ERROR,L3_EGRESS_LINK_DOWN,SMAC_EQUALS_DMAC
200
201 - name: Override drop counter configuration
202 dellemc.enterprise_sonic.sonic_drop_counter:
203 config:
204 - name: counter3
205 alias: c3
206 counter_description: qwerty
207 counter_type: PORT_INGRESS_DROPS
208 enable: true
209 group: group3
210 mirror: session2
211 reasons:
212 - ACL_ANY
213 - FDB_AND_BLACKHOLE_DISCARDS
214 state: overridden
215
216 # After state:
217 # ------------
218 #
219 # sonic# show running-configuration dropcounters
220 # !
221 # dropcounters counter3
222 # enable
223 # type PORT_INGRESS_DROPS
224 # alias c3
225 # group group3
226 # description "qwerty"
227 # mirror session2
228 # add-reason ACL_ANY,FDB_AND_BLACKHOLE_DISCARDS
229
230
231 # Using "deleted" state
232 #
233 # Before state:
234 # -------------
235 #
236 # sonic# show running-configuration dropcounters
237 # !
238 # dropcounters counter1
239 # enable
240 # type PORT_INGRESS_DROPS
241 # alias c1
242 # group group1
243 # description "abc"
244 # mirror session1
245 # add-reason ANY
246 # !
247 # dropcounters counter2
248 # no enable
249 # type PORT_INGRESS_DROPS
250 # alias drop2
251 # group group2
252 # description "xyz789"
253 # add-reason IP_HEADER_ERROR,L3_EGRESS_LINK_DOWN,SMAC_EQUALS_DMAC
254
255 - name: Delete drop counter configuration
256 dellemc.enterprise_sonic.sonic_drop_counter:
257 config:
258 - name: counter1
259 alias: c1
260 counter_description: abc
261 - name: counter2
262 state: deleted
263
264 # After state:
265 # ------------
266 #
267 # sonic# show running-configuration dropcounters
268 # !
269 # dropcounters counter1
270 # enable
271 # type PORT_INGRESS_DROPS
272 # group group1
273 # mirror session1
274 # add-reason ANY
275
276
277 # Using "deleted" state
278 #
279 # Before state:
280 # -------------
281 #
282 # sonic# show running-configuration dropcounters
283 # !
284 # dropcounters counter1
285 # enable
286 # type PORT_INGRESS_DROPS
287 # group group1
288 # mirror session1
289 # add-reason ANY
290
291 - name: Delete all drop counter configuration
292 dellemc.enterprise_sonic.sonic_drop_counter:
293 config:
294 state: deleted
295
296 # After state:
297 # ------------
298 #
299 # (No 'dropcounters' configuration present)
300 """
301
302 RETURN = """
303 before:
304 description: The configuration prior to the module invocation.
305 returned: always
306 type: list
307 after:
308 description: The configuration resulting from module invocation.
309 returned: when changed
310 type: list
311 after_generated:
312 description: The generated configuration from module invocation.
313 returned: when C(check_mode)
314 type: list
315 commands:
316 description: The set of commands pushed to the remote device.
317 returned: always
318 type: list
319 sample: ['command 1', 'command 2', 'command 3']
320 """
321
322
323 from ansible.module_utils.basic import AnsibleModule
324 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.drop_counter.drop_counter import Drop_counterArgs
325 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.drop_counter.drop_counter import Drop_counter
326
327
328 def main():
329 """
330 Main entry point for module execution
331
332 :returns: the result form module invocation
333 """
334 module = AnsibleModule(argument_spec=Drop_counterArgs.argument_spec,
335 supports_check_mode=True)
336
337 result = Drop_counter(module).execute_module()
338 module.exit_json(**result)
339
340
341 if __name__ == '__main__':
342 main()