| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
""" |
| 8 |
The module file for sonic_pms |
| 9 |
""" |
| 10 |
|
| 11 |
from __future__ import absolute_import, division, print_function |
| 12 |
__metaclass__ = type |
| 13 |
|
| 14 |
|
| 15 |
DOCUMENTATION = """ |
| 16 |
--- |
| 17 |
module: sonic_pms |
| 18 |
version_added: '3.1.0' |
| 19 |
notes: |
| 20 |
- Supports C(check_mode). |
| 21 |
- Tested against Enterprise SONiC Distribution by Dell Technologies. |
| 22 |
short_description: Configure interface mode port security settings on SONiC. |
| 23 |
description: |
| 24 |
- This module provides configuration management of port security interface mode parameters on devices running SONiC. |
| 25 |
- Configure switchport before configuring port security in interfaces. |
| 26 |
author: "Santhosh kumar T (@santhosh-kt)" |
| 27 |
options: |
| 28 |
config: |
| 29 |
description: |
| 30 |
- Specifies the port security interface configurations. |
| 31 |
type: list |
| 32 |
elements: dict |
| 33 |
suboptions: |
| 34 |
name: |
| 35 |
required: true |
| 36 |
type: str |
| 37 |
description: |
| 38 |
- Full name of the interface, i.e. Ethernet1. |
| 39 |
port_security_enable: |
| 40 |
required: true |
| 41 |
type: bool |
| 42 |
description: |
| 43 |
- Enables port security at interface level. |
| 44 |
- If I(port_security_enable=False), entire port security configurations will be deleted. |
| 45 |
max_allowed_macs: |
| 46 |
type: int |
| 47 |
description: |
| 48 |
- Maximum no. of secure MACs allowed on the interface. (1 to 4097) |
| 49 |
- If I(port_security_enable=True) and I(max_allowed_macs) not configured, default is C(1). |
| 50 |
violation: |
| 51 |
type: str |
| 52 |
description: |
| 53 |
- Configure the action to be taken in the event of security violation. |
| 54 |
- C(SHUTDOWN) - Shutdown the interface. |
| 55 |
- C(PROTECT) - Drop packets received on the interface. |
| 56 |
- If I(port_security_enable=True) and I(violation) not configured, default is C(PROTECT). |
| 57 |
choices: |
| 58 |
- SHUTDOWN |
| 59 |
- PROTECT |
| 60 |
sticky_mac: |
| 61 |
type: bool |
| 62 |
description: |
| 63 |
- Enable sticky MAC feature on the interface. |
| 64 |
- If I(port_security_enable=True) and I(sticky_mac) not configured, default is C(False). |
| 65 |
state: |
| 66 |
description: |
| 67 |
- Specifies the operation to be performed on the port security related interfaces configured on the device. |
| 68 |
- In case of merged, the input configuration will be merged with the existing port security interfaces related configuration on the device. |
| 69 |
- In case of deleted, the existing OSPFv2 interfaces configuration will be removed from the device. |
| 70 |
- In case of overridden, all the existing OSPFv2 interfaces configuration will be deleted and the specified input configuration will be installed. |
| 71 |
- In case of replaced, the existing interface configuration on the device will be replaced by the configuration in the playbook for |
| 72 |
each interface group configured by the playbook. |
| 73 |
type: str |
| 74 |
default: merged |
| 75 |
choices: ['merged', 'deleted', 'replaced', 'overridden'] |
| 76 |
""" |
| 77 |
|
| 78 |
EXAMPLES = """ |
| 79 |
# Using "deleted" state |
| 80 |
|
| 81 |
# Before state: |
| 82 |
# ------------- |
| 83 |
# |
| 84 |
# sonic# show port-security |
| 85 |
# |
| 86 |
# Secure Port isEnabled MaxSecureAddr FdbCount ViolationCount SecurityAction StickyMac |
| 87 |
# --------------------------------------------------------------------------------------------------------- |
| 88 |
# Ethernet0 Y 1 0 0 PROTECT N |
| 89 |
# Ethernet10 N 1 0 0 PROTECT Y |
| 90 |
# sonic# |
| 91 |
|
| 92 |
- name: Delete the PMS configurations |
| 93 |
sonic_pms: |
| 94 |
config: |
| 95 |
- name: 'Ethernet0' |
| 96 |
port_security_enable: true |
| 97 |
- name: 'Ethernet10' |
| 98 |
port_security_enable: false |
| 99 |
sticky_mac: true |
| 100 |
state: deleted |
| 101 |
|
| 102 |
# After state: |
| 103 |
# ------------ |
| 104 |
# |
| 105 |
# sonic# show port-security |
| 106 |
# |
| 107 |
# Secure Port isEnabled MaxSecureAddr FdbCount ViolationCount SecurityAction StickyMac |
| 108 |
# --------------------------------------------------------------------------------------------------------- |
| 109 |
# Ethernet10 N 1 0 0 PROTECT N |
| 110 |
# sonic# |
| 111 |
|
| 112 |
|
| 113 |
# Using "deleted" state |
| 114 |
|
| 115 |
# Before state: |
| 116 |
# ------------- |
| 117 |
# |
| 118 |
# sonic# show port-security |
| 119 |
# |
| 120 |
# Secure Port isEnabled MaxSecureAddr FdbCount ViolationCount SecurityAction StickyMac |
| 121 |
# --------------------------------------------------------------------------------------------------------- |
| 122 |
# Ethernet0 Y 1 0 0 PROTECT N |
| 123 |
# Ethernet3 Y 10 0 0 PROTECT N |
| 124 |
# Ethernet4 N 15 0 0 SHUTDOWN N |
| 125 |
# Ethernet5 Y 30 0 0 SHUTDOWN N |
| 126 |
# Ethernet10 N 1 0 0 PROTECT Y |
| 127 |
# sonic# |
| 128 |
|
| 129 |
- name: Delete all the PMS configurations |
| 130 |
sonic_pms: |
| 131 |
config: [] |
| 132 |
state: deleted |
| 133 |
|
| 134 |
# After state: |
| 135 |
# ------------ |
| 136 |
# |
| 137 |
# sonic# show port-security |
| 138 |
# sonic# |
| 139 |
|
| 140 |
|
| 141 |
# Using "merged" state |
| 142 |
|
| 143 |
# Before state: |
| 144 |
# ------------- |
| 145 |
# |
| 146 |
# sonic# show port-security |
| 147 |
# sonic# |
| 148 |
|
| 149 |
- name: Add the PMS configurations new to interfaces |
| 150 |
sonic_pms: |
| 151 |
config: |
| 152 |
- name: 'Ethernet0' |
| 153 |
sticky_mac: true |
| 154 |
port_security_enable: true |
| 155 |
max_allowed_macs: 10 |
| 156 |
- name: 'Ethernet3' |
| 157 |
port_security_enable: false |
| 158 |
max_allowed_macs: 10 |
| 159 |
- name: 'Ethernet4' |
| 160 |
port_security_enable: true |
| 161 |
violation: SHUTDOWN |
| 162 |
state: merged |
| 163 |
|
| 164 |
# After state: |
| 165 |
# ------------ |
| 166 |
# |
| 167 |
# sonic# show port-security |
| 168 |
# |
| 169 |
# Secure Port isEnabled MaxSecureAddr FdbCount ViolationCount SecurityAction StickyMac |
| 170 |
# --------------------------------------------------------------------------------------------------------- |
| 171 |
# Ethernet0 Y 10 0 0 PROTECT Y |
| 172 |
# Ethernet3 N 10 0 0 PROTECT N |
| 173 |
# Ethernet4 Y 1 0 0 SHUTDOWN N |
| 174 |
# sonic# |
| 175 |
|
| 176 |
|
| 177 |
# Using "merged" state |
| 178 |
|
| 179 |
# Before state: |
| 180 |
# ------------- |
| 181 |
# |
| 182 |
# sonic# show port-security |
| 183 |
# |
| 184 |
# Secure Port isEnabled MaxSecureAddr FdbCount ViolationCount SecurityAction StickyMac |
| 185 |
# --------------------------------------------------------------------------------------------------------- |
| 186 |
# Ethernet0 Y 10 0 0 PROTECT Y |
| 187 |
# Ethernet3 N 10 0 0 PROTECT N |
| 188 |
# Ethernet4 Y 1 0 0 SHUTDOWN N |
| 189 |
# sonic# |
| 190 |
|
| 191 |
- name: Disable a PMS interface by merge |
| 192 |
sonic_pms: |
| 193 |
config: |
| 194 |
- name: 'Ethernet10' |
| 195 |
port_security_enable: false |
| 196 |
max_allowed_macs: 12 |
| 197 |
violation: SHUTDOWN |
| 198 |
sticky_mac: true |
| 199 |
- name: 'Ethernet4' |
| 200 |
port_security_enable: false |
| 201 |
state: merged |
| 202 |
|
| 203 |
# After state: |
| 204 |
# ------------ |
| 205 |
# |
| 206 |
# sonic# show port-security |
| 207 |
# |
| 208 |
# Secure Port isEnabled MaxSecureAddr FdbCount ViolationCount SecurityAction StickyMac |
| 209 |
# --------------------------------------------------------------------------------------------------------- |
| 210 |
# Ethernet0 Y 10 0 0 PROTECT Y |
| 211 |
# Ethernet3 N 10 0 0 PROTECT N |
| 212 |
# Ethernet10 N 12 0 0 SHUTDOWN Y |
| 213 |
# sonic# |
| 214 |
|
| 215 |
|
| 216 |
# Using "replaced" state |
| 217 |
|
| 218 |
# Before state: |
| 219 |
# ------------- |
| 220 |
# |
| 221 |
# sonic# show port-security |
| 222 |
# |
| 223 |
# Secure Port isEnabled MaxSecureAddr FdbCount ViolationCount SecurityAction StickyMac |
| 224 |
# --------------------------------------------------------------------------------------------------------- |
| 225 |
# Ethernet0 Y 1 0 0 PROTECT N |
| 226 |
# Ethernet3 Y 10 0 0 PROTECT N |
| 227 |
# Ethernet4 N 15 0 0 SHUTDOWN N |
| 228 |
# Ethernet5 Y 30 0 0 SHUTDOWN N |
| 229 |
# Ethernet10 N 12 0 0 SHUTDOWN Y |
| 230 |
# sonic# |
| 231 |
|
| 232 |
- name: Replace the PMS configurations by interface level |
| 233 |
sonic_pms: |
| 234 |
config: |
| 235 |
- name: 'Ethernet10' |
| 236 |
port_security_enable: true |
| 237 |
- name: 'Ethernet3' |
| 238 |
port_security_enable: false |
| 239 |
violation: 'PROTECT' |
| 240 |
sticky_mac: true |
| 241 |
- name: 'Ethernet7' |
| 242 |
port_security_enable: true |
| 243 |
state: replaced |
| 244 |
|
| 245 |
# After state: |
| 246 |
# ------------ |
| 247 |
# |
| 248 |
# sonic# show port-security |
| 249 |
# |
| 250 |
# Secure Port isEnabled MaxSecureAddr FdbCount ViolationCount SecurityAction StickyMac |
| 251 |
# --------------------------------------------------------------------------------------------------------- |
| 252 |
# Ethernet0 Y 1 0 0 PROTECT N |
| 253 |
# Ethernet3 N 10 0 0 PROTECT Y |
| 254 |
# Ethernet4 N 15 0 0 SHUTDOWN N |
| 255 |
# Ethernet5 Y 30 0 0 SHUTDOWN N |
| 256 |
# Ethernet7 Y 1 0 0 PROTECT N |
| 257 |
# Ethernet10 Y 1 0 0 PROTECT N |
| 258 |
# sonic# |
| 259 |
|
| 260 |
|
| 261 |
# Using "overridden" state |
| 262 |
|
| 263 |
# Before state: |
| 264 |
# ------------- |
| 265 |
# |
| 266 |
# sonic# show port-security |
| 267 |
# |
| 268 |
# Secure Port isEnabled MaxSecureAddr FdbCount ViolationCount SecurityAction StickyMac |
| 269 |
# --------------------------------------------------------------------------------------------------------- |
| 270 |
# Ethernet0 Y 1 0 0 PROTECT N |
| 271 |
# Ethernet3 Y 10 0 0 PROTECT N |
| 272 |
# Ethernet4 N 15 0 0 SHUTDOWN N |
| 273 |
# Ethernet5 Y 30 0 0 SHUTDOWN N |
| 274 |
# Ethernet10 N 12 0 0 SHUTDOWN Y |
| 275 |
# sonic# |
| 276 |
|
| 277 |
- name: Override the PMS configurations |
| 278 |
sonic_pms: |
| 279 |
config: |
| 280 |
- name: 'Ethernet7' |
| 281 |
port_security_enable: true |
| 282 |
- name: 'Ethernet10' |
| 283 |
port_security_enable: false |
| 284 |
max_allowed_macs: 12 |
| 285 |
violation: SHUTDOWN |
| 286 |
sticky_mac: true |
| 287 |
state: overridden |
| 288 |
|
| 289 |
# After state: |
| 290 |
# ------------ |
| 291 |
# |
| 292 |
# sonic# show port-security |
| 293 |
# |
| 294 |
# Secure Port isEnabled MaxSecureAddr FdbCount ViolationCount SecurityAction StickyMac |
| 295 |
# --------------------------------------------------------------------------------------------------------- |
| 296 |
# Ethernet7 Y 1 0 0 PROTECT N |
| 297 |
# Ethernet10 N 12 0 0 SHUTDOWN Y |
| 298 |
# sonic# |
| 299 |
""" |
| 300 |
|
| 301 |
RETURN = """ |
| 302 |
before: |
| 303 |
description: The configuration prior to the module invocation. |
| 304 |
returned: always |
| 305 |
type: list |
| 306 |
sample: > |
| 307 |
The configuration returned will always be in the same format |
| 308 |
of the parameters above. |
| 309 |
after: |
| 310 |
description: The configuration resulting from module invocation. |
| 311 |
returned: when changed |
| 312 |
type: list |
| 313 |
sample: > |
| 314 |
The configuration returned will always be in the same format |
| 315 |
of the parameters above. |
| 316 |
after_generated: |
| 317 |
description: The configuration that would be generated by non-check-mode module invocation. |
| 318 |
returned: when C(check_mode) |
| 319 |
type: list |
| 320 |
sample: > |
| 321 |
The configuration returned will always be in the same format |
| 322 |
of the parameters above. |
| 323 |
commands: |
| 324 |
description: The set of commands pushed to the remote device. |
| 325 |
returned: always |
| 326 |
type: list |
| 327 |
sample: ['command 1', 'command 2', 'command 3'] |
| 328 |
""" |
| 329 |
|
| 330 |
|
| 331 |
from ansible.module_utils.basic import AnsibleModule |
| 332 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.pms.pms import PmsArgs |
| 333 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.pms.pms import Pms |
| 334 |
|
| 335 |
|
| 336 |
def main(): |
| 337 |
""" |
| 338 |
Main entry point for module execution |
| 339 |
|
| 340 |
:returns: the result form module invocation |
| 341 |
""" |
| 342 |
module = AnsibleModule(argument_spec=PmsArgs.argument_spec, |
| 343 |
supports_check_mode=True) |
| 344 |
|
| 345 |
result = Pms(module).execute_module() |
| 346 |
module.exit_json(**result) |
| 347 |
|
| 348 |
|
| 349 |
if __name__ == '__main__': |
| 350 |
main() |