| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
""" |
| 8 |
The module file for sonic_mac |
| 9 |
""" |
| 10 |
|
| 11 |
from __future__ import absolute_import, division, print_function |
| 12 |
__metaclass__ = type |
| 13 |
|
| 14 |
DOCUMENTATION = """ |
| 15 |
--- |
| 16 |
module: sonic_mac |
| 17 |
version_added: "2.1.0" |
| 18 |
notes: |
| 19 |
- Tested against Enterprise SONiC Distribution by Dell Technologies. |
| 20 |
- Supports C(check_mode). |
| 21 |
short_description: Manage MAC configuration on SONiC |
| 22 |
description: |
| 23 |
- This module provides configuration management of MAC for devices running SONiC |
| 24 |
author: "S. Talabi (@stalabi1)" |
| 25 |
options: |
| 26 |
config: |
| 27 |
description: |
| 28 |
- A list of MAC configurations. |
| 29 |
type: list |
| 30 |
elements: dict |
| 31 |
suboptions: |
| 32 |
vrf_name: |
| 33 |
description: |
| 34 |
- Specifies the VRF name. |
| 35 |
type: str |
| 36 |
default: 'default' |
| 37 |
mac: |
| 38 |
description: |
| 39 |
- Configuration attributes for MAC. |
| 40 |
type: dict |
| 41 |
suboptions: |
| 42 |
aging_time: |
| 43 |
description: |
| 44 |
- Time in seconds of inactivity before the MAC entry is timed out. |
| 45 |
type: int |
| 46 |
default: 600 |
| 47 |
dampening_interval: |
| 48 |
description: |
| 49 |
- Interval for which mac movements are observed before disabling MAC learning on a port. |
| 50 |
type: int |
| 51 |
default: 5 |
| 52 |
dampening_threshold: |
| 53 |
description: |
| 54 |
- Number of MAC movements allowed per second before disabling MAC learning on a port. |
| 55 |
type: int |
| 56 |
default: 5 |
| 57 |
mac_table_entries: |
| 58 |
description: |
| 59 |
- Configuration attributes for MAC table entries. |
| 60 |
type: list |
| 61 |
elements: dict |
| 62 |
suboptions: |
| 63 |
mac_address: |
| 64 |
description: |
| 65 |
- MAC address for the dynamic or static MAC table entry. |
| 66 |
type: str |
| 67 |
required: True |
| 68 |
vlan_id: |
| 69 |
description: |
| 70 |
- ID number of VLAN on which the MAC address is present. |
| 71 |
type: int |
| 72 |
required: True |
| 73 |
interface: |
| 74 |
description: |
| 75 |
- Specifies the interface for the MAC table entry. |
| 76 |
type: str |
| 77 |
state: |
| 78 |
description: |
| 79 |
- The state of the configuration after module completion |
| 80 |
type: str |
| 81 |
choices: ['merged', 'deleted', 'replaced', 'overridden'] |
| 82 |
default: merged |
| 83 |
""" |
| 84 |
|
| 85 |
EXAMPLES = """ |
| 86 |
# Using "merged" state |
| 87 |
# |
| 88 |
# Before state: |
| 89 |
# ------------- |
| 90 |
# |
| 91 |
# sonic# show mac dampening |
| 92 |
# MAC Move Dampening Threshold : 5 |
| 93 |
# MAC Move Dampening Interval : 5 |
| 94 |
# sonic# show running-configuration | grep mac |
| 95 |
# (No mac configuration pressent) |
| 96 |
|
| 97 |
- name: Merge MAC configurations |
| 98 |
dellemc.enterprise_sonic.sonic_mac: |
| 99 |
config: |
| 100 |
- vrf_name: 'default' |
| 101 |
mac: |
| 102 |
aging_time: 50 |
| 103 |
dampening_interval: 20 |
| 104 |
dampening_threshold: 30 |
| 105 |
mac_table_entries: |
| 106 |
- mac_address: '00:00:5e:00:53:af' |
| 107 |
vlan_id: 1 |
| 108 |
interface: 'Ethernet20' |
| 109 |
- mac_address: '00:33:33:33:33:33' |
| 110 |
vlan_id: 2 |
| 111 |
interface: 'Ethernet24' |
| 112 |
- mac_address: '00:00:4e:00:24:af' |
| 113 |
vlan_id: 3 |
| 114 |
interface: 'Ethernet28' |
| 115 |
state: merged |
| 116 |
|
| 117 |
# After state: |
| 118 |
# ------------ |
| 119 |
# |
| 120 |
# sonic# show mac dampening |
| 121 |
# MAC Move Dampening Threshold : 30 |
| 122 |
# MAC Move Dampening Interval : 20 |
| 123 |
# sonic# show running-configuration | grep mac |
| 124 |
# mac address-table 00:00:5e:00:53:af Vlan1 Ethernet20 |
| 125 |
# mac address-table 00:33:33:33:33:33 Vlan2 Ethernet24 |
| 126 |
# mac address-table 00:00:4e:00:24:af Vlan3 Ethernet28 |
| 127 |
# mac address-table aging-time 50 |
| 128 |
# |
| 129 |
# |
| 130 |
# Using "replaced" state |
| 131 |
# |
| 132 |
# Before state: |
| 133 |
# ------------- |
| 134 |
# |
| 135 |
# sonic# show mac dampening |
| 136 |
# MAC Move Dampening Threshold : 30 |
| 137 |
# MAC Move Dampening Interval : 20 |
| 138 |
# sonic# show running-configuration | grep mac |
| 139 |
# mac address-table 00:00:5e:00:53:af Vlan1 Ethernet20 |
| 140 |
# mac address-table 00:33:33:33:33:33 Vlan2 Ethernet24 |
| 141 |
# mac address-table 00:00:4e:00:24:af Vlan3 Ethernet28 |
| 142 |
# mac address-table aging-time 50 |
| 143 |
|
| 144 |
- name: Replace MAC configurations |
| 145 |
dellemc.enterprise_sonic.sonic_mac: |
| 146 |
config: |
| 147 |
- vrf_name: 'default' |
| 148 |
mac: |
| 149 |
aging_time: 45 |
| 150 |
dampening_interval: 30 |
| 151 |
dampening_threshold: 60 |
| 152 |
mac_table_entries: |
| 153 |
- mac_address: '00:00:5e:00:53:af' |
| 154 |
vlan_id: 3 |
| 155 |
interface: 'Ethernet24' |
| 156 |
- mac_address: '00:44:44:44:44:44' |
| 157 |
vlan_id: 2 |
| 158 |
interface: 'Ethernet20' |
| 159 |
state: replaced |
| 160 |
|
| 161 |
# sonic# show mac dampening |
| 162 |
# MAC Move Dampening Threshold : 60 |
| 163 |
# MAC Move Dampening Interval : 30 |
| 164 |
# sonic# show running-configuration | grep mac |
| 165 |
# mac address-table 00:00:5e:00:53:af Vlan3 Ethernet24 |
| 166 |
# mac address-table 00:33:33:33:33:33 Vlan2 Ethernet24 |
| 167 |
# mac address-table 00:00:4e:00:24:af Vlan3 Ethernet28 |
| 168 |
# mac address-table 00:44:44:44:44:44 Vlan2 Ethernet20 |
| 169 |
# mac address-table aging-time 45 |
| 170 |
# |
| 171 |
# |
| 172 |
# Using "overridden" state |
| 173 |
# |
| 174 |
# Before state: |
| 175 |
# ------------- |
| 176 |
# |
| 177 |
# sonic# show mac dampening |
| 178 |
# MAC Move Dampening Threshold : 60 |
| 179 |
# MAC Move Dampening Interval : 30 |
| 180 |
# sonic# show running-configuration | grep mac |
| 181 |
# mac address-table 00:00:5e:00:53:af Vlan3 Ethernet24 |
| 182 |
# mac address-table 00:33:33:33:33:33 Vlan2 Ethernet24 |
| 183 |
# mac address-table 00:00:4e:00:24:af Vlan3 Ethernet28 |
| 184 |
# mac address-table 00:44:44:44:44:44 Vlan2 Ethernet20 |
| 185 |
# mac address-table aging-time 45 |
| 186 |
|
| 187 |
- name: Override MAC cofigurations |
| 188 |
dellemc.enterprise_sonic.sonic_mac: |
| 189 |
config: |
| 190 |
- vrf_name: 'default' |
| 191 |
mac: |
| 192 |
aging_time: 10 |
| 193 |
dampening_interval: 20 |
| 194 |
dampening_threshold: 30 |
| 195 |
mac_table_entries: |
| 196 |
- mac_address: '00:11:11:11:11:11' |
| 197 |
vlan_id: 1 |
| 198 |
interface: 'Ethernet20' |
| 199 |
- mac_address: '00:22:22:22:22:22' |
| 200 |
vlan_id: 2 |
| 201 |
interface: 'Ethernet24' |
| 202 |
state: overridden |
| 203 |
|
| 204 |
# After state: |
| 205 |
# ------------ |
| 206 |
# |
| 207 |
# sonic# show mac dampening |
| 208 |
# MAC Move Dampening Threshold : 30 |
| 209 |
# MAC Move Dampening Interval : 20 |
| 210 |
# sonic# show running-configuration | grep mac |
| 211 |
# mac address-table 00:11:11:11:11:11 Vlan1 Ethernet20 |
| 212 |
# mac address-table 00:22:22:22:22:22 Vlan2 Ethernet24 |
| 213 |
# mac address-table aging-time 10 |
| 214 |
# |
| 215 |
# |
| 216 |
# Using "deleted" state |
| 217 |
# |
| 218 |
# Before state: |
| 219 |
# ------------- |
| 220 |
# |
| 221 |
# sonic# show mac dampening |
| 222 |
# MAC Move Dampening Threshold : 30 |
| 223 |
# MAC Move Dampening Interval : 20 |
| 224 |
# sonic# show running-configuration | grep mac |
| 225 |
# mac address-table 00:11:11:11:11:11 Vlan1 Ethernet20 |
| 226 |
# mac address-table 00:22:22:22:22:22 Vlan2 Ethernet24 |
| 227 |
# mac address-table aging-time 10 |
| 228 |
|
| 229 |
- name: Delete MAC cofigurations |
| 230 |
dellemc.enterprise_sonic.sonic_mac: |
| 231 |
config: |
| 232 |
- vrf_name: 'default' |
| 233 |
mac: |
| 234 |
aging_time: 10 |
| 235 |
dampening_interval: 20 |
| 236 |
dampening_threshold: 30 |
| 237 |
mac_table_entries: |
| 238 |
- mac_address: '00:11:11:11:11:11' |
| 239 |
vlan_id: 1 |
| 240 |
interface: 'Ethernet20' |
| 241 |
- mac_address: '00:22:22:22:22:22' |
| 242 |
vlan_id: 2 |
| 243 |
interface: 'Ethernet24' |
| 244 |
state: deleted |
| 245 |
|
| 246 |
# After state: |
| 247 |
# ------------ |
| 248 |
# |
| 249 |
# sonic# show mac dampening |
| 250 |
# MAC Move Dampening Threshold : 5 |
| 251 |
# MAC Move Dampening Interval : 5 |
| 252 |
# sonic# show running-configuration | grep mac |
| 253 |
# (No mac configuration present) |
| 254 |
""" |
| 255 |
|
| 256 |
RETURN = """ |
| 257 |
before: |
| 258 |
description: The configuration prior to the module invocation. |
| 259 |
returned: always |
| 260 |
type: list |
| 261 |
sample: > |
| 262 |
The configuration returned will always be in the same format |
| 263 |
as the parameters above. |
| 264 |
after: |
| 265 |
description: The resulting configuration module invocation. |
| 266 |
returned: when changed |
| 267 |
type: list |
| 268 |
sample: > |
| 269 |
The configuration returned will always be in the same format |
| 270 |
as the parameters above. |
| 271 |
after_generated: |
| 272 |
description: The generated configuration module invocation. |
| 273 |
returned: when C(check_mode) |
| 274 |
type: list |
| 275 |
sample: > |
| 276 |
The configuration returned will always be in the same format |
| 277 |
as the parameters above. |
| 278 |
commands: |
| 279 |
description: The set of commands pushed to the remote device. |
| 280 |
returned: always |
| 281 |
type: list |
| 282 |
sample: ['command 1', 'command 2', 'command 3'] |
| 283 |
""" |
| 284 |
|
| 285 |
|
| 286 |
from ansible.module_utils.basic import AnsibleModule |
| 287 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.mac.mac import MacArgs |
| 288 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.mac.mac import Mac |
| 289 |
|
| 290 |
|
| 291 |
def main(): |
| 292 |
""" |
| 293 |
Main entry point for module execution |
| 294 |
|
| 295 |
:returns: the result form module invocation |
| 296 |
""" |
| 297 |
module = AnsibleModule(argument_spec=MacArgs.argument_spec, |
| 298 |
supports_check_mode=True) |
| 299 |
|
| 300 |
result = Mac(module).execute_module() |
| 301 |
module.exit_json(**result) |
| 302 |
|
| 303 |
|
| 304 |
if __name__ == '__main__': |
| 305 |
main() |