| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
""" |
| 8 |
The module file for sonic_ip_neighbor_interfaces |
| 9 |
""" |
| 10 |
|
| 11 |
from __future__ import absolute_import, division, print_function |
| 12 |
__metaclass__ = type |
| 13 |
|
| 14 |
DOCUMENTATION = """ |
| 15 |
--- |
| 16 |
module: sonic_ip_neighbor_interfaces |
| 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 interface-specific IP neighbor configurations on SONiC |
| 22 |
description: |
| 23 |
- This module provides configuration management of interface-specific |
| 24 |
IP neighbor parameters for devices running SONiC. |
| 25 |
author: 'Arun Saravanan Balachandran (@ArunSaravananBalachandran)' |
| 26 |
options: |
| 27 |
config: |
| 28 |
description: |
| 29 |
- Specifies interface-specific IP neighbor configurations. |
| 30 |
type: list |
| 31 |
elements: dict |
| 32 |
suboptions: |
| 33 |
name: |
| 34 |
description: |
| 35 |
- Full name of the interface. |
| 36 |
type: str |
| 37 |
required: true |
| 38 |
ipv4_neighbors: |
| 39 |
description: |
| 40 |
- Specifies the static IPv4 neighbors. |
| 41 |
- I(ip) & I(mac) are required for adding a new neighbor. |
| 42 |
type: list |
| 43 |
elements: dict |
| 44 |
suboptions: |
| 45 |
ip: |
| 46 |
description: |
| 47 |
- IPv4 address of the neighbor. |
| 48 |
type: str |
| 49 |
required: true |
| 50 |
mac: |
| 51 |
description: |
| 52 |
- MAC address of the neighbor. |
| 53 |
type: str |
| 54 |
ipv6_neighbors: |
| 55 |
description: |
| 56 |
- Specifies the static IPv6 neighbors. |
| 57 |
- I(ip) & I(mac) are required for adding a new neighbor. |
| 58 |
type: list |
| 59 |
elements: dict |
| 60 |
suboptions: |
| 61 |
ip: |
| 62 |
description: |
| 63 |
- IPv6 address of the neighbor. |
| 64 |
type: str |
| 65 |
required: true |
| 66 |
mac: |
| 67 |
description: |
| 68 |
- MAC address of the neighbor. |
| 69 |
type: str |
| 70 |
state: |
| 71 |
description: |
| 72 |
- The state of the configuration after module completion. |
| 73 |
- C(merged) - Merges provided interface-specific IP neighbor configuration with on-device configuration. |
| 74 |
- C(replaced) - Replaces on-device IP neighbor configuration of the specified interfaces with provided configuration. |
| 75 |
- C(overridden) - Overrides all on-device interface-specific IP neighbor configurations with the provided configuration. |
| 76 |
- C(deleted) - Deletes on-device interface-specific IP neighbor configuration. |
| 77 |
type: str |
| 78 |
choices: |
| 79 |
- merged |
| 80 |
- deleted |
| 81 |
- replaced |
| 82 |
- overridden |
| 83 |
default: merged |
| 84 |
""" |
| 85 |
EXAMPLES = """ |
| 86 |
# Using "merged" state |
| 87 |
# |
| 88 |
# Before state: |
| 89 |
# ------------- |
| 90 |
# |
| 91 |
# sonic# show running-configuration interface Vlan 10 | grep "arp|neighbor" |
| 92 |
# ip arp 10.1.1.4 00:01:02:03:44:55 |
| 93 |
# sonic# show running-configuration interface Vlan 20 | grep "arp|neighbor" |
| 94 |
# sonic# |
| 95 |
|
| 96 |
- name: Merge provided interface IP neighbor configurations |
| 97 |
dellemc.enterprise_sonic.sonic_ip_neighbor_interfaces: |
| 98 |
config: |
| 99 |
- name: 'Vlan10' |
| 100 |
ipv6_neighbors: |
| 101 |
- ip: '10::2' |
| 102 |
mac: '00:01:02:03:04:22' |
| 103 |
- name: 'Vlan20' |
| 104 |
ipv4_neighbors: |
| 105 |
- ip: '20.1.1.4' |
| 106 |
mac: '00:01:02:03:22:44' |
| 107 |
- ip: '20.1.1.5' |
| 108 |
mac: '00:01:02:03:22:55' |
| 109 |
state: merged |
| 110 |
|
| 111 |
# After state: |
| 112 |
# ------------ |
| 113 |
# |
| 114 |
# sonic# show running-configuration interface Vlan 10 | grep "arp|neighbor" |
| 115 |
# ip arp 10.1.1.4 00:01:02:03:44:55 |
| 116 |
# ipv6 neighbor 10::2 00:01:02:03:04:22 |
| 117 |
# sonic# show running-configuration interface Vlan 20 | grep "arp|neighbor" |
| 118 |
# ip arp 20.1.1.4 00:01:02:03:22:44 |
| 119 |
# ip arp 20.1.1.5 00:01:02:03:22:55 |
| 120 |
# sonic# |
| 121 |
|
| 122 |
|
| 123 |
# Using "deleted" state |
| 124 |
# |
| 125 |
# Before state: |
| 126 |
# ------------- |
| 127 |
# |
| 128 |
# sonic# show running-configuration interface Vlan 10 | grep "arp|neighbor" |
| 129 |
# ip arp 10.1.1.3 00:01:02:03:33:55 |
| 130 |
# ip arp 10.1.1.4 00:01:02:03:44:55 |
| 131 |
# ipv6 neighbor 10::2 00:01:02:03:04:22 |
| 132 |
# ipv6 neighbor 10::3 00:01:02:03:04:33 |
| 133 |
# sonic# show running-configuration interface Vlan 20 | grep "arp|neighbor" |
| 134 |
# ip arp 20.1.1.4 00:01:02:03:22:44 |
| 135 |
# ip arp 20.1.1.5 00:01:02:03:22:55 |
| 136 |
# ipv6 neighbor 20::2 00:01:02:03:22:22 |
| 137 |
# ipv6 neighbor 20::3 00:01:02:03:22:33 |
| 138 |
# sonic# |
| 139 |
|
| 140 |
- name: Delete interface IP neighbor configurations |
| 141 |
dellemc.enterprise_sonic.sonic_ip_neighbor_interfaces: |
| 142 |
config: |
| 143 |
- name: 'Vlan10' |
| 144 |
ipv4_neighbors: |
| 145 |
- ip: '10.1.1.4' |
| 146 |
ipv6_neighbors: |
| 147 |
- ip: '10::2' |
| 148 |
- name: 'Vlan20' |
| 149 |
ipv4_neighbors: |
| 150 |
- ip: '20.1.1.4' |
| 151 |
state: deleted |
| 152 |
|
| 153 |
# After state: |
| 154 |
# ------------ |
| 155 |
# |
| 156 |
# sonic# show running-configuration interface Vlan 10 | grep "arp|neighbor" |
| 157 |
# ip arp 10.1.1.3 00:01:02:03:33:55 |
| 158 |
# ipv6 neighbor 10::3 00:01:02:03:04:33 |
| 159 |
# sonic# show running-configuration interface Vlan 20 | grep "arp|neighbor" |
| 160 |
# ip arp 20.1.1.5 00:01:02:03:22:55 |
| 161 |
# ipv6 neighbor 20::2 00:01:02:03:22:22 |
| 162 |
# ipv6 neighbor 20::3 00:01:02:03:22:33 |
| 163 |
# sonic# |
| 164 |
|
| 165 |
|
| 166 |
# Using "deleted" state |
| 167 |
# |
| 168 |
# Before state: |
| 169 |
# ------------- |
| 170 |
# |
| 171 |
# sonic# show running-configuration interface Vlan 10 | grep "arp|neighbor" |
| 172 |
# ip arp 10.1.1.3 00:01:02:03:33:55 |
| 173 |
# ip arp 10.1.1.4 00:01:02:03:44:55 |
| 174 |
# ipv6 neighbor 10::2 00:01:02:03:04:22 |
| 175 |
# ipv6 neighbor 10::3 00:01:02:03:04:33 |
| 176 |
# sonic# show running-configuration interface Vlan 20 | grep "arp|neighbor" |
| 177 |
# ip arp 20.1.1.4 00:01:02:03:22:44 |
| 178 |
# ip arp 20.1.1.5 00:01:02:03:22:55 |
| 179 |
# ipv6 neighbor 20::2 00:01:02:03:22:22 |
| 180 |
# ipv6 neighbor 20::3 00:01:02:03:22:33 |
| 181 |
# sonic# |
| 182 |
|
| 183 |
- name: Delete all interface IP neighbor configurations for interface Vlan 10 |
| 184 |
dellemc.enterprise_sonic.sonic_ip_neighbor_interfaces: |
| 185 |
config: |
| 186 |
- name: 'Vlan10' |
| 187 |
state: deleted |
| 188 |
|
| 189 |
# After state: |
| 190 |
# ------------ |
| 191 |
# |
| 192 |
# sonic# show running-configuration interface Vlan 10 | grep "arp|neighbor" |
| 193 |
# sonic# show running-configuration interface Vlan 20 | grep "arp|neighbor" |
| 194 |
# ip arp 20.1.1.4 00:01:02:03:22:44 |
| 195 |
# ip arp 20.1.1.5 00:01:02:03:22:55 |
| 196 |
# ipv6 neighbor 20::2 00:01:02:03:22:22 |
| 197 |
# ipv6 neighbor 20::3 00:01:02:03:22:33 |
| 198 |
# sonic# |
| 199 |
|
| 200 |
|
| 201 |
# Using "deleted" state |
| 202 |
# |
| 203 |
# Before state: |
| 204 |
# ------------- |
| 205 |
# |
| 206 |
# sonic# show running-configuration interface Vlan 10 | grep "arp|neighbor" |
| 207 |
# ip arp 10.1.1.3 00:01:02:03:33:55 |
| 208 |
# ip arp 10.1.1.4 00:01:02:03:44:55 |
| 209 |
# ipv6 neighbor 10::2 00:01:02:03:04:22 |
| 210 |
# ipv6 neighbor 10::3 00:01:02:03:04:33 |
| 211 |
# sonic# show running-configuration interface Vlan 20 | grep "arp|neighbor" |
| 212 |
# ip arp 20.1.1.4 00:01:02:03:22:44 |
| 213 |
# ip arp 20.1.1.5 00:01:02:03:22:55 |
| 214 |
# ipv6 neighbor 20::2 00:01:02:03:22:22 |
| 215 |
# sonic# |
| 216 |
|
| 217 |
- name: Delete all interface IP neighbor configurations |
| 218 |
dellemc.enterprise_sonic.sonic_ip_neighbor_interfaces: |
| 219 |
config: |
| 220 |
state: deleted |
| 221 |
|
| 222 |
# After state: |
| 223 |
# ------------ |
| 224 |
# |
| 225 |
# sonic# show running-configuration interface Vlan 10 | grep "arp|neighbor" |
| 226 |
# sonic# show running-configuration interface Vlan 20 | grep "arp|neighbor" |
| 227 |
# sonic# |
| 228 |
|
| 229 |
|
| 230 |
# Using "replaced" state |
| 231 |
# |
| 232 |
# Before state: |
| 233 |
# ------------- |
| 234 |
# |
| 235 |
# sonic# show running-configuration interface Vlan 10 | grep "arp|neighbor" |
| 236 |
# ip arp 10.1.1.3 00:01:02:03:33:55 |
| 237 |
# ip arp 10.1.1.4 00:01:02:03:44:55 |
| 238 |
# ipv6 neighbor 10::2 00:01:02:03:04:22 |
| 239 |
# ipv6 neighbor 10::3 00:01:02:03:04:33 |
| 240 |
# sonic# show running-configuration interface Vlan 20 | grep "arp|neighbor" |
| 241 |
# ip arp 20.1.1.4 00:01:02:03:22:44 |
| 242 |
# ip arp 20.1.1.5 00:01:02:03:22:55 |
| 243 |
# ipv6 neighbor 20::2 00:01:02:03:22:22 |
| 244 |
# ipv6 neighbor 20::3 00:01:02:03:22:33 |
| 245 |
# sonic# |
| 246 |
|
| 247 |
- name: Replace interface IP neighbor configurations for interface Vlan 10 |
| 248 |
dellemc.enterprise_sonic.sonic_ip_neighbor_interfaces: |
| 249 |
config: |
| 250 |
- name: 'Vlan10' |
| 251 |
ipv4_neighbors: |
| 252 |
- ip: '10.1.1.11' |
| 253 |
mac: '00:01:02:03:04:11' |
| 254 |
- ip: '10.1.1.12' |
| 255 |
mac: '00:01:02:03:04:12' |
| 256 |
state: replaced |
| 257 |
|
| 258 |
# After state: |
| 259 |
# ------------ |
| 260 |
# |
| 261 |
# sonic# show running-configuration interface Vlan 10 | grep "arp|neighbor" |
| 262 |
# ip arp 10.1.1.11 00:01:02:03:04:11 |
| 263 |
# ip arp 10.1.1.12 00:01:02:03:04:12 |
| 264 |
# sonic# show running-configuration interface Vlan 20 | grep "arp|neighbor" |
| 265 |
# ip arp 20.1.1.4 00:01:02:03:22:44 |
| 266 |
# ip arp 20.1.1.5 00:01:02:03:22:55 |
| 267 |
# ipv6 neighbor 20::2 00:01:02:03:22:22 |
| 268 |
# ipv6 neighbor 20::3 00:01:02:03:22:33 |
| 269 |
# sonic# |
| 270 |
|
| 271 |
|
| 272 |
# Using "overridden" state |
| 273 |
# |
| 274 |
# Before state: |
| 275 |
# ------------- |
| 276 |
# |
| 277 |
# sonic# show running-configuration interface Vlan 10 | grep "arp|neighbor" |
| 278 |
# ip arp 10.1.1.3 00:01:02:03:33:55 |
| 279 |
# ip arp 10.1.1.4 00:01:02:03:44:55 |
| 280 |
# ipv6 neighbor 10::2 00:01:02:03:04:22 |
| 281 |
# ipv6 neighbor 10::3 00:01:02:03:04:33 |
| 282 |
# sonic# show running-configuration interface Vlan 20 | grep "arp|neighbor" |
| 283 |
# ip arp 20.1.1.4 00:01:02:03:22:44 |
| 284 |
# ip arp 20.1.1.5 00:01:02:03:22:55 |
| 285 |
# ipv6 neighbor 20::2 00:01:02:03:22:22 |
| 286 |
# ipv6 neighbor 20::3 00:01:02:03:22:33 |
| 287 |
# sonic# show running-configuration interface Vlan 30 | grep "arp|neighbor" |
| 288 |
# sonic# |
| 289 |
|
| 290 |
- name: Override all interface IP neighbor configurations |
| 291 |
dellemc.enterprise_sonic.sonic_ip_neighbor_interfaces: |
| 292 |
config: |
| 293 |
- name: 'Vlan10' |
| 294 |
ipv4_neighbors: |
| 295 |
- ip: '10.1.1.11' |
| 296 |
mac: '00:01:02:03:04:11' |
| 297 |
ipv6_neighbors: |
| 298 |
- ip: '10::11' |
| 299 |
mac: '00:01:02:03:10:11' |
| 300 |
- name: 'Vlan30' |
| 301 |
ipv4_neighbors: |
| 302 |
- ip: '30.1.1.6' |
| 303 |
mac: '00:01:02:03:30:66' |
| 304 |
- ip: '30.1.1.7' |
| 305 |
mac: '00:01:02:03:30:77' |
| 306 |
state: overridden |
| 307 |
|
| 308 |
# After state: |
| 309 |
# ------------ |
| 310 |
# |
| 311 |
# sonic# show running-configuration interface Vlan 10 | grep "arp|neighbor" |
| 312 |
# ip arp 10.1.1.11 00:01:02:03:04:11 |
| 313 |
# ipv6 neighbor 10::11 00:01:02:03:10:11 |
| 314 |
# sonic# show running-configuration interface Vlan 20 | grep "arp|neighbor" |
| 315 |
# sonic# show running-configuration interface Vlan 30 | grep "arp|neighbor" |
| 316 |
# ip arp 30.1.1.6 00:01:02:03:30:66 |
| 317 |
# ip arp 30.1.1.7 00:01:02:03:30:77 |
| 318 |
# sonic# |
| 319 |
""" |
| 320 |
RETURN = """ |
| 321 |
before: |
| 322 |
description: The configuration prior to the module invocation. |
| 323 |
returned: always |
| 324 |
type: list |
| 325 |
after: |
| 326 |
description: The configuration resulting from module invocation. |
| 327 |
returned: when changed |
| 328 |
type: list |
| 329 |
after_generated: |
| 330 |
description: The generated configuration from module invocation. |
| 331 |
returned: when C(check_mode) |
| 332 |
type: list |
| 333 |
commands: |
| 334 |
description: The set of commands pushed to the remote device. |
| 335 |
returned: always |
| 336 |
type: list |
| 337 |
""" |
| 338 |
|
| 339 |
|
| 340 |
from ansible.module_utils.basic import AnsibleModule |
| 341 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.ip_neighbor_interfaces.ip_neighbor_interfaces import ( |
| 342 |
Ip_neighbor_interfacesArgs |
| 343 |
) |
| 344 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.ip_neighbor_interfaces.ip_neighbor_interfaces import ( |
| 345 |
Ip_neighbor_interfaces |
| 346 |
) |
| 347 |
|
| 348 |
|
| 349 |
def main(): |
| 350 |
""" |
| 351 |
Main entry point for module execution |
| 352 |
|
| 353 |
:returns: the result form module invocation |
| 354 |
""" |
| 355 |
module = AnsibleModule(argument_spec=Ip_neighbor_interfacesArgs.argument_spec, |
| 356 |
supports_check_mode=True) |
| 357 |
|
| 358 |
result = Ip_neighbor_interfaces(module).execute_module() |
| 359 |
module.exit_json(**result) |
| 360 |
|
| 361 |
|
| 362 |
if __name__ == '__main__': |
| 363 |
main() |