Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_fbs_groups.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_groups
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_fbs_groups
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) groups configuration on SONiC
22 description:
23 - This module provides configuration management of FBS groups for devices running SONiC
24 author: S. Talabi (@stalabi1)
25 options:
26 config:
27 description:
28 - FBS groups configuration
29 type: dict
30 suboptions:
31 next_hop_groups:
32 description:
33 - Next-hop groups configuration
34 type: list
35 elements: dict
36 suboptions:
37 group_name:
38 description:
39 - Name of next-hop group
40 type: str
41 required: true
42 group_description:
43 description:
44 - Description of next-hop group
45 type: str
46 group_type:
47 description:
48 - Type of next-hop group
49 - The group type is required for merged, replaced, and overridden states.
50 type: str
51 choices: ['ipv4', 'ipv6']
52 threshold_type:
53 description:
54 - Type of threshold
55 - Deletion of I(threshold_type) will delete I(threshold_up) and I(threshold_down).
56 type: str
57 choices: ['count', 'percentage']
58 threshold_up:
59 description:
60 - Specifies the minimum threshold value for a next-hop group to be considered forwardable
61 - Range 1-128
62 - I(threshold_type) must be configured.
63 type: int
64 threshold_down:
65 description:
66 - Specifies the threshold value equal to or below for a next-hop to not be considered forwardable
67 - Range 0-127
68 - I(threshold_type) must be configured.
69 type: int
70 next_hops:
71 description:
72 - Next-hops configuration for forwarding
73 type: list
74 elements: dict
75 suboptions:
76 entry_id:
77 description:
78 - Entry ID, range 1-65535
79 type: int
80 required: true
81 ip_address:
82 description:
83 - Forwarding IP address
84 - The IP address is required for merged, replaced, and overridden states.
85 type: str
86 vrf:
87 description:
88 - Forwarding network instance
89 type: str
90 next_hop_type:
91 description:
92 - Type of next-hop
93 type: str
94 choices: ['non_recursive', 'overlay', 'recursive']
95 replication_groups:
96 description:
97 - Replication groups configuration
98 type: list
99 elements: dict
100 suboptions:
101 group_name:
102 description:
103 - Name of replication group
104 type: str
105 required: true
106 group_description:
107 description:
108 - Description of replication group
109 type: str
110 group_type:
111 description:
112 - Type of replication group
113 - The group type is required for merged, replaced, and overridden states.
114 type: str
115 choices: ['ipv4', 'ipv6']
116 next_hops:
117 description:
118 - Next-hops configuration for forwarding
119 type: list
120 elements: dict
121 suboptions:
122 entry_id:
123 description:
124 - Entry ID, range 1-65535
125 type: int
126 required: true
127 ip_address:
128 description:
129 - Forwarding IP address
130 - The IP address is required for merged, replaced, and overridden states.
131 type: str
132 vrf:
133 description:
134 - Forwarding network instance
135 type: str
136 next_hop_type:
137 description:
138 - Type of next-hop
139 type: str
140 choices: ['non_recursive', 'overlay', 'recursive']
141 single_copy:
142 description:
143 - Enable/disable single path to create copy
144 type: bool
145 state:
146 description:
147 - The state of the configuration after module completion
148 type: str
149 choices: ['merged', 'deleted', 'replaced', 'overridden']
150 default: merged
151 """
152
153 EXAMPLES = """
154 # Using "merged" state
155 #
156 # Before state:
157 # -------------
158 #
159 # sonic# show running-configuration pbf next-hop-group
160 # (No 'pbf next-hop-group' configuration present)
161 # sonic# show running-configuration pbf replication-group
162 # (No 'pbf replication-group' configuration present)
163
164 - name: Merge FBS groups configuration
165 dellemc.enterprise_sonic.sonic_fbs_groups:
166 config:
167 next_hop_groups:
168 - group_name: hop1
169 group_description: abc
170 group_type: ipv4
171 threshold_type: count
172 threshold_up: 15
173 threshold_down: 5
174 next_hops:
175 - entry_id: 1
176 ip_address: 1.1.1.1
177 vrf: VrfReg1
178 next_hop_type: non_recursive
179 replication_groups:
180 - group_name: rep1
181 group_description: xyz
182 group_type: ipv6
183 next_hops:
184 - entry_id: 2
185 ip_address: 1::1
186 vrf: VrfReg2
187 next_hop_type: overlay
188 single_copy: true
189 state: merged
190
191 # After state:
192 # ------------
193 #
194 # sonic# show running-configuration pbf next-hop-group
195 # !
196 # pbf next-hop-group hop1 type ip
197 # description abc
198 # threshold type count up 15 down 5
199 # entry 1 next-hop 1.1.1.1 vrf VrfReg1 non-recursive
200 # !
201 # sonic# show running-configuration pbf replication-group
202 # !
203 # pbf replication-group rep1 type ipv6
204 # description xyz
205 # entry 2 next-hop 1::1 vrf VrfReg2 overlay single-copy
206 # !
207
208
209 # Using "replaced" state
210 #
211 # Before state:
212 # -------------
213 #
214 # sonic# show running-configuration pbf next-hop-group
215 # !
216 # pbf next-hop-group hop1 type ip
217 # description abc
218 # threshold type count up 15 down 5
219 # entry 1 next-hop 1.1.1.1 vrf VrfReg1 non-recursive
220 # !
221 # pbf next-hop-group hop2 type ipv6
222 # description abc
223 # entry 5 next-hop 3::3 vrf default non-recursive
224 # !
225 # sonic# show running-configuration pbf replication-group
226 # !
227 # pbf replication-group rep1 type ipv6
228 # description xyz
229 # entry 2 next-hop 1::1 vrf VrfReg2 overlay single-copy
230 # !
231
232 - name: Replace FBS groups configuration
233 dellemc.enterprise_sonic.sonic_fbs_groups:
234 config:
235 next_hop_groups:
236 - group_name: hop2
237 group_description: xyz
238 group_type: ipv4
239 next_hops:
240 - entry_id: 1
241 ip_address: 1.1.1.1
242 vrf: VrfReg1
243 next_hop_type: recursive
244 state: replaced
245
246 # After state:
247 # ------------
248 #
249 # sonic# show running-configuration pbf next-hop-group
250 # !
251 # pbf next-hop-group hop1 type ip
252 # description abc
253 # threshold type count up 15 down 5
254 # entry 1 next-hop 1.1.1.1 vrf VrfReg1 non-recursive
255 # !
256 # pbf next-hop-group hop2 type ipv4
257 # description xyz
258 # entry 1 next-hop 1.1.1.1 vrf VrfReg1 recursive
259 # !
260 # sonic# show running-configuration pbf replication-group
261 # !
262 # pbf replication-group rep1 type ipv6
263 # description xyz
264 # entry 2 next-hop 1::1 vrf VrfReg2 overlay single-copy
265 # !
266
267
268 # Using "overridden" state
269 #
270 # Before state:
271 # -------------
272 #
273 # sonic# show running-configuration pbf next-hop-group
274 # !
275 # pbf next-hop-group hop1 type ip
276 # description abc
277 # entry 1 next-hop 1.1.1.1 vrf VrfReg1 non-recursive
278 # !
279 # sonic# show running-configuration pbf replication-group
280 # !
281 # pbf replication-group rep1 type ipv6
282 # description xyz
283 # entry 2 next-hop 1::1 vrf VrfReg2 overlay single-copy
284 # !
285
286 - name: Override FBS groups configuration
287 dellemc.enterprise_sonic.sonic_fbs_groups:
288 config:
289 next_hop_groups:
290 - group_name: hop1
291 group_description: abc
292 group_type: ipv4
293 state: overridden
294
295 # After state:
296 # ------------
297 #
298 # sonic# show running-configuration pbf next-hop-group
299 # !
300 # pbf next-hop-group hop1 type ip
301 # description abc
302 # !
303 # sonic# show running-configuration pbf replication-group
304 # (No 'pbf replication-group' configuration present)
305
306
307 # Using "deleted" state
308 #
309 # Before state:
310 # -------------
311 #
312 # sonic# show running-configuration pbf next-hop-group
313 # !
314 # pbf next-hop-group hop1 type ip
315 # description abc
316 # entry 1 next-hop 1.1.1.1 vrf VrfReg1 non-recursive
317 # !
318 # sonic# show running-configuration pbf replication-group
319 # !
320 # pbf replication-group rep1 type ipv6
321 # description xyz
322 # entry 2 next-hop 1::1 vrf VrfReg2 overlay single-copy
323 # !
324
325 - name: Delete FBS groups configuration
326 dellemc.enterprise_sonic.sonic_fbs_groups:
327 config:
328 next_hop_groups:
329 - group_name: hop1
330 group_description: abc
331 replication_groups:
332 - group_name: rep1
333 next_hops:
334 - entry_id: 2
335 state: deleted
336
337 # After state:
338 # ------------
339 #
340 # sonic# show running-configuration pbf next-hop-group
341 # !
342 # pbf next-hop-group hop1 type ip
343 # entry 1 next-hop 1.1.1.1 vrf VrfReg1 non-recursive
344 # !
345 # sonic# show running-configuration pbf replication-group
346 # !
347 # pbf replication-group rep1 type ipv6
348 # description xyz
349 # !
350
351
352 # Using "deleted" state
353 #
354 # Before state:
355 # -------------
356 #
357 # sonic# show running-configuration pbf next-hop-group
358 # !
359 # pbf next-hop-group hop1 type ip
360 # entry 1 next-hop 1.1.1.1 vrf VrfReg1 non-recursive
361 # !
362 # sonic# show running-configuration pbf replication-group
363 # !
364 # pbf replication-group rep1 type ipv6
365 # description xyz
366 # !
367
368 - name: Delete FBS groups configuration
369 dellemc.enterprise_sonic.sonic_fbs_groups:
370 config:
371 state: deleted
372
373 # After state:
374 # ------------
375 #
376 # sonic# show running-configuration pbf next-hop-group
377 # (No 'pbf next-hop-group' configuration present)
378 # sonic# show running-configuration pbf replication-group
379 # (No 'pbf replication-group' configuration present)
380 """
381
382 RETURN = """
383 before:
384 description: The configuration prior to the module invocation.
385 returned: always
386 type: dict
387 after:
388 description: The resulting configuration module invocation.
389 returned: when changed
390 type: dict
391 after_generated:
392 description: The generated configuration from module invocation.
393 returned: when C(check_mode)
394 type: dict
395 commands:
396 description: The set of commands pushed to the remote device.
397 returned: always
398 type: list
399 sample: ['command 1', 'command 2', 'command 3']
400 """
401
402
403 from ansible.module_utils.basic import AnsibleModule
404 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.fbs_groups.fbs_groups import Fbs_groupsArgs
405 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.fbs_groups.fbs_groups import Fbs_groups
406
407
408 def main():
409 """
410 Main entry point for module execution
411
412 :returns: the result form module invocation
413 """
414 module = AnsibleModule(argument_spec=Fbs_groupsArgs.argument_spec,
415 supports_check_mode=True)
416
417 result = Fbs_groups(module).execute_module()
418 module.exit_json(**result)
419
420
421 if __name__ == '__main__':
422 main()