Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_acl_interfaces.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_acl_interfaces
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_acl_interfaces
17 version_added: '2.1.0'
18 notes:
19 - Supports C(check_mode).
20 short_description: Manage access control list (ACL) to interface binding on SONiC
21 description:
22 - This module provides configuration management of applying access control lists (ACL)
23 to interfaces in devices running SONiC.
24 - ACL needs to be created earlier in the device.
25 author: 'Arun Saravanan Balachandran (@ArunSaravananBalachandran)'
26 options:
27 config:
28 description:
29 - Specifies interface access-group configurations.
30 type: list
31 elements: dict
32 suboptions:
33 name:
34 description:
35 - Full name of the interface, i.e. Eth1/1.
36 type: str
37 required: true
38 access_groups:
39 description:
40 - Access-group configurations to be set for the interface.
41 type: list
42 elements: dict
43 suboptions:
44 type:
45 description:
46 - Type of the ACLs to be applied on the interface.
47 type: str
48 required: true
49 choices:
50 - mac
51 - ipv4
52 - ipv6
53 acls:
54 description:
55 - List of ACLs for the given type.
56 type: list
57 elements: dict
58 suboptions:
59 name:
60 description:
61 - Name of the ACL to be applied on the interface.
62 type: str
63 required: true
64 direction:
65 description:
66 - Specifies the direction of the packets that the ACL will be applied on.
67 type: str
68 required: true
69 choices:
70 - in
71 - out
72 state:
73 description:
74 - The state of the configuration after module completion.
75 - I(merged) - Merges provided interface access-group configuration with on-device configuration.
76 - I(replaced) - Replaces on-device access-group configuration of the specified interfaces with provided configuration.
77 - I(overridden) - Overrides all on-device interface access-group configurations with the provided configuration.
78 - I(deleted) - Deletes on-device interface access-group configuration.
79 type: str
80 choices:
81 - merged
82 - replaced
83 - overridden
84 - deleted
85 default: merged
86 """
87
88 EXAMPLES = """
89 # Using "merged" state
90 #
91 # Before state:
92 # -------------
93 #
94 # sonic# show mac access-group
95 # sonic#
96 # sonic# show ip access-group
97 # sonic#
98 # sonic# show ipv6 access-group
99 # Ingress IPV6 access-list ipv6-acl-1 on Eth1/1
100 # sonic#
101
102 - name: Merge provided interface access-group configurations
103 dellemc.enterprise_sonic.sonic_acl_interfaces:
104 config:
105 - name: 'Eth1/1'
106 access_groups:
107 - type: 'mac'
108 acls:
109 - name: 'mac-acl-1'
110 direction: 'in'
111 - name: 'mac-acl-2'
112 direction: 'out'
113 - type: 'ipv6'
114 acls:
115 - name: 'ipv6-acl-2'
116 direction: 'out'
117 - name: 'Eth1/2'
118 access_groups:
119 - type: 'ipv4'
120 acls:
121 - name: 'ip-acl-1'
122 direction: 'in'
123 state: merged
124
125 # After state:
126 # ------------
127 #
128 # sonic# show mac access-group
129 # Ingress MAC access-list mac-acl-1 on Eth1/1
130 # Egress MAC access-list mac-acl-2 on Eth1/1
131 # sonic#
132 # sonic# show ip access-group
133 # Ingress IP access-list ip-acl-1 on Eth1/2
134 # sonic#
135 # sonic# show ipv6 access-group
136 # Ingress IPV6 access-list ipv6-acl-1 on Eth1/1
137 # Egress IPV6 access-list ipv6-acl-2 on Eth1/1
138 # sonic#
139
140
141 # Using "replaced" state
142 #
143 # Before state:
144 # -------------
145 #
146 # sonic# show mac access-group
147 # Ingress MAC access-list mac-acl-1 on Eth1/1
148 # Egress MAC access-list mac-acl-2 on Eth1/1
149 # sonic#
150 # sonic# show ip access-group
151 # Ingress IP access-list ip-acl-1 on Eth1/2
152 # sonic#
153 # sonic# show ipv6 access-group
154 # Ingress IPV6 access-list ipv6-acl-1 on Eth1/1
155 # Egress IPV6 access-list ipv6-acl-2 on Eth1/1
156 # sonic#
157
158 - name: Replace device access-group configuration of specified interfaces with provided configuration
159 dellemc.enterprise_sonic.sonic_acl_interfaces:
160 config:
161 - name: 'Eth1/2'
162 access_groups:
163 - type: 'ipv6'
164 acls:
165 - name: 'ipv6-acl-2'
166 direction: 'out'
167 - name: 'Eth1/3'
168 access_groups:
169 - type: 'ipv4'
170 acls:
171 - name: 'ip-acl-2'
172 direction: 'out'
173 state: replaced
174
175 # After state:
176 # ------------
177 #
178 # sonic# show mac access-group
179 # Ingress MAC access-list mac-acl-1 on Eth1/1
180 # Egress MAC access-list mac-acl-2 on Eth1/1
181 # sonic#
182 # sonic# show ip access-group
183 # Egress IP access-list ip-acl-2 on Eth1/3
184 # sonic#
185 # sonic# show ipv6 access-group
186 # Ingress IPV6 access-list ipv6-acl-1 on Eth1/1
187 # Egress IPV6 access-list ipv6-acl-2 on Eth1/1
188 # Egress IPV6 access-list ipv6-acl-2 on Eth1/2
189 # sonic#
190
191
192 # Using "overridden" state
193 #
194 # Before state:
195 # -------------
196 #
197 # sonic# show mac access-group
198 # Ingress MAC access-list mac-acl-1 on Eth1/1
199 # Egress MAC access-list mac-acl-2 on Eth1/1
200 # sonic#
201 # sonic# show ip access-group
202 # Egress IP access-list ip-acl-2 on Eth1/3
203 # sonic#
204 # sonic# show ipv6 access-group
205 # Ingress IPV6 access-list ipv6-acl-1 on Eth1/1
206 # Egress IPV6 access-list ipv6-acl-2 on Eth1/1
207 # Egress IPV6 access-list ipv6-acl-2 on Eth1/2
208 # sonic#
209
210 - name: Override all interfaces access-group device configuration with provided configuration
211 dellemc.enterprise_sonic.sonic_acl_interfaces:
212 config:
213 - name: 'Eth1/1'
214 access_groups:
215 - type: 'ip'
216 acls:
217 - name: 'ip-acl-2'
218 direction: 'out'
219 - name: 'Eth1/2'
220 access_groups:
221 - type: 'ip'
222 acls:
223 - name: 'ip-acl-2'
224 direction: 'out'
225 state: overridden
226
227 # After state:
228 # ------------
229 #
230 # sonic# show mac access-group
231 # sonic#
232 # sonic# show ip access-group
233 # Egress IP access-list ip-acl-2 on Eth1/1
234 # Egress IP access-list ip-acl-2 on Eth1/2
235 # sonic#
236 # sonic# show ipv6 access-group
237 # sonic#
238
239
240 # Using "deleted" state
241 #
242 # Before state:
243 # -------------
244 #
245 # sonic# show mac access-group
246 # Ingress MAC access-list mac-acl-1 on Eth1/1
247 # Egress MAC access-list mac-acl-2 on Eth1/1
248 # sonic#
249 # sonic# show ip access-group
250 # Egress IP access-list ip-acl-2 on Eth1/3
251 # sonic#
252 # sonic# show ipv6 access-group
253 # Ingress IPV6 access-list ipv6-acl-1 on Eth1/1
254 # Egress IPV6 access-list ipv6-acl-2 on Eth1/1
255 # Egress IPV6 access-list ipv6-acl-2 on Eth1/2
256 # sonic#
257
258 - name: Delete specified interfaces access-group configurations
259 dellemc.enterprise_sonic.sonic_l2_acls:
260 config:
261 - name: 'Eth1/1'
262 access_groups:
263 - type: 'mac'
264 acls:
265 - name: 'mac-acl-1'
266 direction: 'in'
267 - type: 'ipv6'
268 - name: 'Eth1/2'
269 state: deleted
270
271 # After state:
272 # ------------
273 #
274 # sonic# show mac access-group
275 # Egress MAC access-list mac-acl-2 on Eth1/1
276 # sonic#
277 # sonic# show ip access-group
278 # Egress IP access-list ip-acl-2 on Eth1/3
279 # sonic#
280 # sonic# show ipv6 access-group
281 # sonic#
282
283
284 # Using "deleted" state
285 #
286 # Before state:
287 # -------------
288 #
289 # sonic# show mac access-group
290 # Ingress MAC access-list mac-acl-1 on Eth1/1
291 # Egress MAC access-list mac-acl-2 on Eth1/1
292 # sonic#
293 # sonic# show ip access-group
294 # Egress IP access-list ip-acl-2 on Eth1/3
295 # sonic#
296 # sonic# show ipv6 access-group
297 # Ingress IPV6 access-list ipv6-acl-1 on Eth1/1
298 # Egress IPV6 access-list ipv6-acl-2 on Eth1/1
299 # Egress IPV6 access-list ipv6-acl-2 on Eth1/2
300 # sonic#
301
302 - name: Delete all interface access-group configurations
303 dellemc.enterprise_sonic.sonic_acl_interfaces:
304 config:
305 state: deleted
306
307 # After state:
308 # ------------
309 #
310 # sonic# show mac access-group
311 # sonic#
312 # sonic# show ip access-group
313 # sonic#
314 # sonic# show ipv6 access-group
315 # sonic#
316 """
317
318 RETURN = """
319 before:
320 description: The configuration prior to the module invocation.
321 returned: always
322 type: list
323 sample: >
324 The configuration returned will always be in the same format
325 as the parameters above.
326 after:
327 description: The resulting configuration module invocation.
328 returned: when changed
329 type: list
330 sample: >
331 The configuration returned will always be in the same format
332 as the parameters above.
333 after_generated:
334 description: The generated configuration module invocation.
335 returned: when C(check_mode)
336 type: list
337 sample: >
338 The configuration returned will always be in the same format
339 as the parameters above.
340 commands:
341 description: The set of commands pushed to the remote device.
342 returned: always
343 type: list
344 sample: ['command 1', 'command 2', 'command 3']
345 """
346
347
348 from ansible.module_utils.basic import AnsibleModule
349 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.acl_interfaces.acl_interfaces import Acl_interfacesArgs
350 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.acl_interfaces.acl_interfaces import Acl_interfaces
351
352
353 def main():
354 """
355 Main entry point for module execution
356
357 :returns: the result form module invocation
358 """
359 module = AnsibleModule(argument_spec=Acl_interfacesArgs.argument_spec,
360 supports_check_mode=True)
361
362 result = Acl_interfaces(module).execute_module()
363 module.exit_json(**result)
364
365
366 if __name__ == '__main__':
367 main()