Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_fbs_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_fbs_interfaces
9 """
10 from __future__ import absolute_import, division, print_function
11 __metaclass__ = type
12
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_fbs_interfaces
17 version_added: 4.0.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) interfaces configuration on SONiC
22 description:
23 - This module provides configuration management of FBS interfaces for devices running SONiC
24 author: S. Talabi (@stalabi1)
25 options:
26 config:
27 description:
28 - FBS interfaces configuration
29 type: list
30 elements: dict
31 suboptions:
32 name:
33 description:
34 - Name of interface
35 type: str
36 required: true
37 ingress_policies:
38 description:
39 - Ingress policies configuration for the interface
40 type: dict
41 suboptions:
42 forwarding:
43 description:
44 - Forwarding policy
45 type: dict
46 suboptions:
47 policy_name:
48 description:
49 - Name of forwarding policy
50 type: str
51 monitoring:
52 description:
53 - Monitoring policy
54 type: dict
55 suboptions:
56 policy_name:
57 description:
58 - Name of monitoring policy
59 type: str
60 qos:
61 description:
62 - QoS policy
63 type: dict
64 suboptions:
65 policy_name:
66 description:
67 - Name of QoS policy
68 type: str
69
70 egress_policies:
71 description:
72 - Egress policies configuration for the interface
73 type: dict
74 suboptions:
75 qos:
76 description:
77 - QoS policy
78 type: dict
79 suboptions:
80 policy_name:
81 description:
82 - Name of QoS policy
83 type: str
84 state:
85 description:
86 - The state of the configuration after module completion
87 type: str
88 choices: ['merged', 'deleted', 'replaced', 'overridden']
89 default: merged
90 """
91
92 EXAMPLES = """
93 # Using "merged" state
94 #
95 # Before state:
96 # -------------
97 #
98 # sonic# show running-configuration interface Eth 1/5 | grep service-policy
99 # (No 'service-policy' configuration present)
100
101 - name: Merge FBS interfaces configuration
102 dellemc.enterprise_sonic.sonic_fbs_interfaces:
103 config:
104 - name: Eth1/5
105 ingress_policies:
106 forwarding:
107 policy_name: fwd_policy
108 monitoring:
109 policy_name: monitoring_policy
110 qos:
111 policy_name: qos_policy
112 egress_policies:
113 qos:
114 policy_name: qos_policy
115 state: merged
116
117 # After state:
118 # ------------
119 #
120 # sonic# show running-configuration interface Eth 1/5 | grep service-policy
121 # service-policy type qos in qos_policy
122 # service-policy type monitoring in monitoring_policy
123 # service-policy type forwarding in fwd_policy
124 # service-policy type qos out qos_policy
125
126
127 # Using "replaced" state
128 #
129 # Before state:
130 # -------------
131 #
132 # sonic# show running-configuration interface Eth 1/5 | grep service-policy
133 # service-policy type qos in qos_policy
134 # service-policy type monitoring in monitoring_policy
135 # service-policy type forwarding in fwd_policy
136 # service-policy type qos out qos_policy
137 # sonic# show running-configuration interface Eth 1/7 | grep service-policy
138 # service-policy type qos out qos_policy
139
140 - name: Replace FBS interfaces configuration
141 dellemc.enterprise_sonic.sonic_fbs_interfaces:
142 config:
143 - name: Eth1/5
144 ingress_policies:
145 forwarding:
146 policy_name: fwd_policy
147 state: replaced
148
149 # After state:
150 # ------------
151 #
152 # sonic# show running-configuration interface Eth 1/5 | grep service-policy
153 # service-policy type forwarding in fwd_policy
154 # sonic# show running-configuration interface Eth 1/7 | grep service-policy
155 # service-policy type qos out qos_policy
156
157
158 # Using "overridden" state
159 #
160 # Before state:
161 # -------------
162 #
163 # sonic# show running-configuration interface Eth 1/5 | grep service-policy
164 # service-policy type qos in qos_policy
165 # service-policy type monitoring in monitoring_policy
166 # service-policy type forwarding in fwd_policy
167 # service-policy type qos out qos_policy
168
169 - name: Override FBS interfaces configuration
170 dellemc.enterprise_sonic.sonic_fbs_interfaces:
171 config:
172 - name: Eth1/7
173 egress_policies:
174 qos:
175 policy_name: qos_policy
176 state: overridden
177
178 # After state:
179 # ------------
180 #
181 # sonic# show running-configuration interface Eth 1/5 | grep service-policy
182 # (No 'service-policy' configuration present)
183 # sonic# show running-configuration interface Eth 1/7 | grep service-policy
184 # service-policy type qos out qos_policy
185
186
187 # Using "deleted" state
188 #
189 # Before state:
190 # -------------
191 #
192 # sonic# show running-configuration interface Eth 1/5 | grep service-policy
193 # service-policy type qos in qos_policy
194 # service-policy type monitoring in monitoring_policy
195 # service-policy type forwarding in fwd_policy
196 # service-policy type qos out qos_policy
197
198 - name: Delete FBS interfaces configuration
199 dellemc.enterprise_sonic.sonic_fbs_interfaces:
200 config:
201 - name: Eth1/5
202 ingress_policies:
203 forwarding:
204 policy_name: fwd_policy
205 monitoring:
206 policy_name: monitoring_policy
207 state: deleted
208
209 # After state:
210 # ------------
211 #
212 # sonic# show running-configuration interface Eth 1/5 | grep service-policy
213 # service-policy type qos in qos_policy
214 # service-policy type qos out qos_policy
215
216
217 # Using "deleted" state
218 #
219 # Before state:
220 # -------------
221 #
222 # sonic# show running-configuration interface Eth 1/5 | grep service-policy
223 # service-policy type qos in qos_policy
224 # service-policy type monitoring in monitoring_policy
225 # service-policy type forwarding in fwd_policy
226 # service-policy type qos out qos_policy
227 # sonic# show running-configuration interface Eth 1/7 | grep service-policy
228 # service-policy type qos out qos_policy
229
230 - name: Delete all FBS interfaces configuration
231 dellemc.enterprise_sonic.sonic_fbs_interfaces:
232 config:
233 state: deleted
234
235 # After state:
236 # ------------
237 #
238 # sonic# show running-configuration interface Eth 1/5 | grep service-policy
239 # (No 'service-policy' configuration present)
240 # sonic# show running-configuration interface Eth 1/7 | grep service-policy
241 # (No 'service-policy' configuration present)
242 """
243 RETURN = """
244 before:
245 description: The configuration prior to the module invocation.
246 returned: always
247 type: list
248 after:
249 description: The resulting configuration from module invocation.
250 returned: when changed
251 type: list
252 after_generated:
253 description: The generated configuration from module invocation.
254 returned: when C(check_mode)
255 type: list
256 commands:
257 description: The set of commands pushed to the remote device.
258 returned: always
259 type: list
260 sample: ['command 1', 'command 2', 'command 3']
261 """
262
263
264 from ansible.module_utils.basic import AnsibleModule
265 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.fbs_interfaces.fbs_interfaces import Fbs_interfacesArgs
266 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.fbs_interfaces.fbs_interfaces import Fbs_interfaces
267
268
269 def main():
270 """
271 Main entry point for module execution
272
273 :returns: the result form module invocation
274 """
275 module = AnsibleModule(argument_spec=Fbs_interfacesArgs.argument_spec,
276 supports_check_mode=True)
277
278 result = Fbs_interfaces(module).execute_module()
279 module.exit_json(**result)
280
281
282 if __name__ == '__main__':
283 main()