Debian Codegraph @

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