Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_network_policy.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_network_policy
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_network_policy
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 network policy configuration on SONiC
22 description:
23 - This module provides configuration management of network policy for devices running SONiC
24 author: S. Talabi (@stalabi1)
25 options:
26 config:
27 description:
28 - List of network policy configurations
29 type: list
30 elements: dict
31 suboptions:
32 number:
33 description:
34 - Network policy number, range 1-128
35 type: int
36 required: true
37 applications:
38 description:
39 - List of network policy application configurations
40 - I(dot1p) and I(vlan_id) are mutually exclusive
41 - I(dot1p) cannot be configured when I(untagged=True)
42 type: list
43 elements: dict
44 suboptions:
45 app_type:
46 description:
47 - Media type of the application
48 type: str
49 choices: ['voice', 'voice-signaling']
50 required: true
51 dot1p:
52 description:
53 - Enable dot1p priority tagging
54 type: str
55 choices: ['enabled']
56 vlan_id:
57 description:
58 - VLAN identifier, range 1-4094
59 type: int
60 untagged:
61 description:
62 - Indicates that the application is using an untagged VLAN
63 type: bool
64 priority:
65 description:
66 - Priority of VLAN, range 0-7
67 type: int
68 dscp:
69 description:
70 - DSCP value of VLAN, range 0-63
71 type: int
72 state:
73 description:
74 - The state of the configuration after module completion
75 type: str
76 choices: ['merged', 'deleted', 'replaced', 'overridden']
77 default: merged
78 """
79
80 EXAMPLES = """
81 # Using "merged" state
82 #
83 # Before state:
84 # -------------
85 #
86 # sonic# show running-configuration
87 # (No network policy configuration present)
88
89 - name: Merge network policy configuration
90 dellemc.enterprise_sonic.sonic_network_policy:
91 config:
92 - number: 1
93 applications:
94 - app_type: voice
95 vlan_id: 2
96 priority: 1
97 dscp: 1
98 - app_type: voice-signaling
99 dot1p: enabled
100 dscp: 50
101 state: merged
102
103 # After state:
104 # ------------
105 #
106 # sonic# show running-configuration
107 # !
108 # network-policy profile 1
109 # voice vlan 2 cos 1 dscp 1
110 # voice-signaling vlan dot1p dscp 50
111 # !
112
113
114 # Using "replaced" state
115 #
116 # Before state:
117 # -------------
118 #
119 # sonic# show running-configuration
120 # !
121 # network-policy profile 1
122 # voice vlan 2 cos 1 dscp 1
123 # voice-signaling vlan 3 untagged dscp 50
124 # !
125 # network-policy profile 2
126 # voice vlan 100 cos 7 dscp 12
127 # voice-signaling vlan 400 cos 7 dscp 45
128 # !
129
130 - name: Replace network policy configuration
131 dellemc.enterprise_sonic.sonic_network_policy:
132 config:
133 - number: 1
134 applications:
135 - app_type: voice
136 vlan_id: 1
137 untagged: false
138 priority: 0
139 dscp: 0
140 state: replaced
141
142 # After state:
143 # ------------
144 #
145 # sonic# show running-configuration
146 # !
147 # network-policy profile 1
148 # voice vlan 1 cos 0 dscp 0
149 # !
150 # network-policy profile 2
151 # voice vlan 100 cos 7 dscp 12
152 # voice-signaling vlan 400 cos 7 dscp 45
153 # !
154
155
156 # Using "overridden" state
157 #
158 # Before state:
159 # -------------
160 #
161 # sonic# show running-configuration
162 # !
163 # network-policy profile 1
164 # voice vlan 2 cos 1 dscp 1
165 # voice-signaling vlan 3 untagged dscp 50
166 # !
167 # network-policy profile 2
168 # voice vlan 100 cos 7 dscp 12
169 # voice-signaling vlan 400 cos 7 dscp 45
170 # !
171
172 - name: Override network policy configuration
173 dellemc.enterprise_sonic.sonic_network_policy:
174 config:
175 - number: 1
176 applications:
177 - app_type: voice
178 vlan_id: 1
179 untagged: false
180 priority: 0
181 dscp: 0
182 state: overridden
183
184 # After state:
185 # ------------
186 #
187 # sonic# show running-configuration
188 # !
189 # network-policy profile 1
190 # voice vlan 1 cos 0 dscp 0
191 # !
192
193
194 # Using "deleted" state
195 #
196 # Before state:
197 # -------------
198 #
199 # sonic# show running-configuration
200 # !
201 # network-policy profile 1
202 # voice vlan 2 cos 1 dscp 1
203 # voice-signaling vlan 3 untagged dscp 50
204 # !
205 # network-policy profile 2
206 # voice vlan 100 cos 7 dscp 12
207 # voice-signaling vlan 400 cos 7 dscp 45
208 # !
209 # network-policy profile 3
210 # voice-signaling vlan 80 cos 6 dscp 32
211 # !
212
213 - name: Delete network policy configuration
214 dellemc.enterprise_sonic.sonic_network_policy:
215 config:
216 - number: 1
217 applications:
218 - app_type: voice
219 dscp: 1
220 - number: 2
221 applications:
222 - app_type: voice
223 - number: 3
224 state: deleted
225
226 # After state:
227 # ------------
228 #
229 # sonic# show running-configuration
230 # !
231 # network-policy profile 1
232 # voice vlan 2 cos 1
233 # voice-signaling vlan 3 untagged dscp 50
234 # !
235 # network-policy profile 2
236 # voice-signaling vlan 400 cos 7 dscp 45
237 # !
238
239
240 # Using "deleted" state
241 #
242 # Before state:
243 # -------------
244 #
245 # sonic# show running-configuration
246 # !
247 # network-policy profile 1
248 # voice vlan 2 cos 1 dscp 1
249 # voice-signaling vlan 3 untagged dscp 50
250 # !
251 # network-policy profile 2
252 # voice vlan 100 cos 7 dscp 12
253 # voice-signaling vlan 400 cos 7 dscp 45
254 # !
255 # network-policy profile 3
256 # voice-signaling vlan 80 cos 6 dscp 32
257 # !
258
259 - name: Delete all network policy configuration
260 dellemc.enterprise_sonic.sonic_network_policy:
261 config:
262 state: deleted
263
264 # After state:
265 # ------------
266 #
267 # sonic# show running-configuration
268 # (No network policy configuration present)
269 """
270
271 RETURN = """
272 before:
273 description: The configuration prior to the module invocation.
274 returned: always
275 type: list
276 after:
277 description: The configuration resulting from module invocation.
278 returned: when changed
279 type: list
280 after_generated:
281 description: The generated configuration from module invocation.
282 returned: when C(check_mode)
283 type: list
284 commands:
285 description: The set of commands pushed to the remote device.
286 returned: always
287 type: list
288 sample: ['command 1', 'command 2', 'command 3']
289 """
290
291
292 from ansible.module_utils.basic import AnsibleModule
293 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.network_policy.network_policy import Network_policyArgs
294 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.network_policy.network_policy import Network_policy
295
296
297 def main():
298 """
299 Main entry point for module execution
300
301 :returns: the result form module invocation
302 """
303 module = AnsibleModule(argument_spec=Network_policyArgs.argument_spec,
304 supports_check_mode=True)
305
306 result = Network_policy(module).execute_module()
307 module.exit_json(**result)
308
309
310 if __name__ == '__main__':
311 main()