| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
""" |
| 8 |
The module file for sonic_ip_neighbor |
| 9 |
""" |
| 10 |
|
| 11 |
from __future__ import absolute_import, division, print_function |
| 12 |
__metaclass__ = type |
| 13 |
|
| 14 |
|
| 15 |
DOCUMENTATION = """ |
| 16 |
--- |
| 17 |
module: sonic_ip_neighbor |
| 18 |
version_added: 2.1.0 |
| 19 |
notes: |
| 20 |
- Supports C(check_mode). |
| 21 |
short_description: Manage IP neighbor global configuration on SONiC. |
| 22 |
description: |
| 23 |
- This module provides configuration management of IP neighbor global for devices running SONiC. |
| 24 |
author: "M. Zhang (@mingjunzhang2019)" |
| 25 |
options: |
| 26 |
config: |
| 27 |
description: |
| 28 |
- Specifies IP neighbor global configurations. |
| 29 |
type: dict |
| 30 |
suboptions: |
| 31 |
ipv4_arp_timeout: |
| 32 |
type: int |
| 33 |
description: |
| 34 |
- IPv4 ARP timeout. |
| 35 |
- The range is from 60 to 14400. |
| 36 |
ipv6_nd_cache_expiry: |
| 37 |
type: int |
| 38 |
description: |
| 39 |
- IPv6 ND cache expiry. |
| 40 |
- The range is from 60 to 14400. |
| 41 |
num_local_neigh: |
| 42 |
type: int |
| 43 |
description: |
| 44 |
- The number of reserved local neighbors. |
| 45 |
- The range is from 0 to 32000. |
| 46 |
ipv4_drop_neighbor_aging_time: |
| 47 |
type: int |
| 48 |
description: |
| 49 |
- IPv4 drop neighbor aging time. |
| 50 |
- The range is from 60 to 14400. |
| 51 |
ipv6_drop_neighbor_aging_time: |
| 52 |
type: int |
| 53 |
description: |
| 54 |
- IPv6 drop neighbor aging time. |
| 55 |
- The range is from 60 to 14400. |
| 56 |
state: |
| 57 |
description: |
| 58 |
- The state of the configuration after module completion. |
| 59 |
type: str |
| 60 |
choices: |
| 61 |
- merged |
| 62 |
- replaced |
| 63 |
- overridden |
| 64 |
- deleted |
| 65 |
default: merged |
| 66 |
""" |
| 67 |
|
| 68 |
EXAMPLES = """ |
| 69 |
# |
| 70 |
# Using "merged" state |
| 71 |
# |
| 72 |
# Before state: |
| 73 |
# ------------- |
| 74 |
# |
| 75 |
# sonic# show running-configuration |
| 76 |
# ! |
| 77 |
# ip arp timeout 180 |
| 78 |
# ip drop-neighbor aging-time 300 |
| 79 |
# ipv6 drop-neighbor aging-time 300 |
| 80 |
# ip reserve local-neigh 0 |
| 81 |
# ipv6 nd cache expire 180 |
| 82 |
# ! |
| 83 |
- name: Configure IP neighbor global |
| 84 |
sonic_ip_neighbor: |
| 85 |
config: |
| 86 |
ipv4_arp_timeout: 1200 |
| 87 |
ipv4_drop_neighbor_aging_time: 600 |
| 88 |
ipv6_drop_neighbor_aging_time: 600 |
| 89 |
ipv6_nd_cache_expiry: 1200 |
| 90 |
num_local_neigh: 1000 |
| 91 |
state: merged |
| 92 |
|
| 93 |
# After state: |
| 94 |
# ------------ |
| 95 |
# |
| 96 |
# sonic# show running-configuration |
| 97 |
# ! |
| 98 |
# ip arp timeout 1200 |
| 99 |
# ip drop-neighbor aging-time 600 |
| 100 |
# ipv6 drop-neighbor aging-time 600 |
| 101 |
# ip reserve local-neigh 1000 |
| 102 |
# ipv6 nd cache expire 1200 |
| 103 |
# ! |
| 104 |
# |
| 105 |
# Using "deleted" state |
| 106 |
# |
| 107 |
# Before state: |
| 108 |
# ------------- |
| 109 |
# |
| 110 |
# sonic# show running-configuration |
| 111 |
# ! |
| 112 |
# ip arp timeout 1200 |
| 113 |
# ip drop-neighbor aging-time 600 |
| 114 |
# ipv6 drop-neighbor aging-time 600 |
| 115 |
# ip reserve local-neigh 1000 |
| 116 |
# ipv6 nd cache expire 1200 |
| 117 |
# ! |
| 118 |
- name: Delete some IP neighbor configuration |
| 119 |
sonic_ip_neighbor: |
| 120 |
config: |
| 121 |
ipv4_arp_timeout: 0 |
| 122 |
ipv4_drop_neighbor_aging_time: 0 |
| 123 |
state: deleted |
| 124 |
|
| 125 |
# After state: |
| 126 |
# ------------ |
| 127 |
# |
| 128 |
# sonic# show running-configuration |
| 129 |
# ! |
| 130 |
# ip arp timeout 180 |
| 131 |
# ip drop-neighbor aging-time 300 |
| 132 |
# ipv6 drop-neighbor aging-time 600 |
| 133 |
# ip reserve local-neigh 1000 |
| 134 |
# ipv6 nd cache expire 1200 |
| 135 |
# ! |
| 136 |
# |
| 137 |
# Using "deleted" state |
| 138 |
# |
| 139 |
# Before state: |
| 140 |
# ------------- |
| 141 |
# |
| 142 |
# sonic# show running-configuration |
| 143 |
# ! |
| 144 |
# ip arp timeout 1200 |
| 145 |
# ip drop-neighbor aging-time 600 |
| 146 |
# ipv6 drop-neighbor aging-time 600 |
| 147 |
# ip reserve local-neigh 1000 |
| 148 |
# ipv6 nd cache expire 1200 |
| 149 |
# ! |
| 150 |
- name: Delete all IP neighbor configuration |
| 151 |
sonic_ip_neighbor: |
| 152 |
config: {} |
| 153 |
state: deleted |
| 154 |
|
| 155 |
# After state: |
| 156 |
# ------------ |
| 157 |
# |
| 158 |
# sonic# show running-configuration |
| 159 |
# ! |
| 160 |
# ip arp timeout 180 |
| 161 |
# ip drop-neighbor aging-time 300 |
| 162 |
# ipv6 drop-neighbor aging-time 300 |
| 163 |
# ip reserve local-neigh 0 |
| 164 |
# ipv6 nd cache expire 180 |
| 165 |
# ! |
| 166 |
# |
| 167 |
# Using "replaced" state |
| 168 |
# |
| 169 |
# Before state: |
| 170 |
# ------------- |
| 171 |
# |
| 172 |
# sonic# show running-configuration |
| 173 |
# ! |
| 174 |
# ip arp timeout 1200 |
| 175 |
# ip drop-neighbor aging-time 600 |
| 176 |
# ipv6 drop-neighbor aging-time 300 |
| 177 |
# ip reserve local-neigh 0 |
| 178 |
# ipv6 nd cache expire 180 |
| 179 |
# ! |
| 180 |
- name: Change some IP neighbor configuration |
| 181 |
sonic_ip_neighbor: |
| 182 |
config: |
| 183 |
ipv6_drop_neighbor_aging_time: 600 |
| 184 |
ipv6_nd_cache_expiry: 1200 |
| 185 |
num_local_neigh: 1000 |
| 186 |
state: replaced |
| 187 |
|
| 188 |
# After state: |
| 189 |
# ------------ |
| 190 |
# |
| 191 |
# sonic# show running-configuration |
| 192 |
# ! |
| 193 |
# ip arp timeout 1200 |
| 194 |
# ip drop-neighbor aging-time 600 |
| 195 |
# ipv6 drop-neighbor aging-time 600 |
| 196 |
# ip reserve local-neigh 1000 |
| 197 |
# ipv6 nd cache expire 1200 |
| 198 |
# ! |
| 199 |
# |
| 200 |
# Using "overridden" state |
| 201 |
# |
| 202 |
# Before state: |
| 203 |
# ------------- |
| 204 |
# |
| 205 |
# sonic# show running-configuration |
| 206 |
# ! |
| 207 |
# ip arp timeout 1200 |
| 208 |
# ip drop-neighbor aging-time 600 |
| 209 |
# ipv6 drop-neighbor aging-time 300 |
| 210 |
# ip reserve local-neigh 0 |
| 211 |
# ipv6 nd cache expire 180 |
| 212 |
# ! |
| 213 |
- name: Reset IP neighbor configuration, then configure some |
| 214 |
sonic_ip_neighbor: |
| 215 |
config: |
| 216 |
ipv6_drop_neighbor_aging_time: 600 |
| 217 |
ipv6_nd_cache_expiry: 1200 |
| 218 |
num_local_neigh: 1000 |
| 219 |
state: overridden |
| 220 |
|
| 221 |
# After state: |
| 222 |
# ------------ |
| 223 |
# |
| 224 |
# sonic# show running-configuration |
| 225 |
# ! |
| 226 |
# ip arp timeout 180 |
| 227 |
# ip drop-neighbor aging-time 300 |
| 228 |
# ipv6 drop-neighbor aging-time 600 |
| 229 |
# ip reserve local-neigh 1000 |
| 230 |
# ipv6 nd cache expire 1200 |
| 231 |
# ! |
| 232 |
# |
| 233 |
""" |
| 234 |
|
| 235 |
RETURN = """ |
| 236 |
before: |
| 237 |
description: The configuration prior to the module invocation. |
| 238 |
returned: always |
| 239 |
type: list |
| 240 |
sample: > |
| 241 |
The configuration returned will always be in the same format |
| 242 |
as the parameters above. |
| 243 |
after: |
| 244 |
description: The resulting configuration module invocation. |
| 245 |
returned: when changed |
| 246 |
type: list |
| 247 |
sample: > |
| 248 |
The configuration returned will always be in the same format |
| 249 |
as the parameters above. |
| 250 |
after_generated: |
| 251 |
description: The generated configuration module invocation. |
| 252 |
returned: when C(check_mode) |
| 253 |
type: list |
| 254 |
sample: > |
| 255 |
The configuration returned will always be in the same format |
| 256 |
as the parameters above. |
| 257 |
commands: |
| 258 |
description: The set of commands pushed to the remote device. |
| 259 |
returned: always |
| 260 |
type: list |
| 261 |
sample: ['command 1', 'command 2', 'command 3'] |
| 262 |
""" |
| 263 |
|
| 264 |
|
| 265 |
from ansible.module_utils.basic import AnsibleModule |
| 266 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.ip_neighbor.ip_neighbor import Ip_neighborArgs |
| 267 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.ip_neighbor.ip_neighbor import Ip_neighbor |
| 268 |
|
| 269 |
|
| 270 |
def main(): |
| 271 |
""" |
| 272 |
Main entry point for module execution |
| 273 |
|
| 274 |
:returns: the result form module invocation |
| 275 |
""" |
| 276 |
module = AnsibleModule(argument_spec=Ip_neighborArgs.argument_spec, |
| 277 |
supports_check_mode=True) |
| 278 |
|
| 279 |
result = Ip_neighbor(module).execute_module() |
| 280 |
module.exit_json(**result) |
| 281 |
|
| 282 |
|
| 283 |
if __name__ == '__main__': |
| 284 |
main() |