Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_fbs_policies.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_fbs_policies
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_fbs_policies
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 flow based services (FBS) policies configuration on SONiC
22 description:
23 - This module provides configuration management of FBS policies for devices running SONiC
24 author: S. Talabi (@stalabi1)
25 options:
26 config:
27 description:
28 - FBS policies configuration
29 type: list
30 elements: dict
31 suboptions:
32 policy_name:
33 description:
34 - Name of policy
35 type: str
36 required: true
37 policy_type:
38 description:
39 - Type of policy
40 type: str
41 choices: ['acl-copp', 'copp', 'forwarding', 'monitoring', 'qos']
42 policy_description:
43 description:
44 - Description of policy
45 type: str
46 sections:
47 description:
48 - Policy sections configuration
49 type: list
50 elements: dict
51 suboptions:
52 class:
53 description:
54 - Name of classifier
55 type: str
56 required: true
57 priority:
58 description:
59 - Flow priority in the policy, range 0-4095
60 type: int
61 section_description:
62 description:
63 - Description of section
64 type: str
65 acl_copp:
66 description:
67 - ACL CoPP configuration
68 - I(policy_type) must be configured to C(acl-copp) for user-assigned policy names
69 - or C(copp) for I(policy_name = copp-system-policy)
70 type: dict
71 suboptions:
72 cpu_queue_index:
73 description:
74 - CPU queue index, range 0-31
75 type: int
76 policer:
77 description:
78 - Traffic policing configuration
79 type: dict
80 suboptions:
81 cir:
82 description:
83 - Committed information rate measured in bps, range 1-4294967295
84 type: int
85 pir:
86 description:
87 - Peak information rate measured in bps, range 1-4294967295
88 type: int
89 cbs:
90 description:
91 - Committed burst size measured Bps, range 1-4294967295
92 type: int
93 pbs:
94 description:
95 - Peak burst size measured in Bps, range 1-4294967295
96 type: int
97 qos:
98 description:
99 - QoS action configuration
100 - I(policy_type) must be configured to C(qos)
101 type: dict
102 suboptions:
103 output_queue_index:
104 description:
105 - Output queue index, range 0-7
106 type: int
107 policer:
108 description:
109 - Traffic policing configuration
110 type: dict
111 suboptions:
112 cir:
113 description:
114 - Committed information rate measured in bps, range 1-4294967295
115 type: int
116 pir:
117 description:
118 - Peak information rate measured in bps, range 1-4294967295
119 type: int
120 cbs:
121 description:
122 - Committed burst size measured Bps, range 1-4294967295
123 type: int
124 pbs:
125 description:
126 - Peak burst size measured in Bps, range 1-4294967295
127 type: int
128 remark:
129 description:
130 - Remark configuration
131 type: dict
132 suboptions:
133 set_dscp:
134 description:
135 - Set DSCP remarking value, range 0-63
136 type: int
137 set_dot1p:
138 description:
139 - Set Dot1p remarking value, range 0-7
140 type: int
141 mirror_sessions:
142 description:
143 - Mirroring sessions configuration
144 - I(policy_type) must be configured to C(monitoring)
145 type: list
146 elements: dict
147 suboptions:
148 session_name:
149 description:
150 - Name of the mirror session
151 type: str
152 required: true
153 forwarding:
154 description:
155 - Forwarding actions configuration
156 - I(policy_type) must be configured to C(forwarding)
157 type: dict
158 suboptions:
159 ars_disable:
160 description:
161 - Enable/disable adaptive routing and switching forwarding
162 - Functional default is C(false)
163 type: bool
164 egress_interfaces:
165 description:
166 - Egress interfaces configuration
167 type: list
168 elements: dict
169 suboptions:
170 intf_name:
171 description:
172 - Name of interface
173 type: str
174 required: true
175 priority:
176 description:
177 - Priority of the egress interfaces to be selected for forwarding, range 1-65535
178 type: int
179 next_hops:
180 description:
181 - Next hops configuration for L3 forwarding
182 type: list
183 elements: dict
184 suboptions:
185 address:
186 description:
187 - Forwarding IP/IPv6 address
188 type: str
189 required: true
190 vrf:
191 description:
192 - Forwarding network instance
193 type: str
194 priority:
195 description:
196 - Priority of the next hop to be selected for forwarding, range 1-65535
197 type: int
198 next_hop_groups:
199 description:
200 - Next hop groups configuration for L3 forwarding
201 type: list
202 elements: dict
203 suboptions:
204 group_name:
205 description:
206 - Name of next hop group
207 type: str
208 required: true
209 group_type:
210 description:
211 - Type of next hop group
212 type: str
213 choices: ['ipv4', 'ipv6']
214 priority:
215 description:
216 - Priority of the next hop group to be selected for forwarding, range 1-65535
217 type: int
218 replication_groups:
219 description:
220 - Replication groups configuration for L3 forwarding
221 type: list
222 elements: dict
223 suboptions:
224 group_name:
225 description:
226 - Name of replication group
227 type: str
228 required: true
229 group_type:
230 description:
231 - Type of replication group
232 type: str
233 choices: ['ipv4', 'ipv6']
234 priority:
235 description:
236 - Priority of the replication group to be selected for forwarding, range 1-65535
237 type: int
238 state:
239 description:
240 - The state of the configuration after module completion
241 type: str
242 choices: ['merged', 'deleted', 'replaced', 'overridden']
243 default: merged
244 """
245
246 EXAMPLES = """
247 # Using "merged" state
248 #
249 # Before state:
250 # -------------
251 #
252 # sonic# show running-configuration policy-map
253 # (No policy-map configuration present)
254
255 - name: Merge FBS policies configuration
256 dellemc.enterprise_sonic.sonic_fbs_policies:
257 config:
258 - policy_name: policy1
259 policy_description: abc
260 policy_type: forwarding
261 sections:
262 - class: class1
263 forwarding:
264 ars_disable: true
265 egress_interfaces:
266 - intf_name: Ethernet96
267 priority: 1
268 priority: 0
269 section_description: xyz
270 - policy_name: policy2
271 policy_description: qwerty
272 policy_type: acl-copp
273 sections:
274 - class: class1
275 acl_copp:
276 cpu_queue_index: 0
277 policer:
278 cbs: 80
279 cir: 75
280 pbs: 95
281 pir: 96
282 priority: 0
283 - policy_name: policy3
284 policy_description: 'this is policy 3'
285 policy_type: qos
286 sections:
287 - class: class1
288 qos:
289 output_queue_index: 0
290 policer:
291 cbs: 15
292 cir: 20
293 pbs: 21
294 pir: 24
295 remark:
296 set_dot1p: 0
297 set_dscp: 0
298 priority: 0
299 - policy_name: policy4
300 policy_description: 'this is policy 4'
301 policy_type: monitoring
302 sections:
303 - class: class1
304 mirror_sessions:
305 - session_name: session1
306 priority: 0
307 - policy_name: policy5
308 policy_description: abc
309 policy_type: forwarding
310 sections:
311 - class: class1
312 forwarding:
313 next_hops:
314 - address: 1.1.1.1
315 vrf: default
316 priority: 1
317 next_hop_groups:
318 - group_name: hop1
319 group_type: ipv4
320 priority: 1
321 replication_groups:
322 - group_name: rep1
323 group_type: ipv4
324 priority: 1
325 priority: 0
326 section_description: 'section for class1'
327 state: merged
328
329 # After state:
330 # ------------
331 #
332 # sonic# show running-configuration policy-map
333 # !
334 # policy-map policy1 type forwarding
335 # description abc
336 # class class1 priority 0
337 # description xyz
338 # set interface Ethernet96 priority 1
339 # set ars disable
340 # !
341 # !
342 # policy-map policy2 type acl-copp
343 # description qwerty
344 # class class1 priority 0
345 # set trap-queue 0
346 # police cir 75 cbs 80 pir 96 pbs 95
347 # !
348 # !
349 # policy-map policy3 type qos
350 # description "this is policy 3"
351 # class class1 priority 0
352 # set pcp 0
353 # set dscp 0
354 # set traffic-class 0
355 # police cir 20 cbs 15 pir 24 pbs 21
356 # !
357 # !
358 # policy-map policy4 type monitoring
359 # description "this is policy 4"
360 # class class1 priority 0
361 # set mirror-session session1
362 # !
363 # !
364 # policy-map policy5 type forwarding
365 # description abc
366 # class class1 priority 0
367 # description "section for class1"
368 # set ip next-hop 1.1.1.1 vrf default priority 1
369 # set ip next-hop-group hop1 priority 1
370 # set ip replication-group rep1 priority 1
371 # !
372
373
374 # Using "replaced" state
375 #
376 # Before state:
377 # -------------
378 #
379 # sonic# show running-configuration policy-map
380 # !
381 # policy-map policy1 type forwarding
382 # description abc
383 # class class1 priority 0
384 # description xyz
385 # set interface Ethernet20 priority 1
386 # set ars disable
387 # !
388 # !
389 # policy-map policy2 type acl-copp
390 # description qwerty
391 # class class1 priority 0
392 # set trap-queue 0
393 # police cir 75 cbs 80 pir 96 pbs 95
394 # !
395
396 - name: Replace FBS policies configuration
397 dellemc.enterprise_sonic.sonic_fbs_policies:
398 config:
399 - policy_name: policy1
400 policy_description: 'abc123'
401 policy_type: monitoring
402 sections:
403 - class: class1
404 mirror_sessions:
405 - session_name: mirror1
406 priority: 0
407 state: replaced
408
409 # After state:
410 # ------------
411 #
412 # sonic# show running-configuration policy-map
413 # !
414 # policy-map policy1 type monitoring
415 # description "abc123"
416 # class class1 priority 0
417 # set mirror-session mirror1
418 # !
419 # !
420 # policy-map policy2 type acl-copp
421 # description qwerty
422 # class class1 priority 0
423 # set trap-queue 0
424 # police cir 75 cbs 80 pir 96 pbs 95
425 # !
426
427
428 # Using "overridden" state
429 #
430 # Before state:
431 # -------------
432 #
433 # sonic# show running-configuration policy-map
434 # !
435 # policy-map policy1 type forwarding
436 # description abc
437 # class class1 priority 0
438 # description xyz
439 # set interface Ethernet20 priority 1
440 # set ars disable
441 # !
442
443 - name: Override FBS policies configuration
444 dellemc.enterprise_sonic.sonic_fbs_policies:
445 config:
446 - policy_name: policy2
447 policy_description: qwerty
448 policy_type: copp
449 sections:
450 - class: class1
451 acl_copp:
452 cpu_queue_index: 0
453 policer:
454 cbs: 80
455 cir: 75
456 pbs: 95
457 pir: 96
458 priority: 0
459 state: overridden
460
461 # After state:
462 # ------------
463 #
464 # sonic# show running-configuration policy-map
465 # !
466 # policy-map policy2 type acl-copp
467 # description qwerty
468 # class class1 priority 0
469 # set trap-queue 0
470 # police cir 75 cbs 80 pir 96 pbs 95
471 # !
472
473
474 # Using "deleted" state
475 #
476 # Before state:
477 # -------------
478 #
479 # sonic# show running-configuration policy-map
480 # !
481 # policy-map policy1 type forwarding
482 # description abc
483 # class class1 priority 0
484 # description xyz
485 # set interface Ethernet20 priority 1
486 # set ars disable
487 # !
488 # !
489 # policy-map policy2 type acl-copp
490 # description qwerty
491 # class class1 priority 0
492 # set trap-queue 0
493 # police cir 75 cbs 80 pir 96 pbs 95
494 # !
495 # !
496 # policy-map policy3 type monitoring
497 # description "this is policy 3"
498 # class class1 priority 0
499 # set mirror-session mirror1
500 # !
501
502 - name: Delete FBS policies configuration
503 dellemc.enterprise_sonic.sonic_fbs_policies:
504 config:
505 - policy_name: policy1
506 - policy_name: policy2
507 sections:
508 - class: class1
509 acl_copp:
510 policer:
511 cbs: 80
512 cir: 75
513 pbs: 95
514 pir: 96
515 - policy_name: policy3
516 sections:
517 - class: class1
518 state: deleted
519
520 # After state:
521 # ------------
522 #
523 # sonic# show running-configuration policy-map
524 # !
525 # policy-map policy2 type acl-copp
526 # description qwerty
527 # class class1 priority 0
528 # set trap-queue 0
529 # !
530 # !
531 # policy-map policy3 type monitoring
532 # description "this is policy 3"
533 # !
534
535
536 # Using "deleted" state
537 #
538 # Before state:
539 # -------------
540 #
541 # sonic# show running-configuration policy-map
542 # !
543 # policy-map policy2 type acl-copp
544 # description qwerty
545 # class class1 priority 0
546 # set trap-queue 0
547 # !
548 # !
549 # policy-map policy3 type monitoring
550 # description "this is policy 3"
551 # !
552
553 - name: Delete all FBS policies configuration
554 dellemc.enterprise_sonic.sonic_fbs_policies:
555 config:
556 state: deleted
557
558 # After state:
559 # -------------
560 #
561 # sonic# show running-configuration policy-map
562 # (No policy-map configuration present)
563 """
564
565 RETURN = """
566 before:
567 description: The configuration prior to the module invocation.
568 returned: always
569 type: list
570 after:
571 description: The configuration resulting from module invocation.
572 returned: when changed
573 type: list
574 after_generated:
575 description: The generated configuration from module invocation.
576 returned: when C(check_mode)
577 type: list
578 commands:
579 description: The set of commands pushed to the remote device.
580 returned: always
581 type: list
582 sample: ['command 1', 'command 2', 'command 3']
583 """
584
585
586 from ansible.module_utils.basic import AnsibleModule
587 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.fbs_policies.fbs_policies import Fbs_policiesArgs
588 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.fbs_policies.fbs_policies import Fbs_policies
589
590
591 def main():
592 """
593 Main entry point for module execution
594
595 :returns: the result form module invocation
596 """
597 module = AnsibleModule(argument_spec=Fbs_policiesArgs.argument_spec,
598 supports_check_mode=True)
599
600 result = Fbs_policies(module).execute_module()
601 module.exit_json(**result)
602
603
604 if __name__ == '__main__':
605 main()