| 1 |
|
| 2 |
|
| 3 |
. |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
""" |
| 8 |
The module file for sonic_l2_interfaces |
| 9 |
""" |
| 10 |
|
| 11 |
from __future__ import absolute_import, division, print_function |
| 12 |
__metaclass__ = type |
| 13 |
|
| 14 |
DOCUMENTATION = """ |
| 15 |
--- |
| 16 |
module: sonic_l2_interfaces |
| 17 |
version_added: 1.0.0 |
| 18 |
notes: |
| 19 |
- Tested against Enterprise SONiC Distribution by Dell Technologies. |
| 20 |
- Supports C(check_mode). |
| 21 |
short_description: Configure interface-to-VLAN association that is based on access or trunk mode |
| 22 |
description: Manages Layer 2 interface attributes of Enterprise SONiC Distribution by Dell Technologies. |
| 23 |
author: Niraimadaiselvam M(@niraimadaiselvamm) |
| 24 |
options: |
| 25 |
config: |
| 26 |
description: A list of Layer 2 interface configurations. |
| 27 |
type: list |
| 28 |
elements: dict |
| 29 |
suboptions: |
| 30 |
name: |
| 31 |
type: str |
| 32 |
description: Full name of the interface, for example, 'Eth1/26'. |
| 33 |
required: true |
| 34 |
trunk: |
| 35 |
type: dict |
| 36 |
description: Configures trunking parameters on an interface. |
| 37 |
suboptions: |
| 38 |
allowed_vlans: |
| 39 |
description: Specifies a list of allowed trunk mode VLANs and VLAN ranges for the interface. |
| 40 |
type: list |
| 41 |
elements: dict |
| 42 |
suboptions: |
| 43 |
vlan: |
| 44 |
type: str |
| 45 |
description: Configures the specified trunk mode VLAN or VLAN range. |
| 46 |
access: |
| 47 |
type: dict |
| 48 |
description: Configures access mode characteristics of the interface. |
| 49 |
suboptions: |
| 50 |
vlan: |
| 51 |
type: int |
| 52 |
description: Configures the specified VLAN in access mode. |
| 53 |
state: |
| 54 |
type: str |
| 55 |
description: The state that the configuration should be left in. |
| 56 |
choices: |
| 57 |
- merged |
| 58 |
- deleted |
| 59 |
- replaced |
| 60 |
- overridden |
| 61 |
default: merged |
| 62 |
""" |
| 63 |
|
| 64 |
EXAMPLES = """ |
| 65 |
# Using "deleted" state |
| 66 |
# |
| 67 |
# Before state: |
| 68 |
# ------------- |
| 69 |
# |
| 70 |
# do show Vlan |
| 71 |
# Q: A - Access (Untagged), T - Tagged |
| 72 |
# NUM Status Q Ports |
| 73 |
# 10 Inactive A Eth1/3 |
| 74 |
# 11 Inactive T Eth1/3 |
| 75 |
# 12 Inactive A Eth1/4 |
| 76 |
# 13 Inactive T Eth1/4 |
| 77 |
# 14 Inactive A Eth1/5 |
| 78 |
# 15 Inactive T Eth1/5 |
| 79 |
# |
| 80 |
- name: Configures switch port of interfaces |
| 81 |
dellemc.enterprise_sonic.sonic_l2_interfaces: |
| 82 |
config: |
| 83 |
- name: Eth1/3 |
| 84 |
- name: Eth1/4 |
| 85 |
state: deleted |
| 86 |
# |
| 87 |
# After state: |
| 88 |
# ------------ |
| 89 |
# |
| 90 |
# do show Vlan |
| 91 |
# Q: A - Access (Untagged), T - Tagged |
| 92 |
# NUM Status Q Ports |
| 93 |
# 10 Inactive |
| 94 |
# 11 Inactive |
| 95 |
# 12 Inactive |
| 96 |
# 13 Inactive |
| 97 |
# 14 Inactive A Eth1/5 |
| 98 |
# 15 Inactive T Eth1/5 |
| 99 |
# |
| 100 |
# |
| 101 |
# Using "deleted" state |
| 102 |
# |
| 103 |
# Before state: |
| 104 |
# ------------- |
| 105 |
# |
| 106 |
# do show Vlan |
| 107 |
# Q: A - Access (Untagged), T - Tagged |
| 108 |
# NUM Status Q Ports |
| 109 |
# 10 Inactive A Eth1/3 |
| 110 |
# 11 Inactive T Eth1/3 |
| 111 |
# 12 Inactive A Eth1/4 |
| 112 |
# 13 Inactive T Eth1/4 |
| 113 |
# 14 Inactive A Eth1/5 |
| 114 |
# 15 Inactive T Eth1/5 |
| 115 |
# |
| 116 |
- name: Configures switch port of interfaces |
| 117 |
dellemc.enterprise_sonic.sonic_l2_interfaces: |
| 118 |
config: |
| 119 |
state: deleted |
| 120 |
# |
| 121 |
# After state: |
| 122 |
# do show Vlan |
| 123 |
# Q: A - Access (Untagged), T - Tagged |
| 124 |
# NUM Status Q Ports |
| 125 |
# 10 Inactive |
| 126 |
# 11 Inactive |
| 127 |
# 12 Inactive |
| 128 |
# 13 Inactive |
| 129 |
# 14 Inactive |
| 130 |
# 15 Inactive |
| 131 |
# |
| 132 |
# |
| 133 |
# Using "deleted" state |
| 134 |
# |
| 135 |
# Before state: |
| 136 |
# ------------- |
| 137 |
# |
| 138 |
# do show Vlan |
| 139 |
# Q: A - Access (Untagged), T - Tagged |
| 140 |
# NUM Status Q Ports |
| 141 |
# 11 Inactive T Ethernet12 |
| 142 |
# 12 Inactive A Ethernet12 |
| 143 |
# 13 Inactive T Ethernet12 |
| 144 |
# 14 Inactive T Ethernet12 |
| 145 |
# 15 Inactive T Ethernet12 |
| 146 |
# 16 Inactive T Ethernet12 |
| 147 |
|
| 148 |
- name: Delete the access vlan and a range of trunk vlans for an interface |
| 149 |
sonic_l2_interfaces: |
| 150 |
config: |
| 151 |
- name: Ethernet12 |
| 152 |
access: |
| 153 |
vlan: 12 |
| 154 |
trunk: |
| 155 |
allowed_vlans: |
| 156 |
- vlan: 13-16 |
| 157 |
state: deleted |
| 158 |
|
| 159 |
# After state: |
| 160 |
# ------------ |
| 161 |
# |
| 162 |
# do show Vlan |
| 163 |
# Q: A - Access (Untagged), T - Tagged |
| 164 |
# NUM Status Q Ports |
| 165 |
# 11 Inactive T Ethernet12 |
| 166 |
# 12 Inactive |
| 167 |
# 13 Inactive |
| 168 |
# 14 Inactive |
| 169 |
# 15 Inactive |
| 170 |
# 16 Inactive |
| 171 |
# |
| 172 |
# |
| 173 |
# |
| 174 |
# Using "merged" state |
| 175 |
# |
| 176 |
# Before state: |
| 177 |
# ------------- |
| 178 |
# |
| 179 |
# do show Vlan |
| 180 |
# Q: A - Access (Untagged), T - Tagged |
| 181 |
# NUM Status Q Ports |
| 182 |
# 10 Inactive |
| 183 |
# 11 Inactive T Eth1/7 |
| 184 |
# 12 Inactive T Eth1/7 |
| 185 |
# |
| 186 |
- name: Configures an access vlan for an interface |
| 187 |
dellemc.enterprise_sonic.sonic_l2_interfaces: |
| 188 |
config: |
| 189 |
- name: Eth1/3 |
| 190 |
access: |
| 191 |
vlan: 10 |
| 192 |
state: merged |
| 193 |
# |
| 194 |
# After state: |
| 195 |
# ------------ |
| 196 |
# |
| 197 |
# do show Vlan |
| 198 |
# Q: A - Access (Untagged), T - Tagged |
| 199 |
# NUM Status Q Ports |
| 200 |
# 10 Inactive A Eth1/3 |
| 201 |
# 11 Inactive T Eth1/7 |
| 202 |
# 12 Inactive T Eth1/7 |
| 203 |
# |
| 204 |
# |
| 205 |
# Using "merged" state |
| 206 |
# |
| 207 |
# Before state: |
| 208 |
# ------------- |
| 209 |
# |
| 210 |
# do show Vlan |
| 211 |
# Q: A - Access (Untagged), T - Tagged |
| 212 |
# NUM Status Q Ports |
| 213 |
# 10 Inactive A Eth1/3 |
| 214 |
# 12 Inactive |
| 215 |
# 13 Inactive |
| 216 |
# 14 Inactive |
| 217 |
# 15 Inactive |
| 218 |
# 16 Inactive |
| 219 |
# 18 Inactive |
| 220 |
# |
| 221 |
- name: Modify the access vlan, add a range of trunk vlans and a single trunk vlan for an interface |
| 222 |
dellemc.enterprise_sonic.sonic_l2_interfaces: |
| 223 |
config: |
| 224 |
- name: Eth1/3 |
| 225 |
access: |
| 226 |
vlan: 12 |
| 227 |
trunk: |
| 228 |
allowed_vlans: |
| 229 |
- vlan: 13-16 |
| 230 |
- vlan: 18 |
| 231 |
state: merged |
| 232 |
# |
| 233 |
# After state: |
| 234 |
# ------------ |
| 235 |
# |
| 236 |
# do show Vlan |
| 237 |
# Q: A - Access (Untagged), T - Tagged |
| 238 |
# NUM Status Q Ports |
| 239 |
# 10 Inactive |
| 240 |
# 12 Inactive A Eth1/3 |
| 241 |
# 13 Inactive T Eth1/3 |
| 242 |
# 14 Inactive T Eth1/3 |
| 243 |
# 15 Inactive T Eth1/3 |
| 244 |
# 16 Inactive T Eth1/3 |
| 245 |
# 18 Inactive T Eth1/3 |
| 246 |
# |
| 247 |
# |
| 248 |
# Using "merged" state |
| 249 |
# |
| 250 |
# Before state: |
| 251 |
# ------------- |
| 252 |
# |
| 253 |
# do show Vlan |
| 254 |
# Q: A - Access (Untagged), T - Tagged |
| 255 |
# NUM Status Q Ports |
| 256 |
# 10 Inactive |
| 257 |
# 11 Inactive |
| 258 |
# 12 Inactive A Eth1/4 |
| 259 |
# 13 Inactive T Eth1/4 |
| 260 |
# 14 Inactive A Eth1/5 |
| 261 |
# 15 Inactive T Eth1/5 |
| 262 |
# |
| 263 |
- name: Configures switch port of interfaces |
| 264 |
dellemc.enterprise_sonic.sonic_l2_interfaces: |
| 265 |
config: |
| 266 |
- name: Eth1/3 |
| 267 |
access: |
| 268 |
vlan: 12 |
| 269 |
trunk: |
| 270 |
allowed_vlans: |
| 271 |
- vlan: 13 |
| 272 |
- vlan: 14 |
| 273 |
state: merged |
| 274 |
# |
| 275 |
# After state: |
| 276 |
# ------------ |
| 277 |
# |
| 278 |
# do show Vlan |
| 279 |
# Q: A - Access (Untagged), T - Tagged |
| 280 |
# NUM Status Q Ports |
| 281 |
# 10 Inactive |
| 282 |
# 11 Inactive |
| 283 |
# 12 Inactive A Eth1/3 |
| 284 |
# A Eth1/4 |
| 285 |
# 13 Inactive T Eth1/3 |
| 286 |
# T Eth1/4 |
| 287 |
# 14 Inactive A Eth1/3 |
| 288 |
# A Eth1/5 |
| 289 |
# 15 Inactive T Eth1/5 |
| 290 |
# |
| 291 |
# |
| 292 |
# Using "replaced" state |
| 293 |
# |
| 294 |
# Before state: |
| 295 |
# ------------- |
| 296 |
# |
| 297 |
# do show Vlan |
| 298 |
# Q: A - Access (Untagged), T - Tagged |
| 299 |
# NUM Status Q Ports |
| 300 |
# 10 Inactive A Ethernet12 |
| 301 |
# A Ethernet13 |
| 302 |
# 11 Inactive T Ethernet12 |
| 303 |
# T Ethernet13 |
| 304 |
|
| 305 |
- name: Replace access vlan and trunk vlans for specified interfaces |
| 306 |
sonic_l2_interfaces: |
| 307 |
config: |
| 308 |
- name: Ethernet12 |
| 309 |
access: |
| 310 |
vlan: 12 |
| 311 |
trunk: |
| 312 |
allowed_vlans: |
| 313 |
- vlan: 13-14 |
| 314 |
- name: Ethernet14 |
| 315 |
access: |
| 316 |
vlan: 10 |
| 317 |
trunk: |
| 318 |
allowed_vlans: |
| 319 |
- vlan: 11 |
| 320 |
- vlan: 13-14 |
| 321 |
state: replaced |
| 322 |
|
| 323 |
# After state: |
| 324 |
# ------------ |
| 325 |
# |
| 326 |
# do show Vlan |
| 327 |
# Q: A - Access (Untagged), T - Tagged |
| 328 |
# NUM Status Q Ports |
| 329 |
# 10 Inactive A Ethernet13 |
| 330 |
# A Ethernet14 |
| 331 |
# 11 Inactive T Ethernet13 |
| 332 |
# T Ethernet14 |
| 333 |
# 12 Inactive A Ethernet12 |
| 334 |
# 13 Inactive T Ethernet12 |
| 335 |
# T Ethernet14 |
| 336 |
# 14 Inactive T Ethernet12 |
| 337 |
# T Ethernet14 |
| 338 |
# |
| 339 |
# |
| 340 |
# Using "overridden" state |
| 341 |
# |
| 342 |
# Before state: |
| 343 |
# ------------- |
| 344 |
# |
| 345 |
# do show Vlan |
| 346 |
# Q: A - Access (Untagged), T - Tagged |
| 347 |
# NUM Status Q Ports |
| 348 |
# 10 Inactive A Ethernet11 |
| 349 |
# 11 Inactive T Ethernet11 |
| 350 |
# 12 Inactive A Ethernet12 |
| 351 |
# 13 Inactive T Ethernet12 |
| 352 |
|
| 353 |
- name: Override L2 interfaces configuration in device with provided configuration |
| 354 |
sonic_l2_interfaces: |
| 355 |
config: |
| 356 |
- name: Ethernet13 |
| 357 |
access: |
| 358 |
vlan: 12 |
| 359 |
trunk: |
| 360 |
allowed_vlans: |
| 361 |
- vlan: 13-14 |
| 362 |
state: overridden |
| 363 |
|
| 364 |
# After state: |
| 365 |
# ------------ |
| 366 |
# |
| 367 |
# do show Vlan |
| 368 |
# Q: A - Access (Untagged), T - Tagged |
| 369 |
# NUM Status Q Ports |
| 370 |
# 12 Inactive A Ethernet13 |
| 371 |
# 13 Inactive T Ethernet13 |
| 372 |
# 14 Inactive T Ethernet13 |
| 373 |
# |
| 374 |
# |
| 375 |
""" |
| 376 |
|
| 377 |
RETURN = """ |
| 378 |
before: |
| 379 |
description: The configuration prior to the module invocation. |
| 380 |
returned: always |
| 381 |
type: list |
| 382 |
sample: > |
| 383 |
The configuration returned always in the same format |
| 384 |
as the parameters above. |
| 385 |
after: |
| 386 |
description: The resulting configuration module invocation. |
| 387 |
returned: when changed |
| 388 |
type: list |
| 389 |
sample: > |
| 390 |
The configuration returned is always in the same format |
| 391 |
as the parameters above. |
| 392 |
commands: |
| 393 |
description: The set of commands pushed to the remote device. |
| 394 |
returned: always |
| 395 |
type: list |
| 396 |
sample: ['command 1', 'command 2', 'command 3'] |
| 397 |
""" |
| 398 |
|
| 399 |
|
| 400 |
from ansible.module_utils.basic import AnsibleModule |
| 401 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.l2_interfaces.l2_interfaces import L2_interfacesArgs |
| 402 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.l2_interfaces.l2_interfaces import L2_interfaces |
| 403 |
|
| 404 |
|
| 405 |
def main(): |
| 406 |
""" |
| 407 |
Main entry point for module execution |
| 408 |
|
| 409 |
:returns: the result form module invocation |
| 410 |
""" |
| 411 |
module = AnsibleModule(argument_spec=L2_interfacesArgs.argument_spec, |
| 412 |
supports_check_mode=True) |
| 413 |
|
| 414 |
result = L2_interfaces(module).execute_module() |
| 415 |
module.exit_json(**result) |
| 416 |
|
| 417 |
|
| 418 |
if __name__ == '__main__': |
| 419 |
main() |