| 1 |
|
| 2 |
|
| 3 |
. |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
""" |
| 8 |
The module file for sonic_bgp |
| 9 |
""" |
| 10 |
|
| 11 |
from __future__ import absolute_import, division, print_function |
| 12 |
__metaclass__ = type |
| 13 |
|
| 14 |
DOCUMENTATION = """ |
| 15 |
--- |
| 16 |
module: sonic_bgp |
| 17 |
version_added: 1.0.0 |
| 18 |
notes: |
| 19 |
- Tested against Enterprise SONiC Distribution by Dell Technologies. |
| 20 |
- Supports C(check_mode). |
| 21 |
author: Dhivya P (@dhivayp) |
| 22 |
short_description: Manage global BGP and its parameters |
| 23 |
description: |
| 24 |
- This module provides configuration management of global BGP parameters on devices running Enterprise SONiC Distribution by Dell Technologies. |
| 25 |
options: |
| 26 |
config: |
| 27 |
description: |
| 28 |
- Specifies the BGP-related configuration. |
| 29 |
type: list |
| 30 |
elements: dict |
| 31 |
suboptions: |
| 32 |
bgp_as: |
| 33 |
description: |
| 34 |
- Specifies the BGP autonomous system (AS) number to configure on the device. |
| 35 |
type: str |
| 36 |
required: true |
| 37 |
vrf_name: |
| 38 |
description: |
| 39 |
- Specifies the VRF name. |
| 40 |
type: str |
| 41 |
default: 'default' |
| 42 |
router_id: |
| 43 |
description: |
| 44 |
- Configures the BGP routing process router-id value. |
| 45 |
type: str |
| 46 |
log_neighbor_changes: |
| 47 |
description: |
| 48 |
- Enables/disables logging neighbor up/down and reset reason. |
| 49 |
type: bool |
| 50 |
as_notation: |
| 51 |
description: |
| 52 |
- Specify the AS number notation format |
| 53 |
- Option supported on Enterprise-Sonic releases 4.4.0 and higher. |
| 54 |
choices: ['asdot', 'asdot+'] |
| 55 |
type: str |
| 56 |
max_med: |
| 57 |
description: |
| 58 |
- Configure max med and its parameters |
| 59 |
type: dict |
| 60 |
suboptions: |
| 61 |
on_startup: |
| 62 |
description: |
| 63 |
- On startup time and max-med value |
| 64 |
type: dict |
| 65 |
suboptions: |
| 66 |
timer: |
| 67 |
description: |
| 68 |
- Configures on startup time |
| 69 |
type: int |
| 70 |
med_val: |
| 71 |
description: |
| 72 |
- on startup med value |
| 73 |
type: int |
| 74 |
timers: |
| 75 |
description: |
| 76 |
- Adjust routing timers |
| 77 |
type: dict |
| 78 |
suboptions: |
| 79 |
holdtime: |
| 80 |
description: |
| 81 |
- Configures hold-time |
| 82 |
type: int |
| 83 |
keepalive_interval: |
| 84 |
description: |
| 85 |
- Configures keepalive-interval |
| 86 |
type: int |
| 87 |
graceful_restart: |
| 88 |
version_added: 3.1.0 |
| 89 |
description: |
| 90 |
- Configure graceful restart |
| 91 |
type: dict |
| 92 |
suboptions: |
| 93 |
enabled: |
| 94 |
description: |
| 95 |
- Enable graceful restart |
| 96 |
type: bool |
| 97 |
restart_time: |
| 98 |
description: |
| 99 |
- Configures restart-time. |
| 100 |
- The range is from 1 to 3600. |
| 101 |
type: int |
| 102 |
stale_routes_time: |
| 103 |
description: |
| 104 |
- Configures stale-routes-time. |
| 105 |
- The range is from 1 to 3600. |
| 106 |
type: int |
| 107 |
preserve_fw_state: |
| 108 |
description: |
| 109 |
- Configures preserve-fw-state |
| 110 |
type: bool |
| 111 |
bestpath: |
| 112 |
description: |
| 113 |
- Configures the BGP best-path. |
| 114 |
type: dict |
| 115 |
suboptions: |
| 116 |
as_path: |
| 117 |
description: |
| 118 |
- Configures the as-path values. |
| 119 |
type: dict |
| 120 |
suboptions: |
| 121 |
confed: |
| 122 |
description: |
| 123 |
- Configures the confed values of as-path. |
| 124 |
type: bool |
| 125 |
ignore: |
| 126 |
description: |
| 127 |
- Configures the ignore values of as-path. |
| 128 |
type: bool |
| 129 |
multipath_relax: |
| 130 |
description: |
| 131 |
- Configures the multipath_relax values of as-path. |
| 132 |
type: bool |
| 133 |
multipath_relax_as_set: |
| 134 |
description: |
| 135 |
- Configures the multipath_relax_as_set values of as-path. |
| 136 |
type: bool |
| 137 |
bandwidth: |
| 138 |
version_added: 3.1.0 |
| 139 |
description: |
| 140 |
- Link Bandwidth attribute for the bestpath selection process |
| 141 |
- Options are as follows |
| 142 |
- default_weight - Assign a low default weight (value 1) to paths not having link bandwidth |
| 143 |
- ignore_weight - Ignore link bandwidth (i.e., do regular ECMP, not weighted) |
| 144 |
- skip_missing - Ignore paths without link bandwidth for ECMP (if other paths have it) |
| 145 |
choices: ['default_weight', 'ignore_weight', 'skip_missing'] |
| 146 |
type: str |
| 147 |
compare_routerid: |
| 148 |
description: |
| 149 |
- Configures the compare_routerid. |
| 150 |
type: bool |
| 151 |
med: |
| 152 |
description: |
| 153 |
- Configures the med values. |
| 154 |
type: dict |
| 155 |
suboptions: |
| 156 |
confed: |
| 157 |
description: |
| 158 |
- Configures the confed values of med. |
| 159 |
type: bool |
| 160 |
missing_as_worst: |
| 161 |
description: |
| 162 |
- Configures the missing_as_worst values of as-path. |
| 163 |
type: bool |
| 164 |
always_compare_med: |
| 165 |
description: |
| 166 |
- Allows comparing meds from different neighbors if set to true |
| 167 |
type: bool |
| 168 |
rt_delay: |
| 169 |
description: |
| 170 |
- Time in seconds to wait before processing route-map changes. |
| 171 |
- Range is 0-600. 0 disables the timer and changes to route-map will not be updated. |
| 172 |
type: int |
| 173 |
state: |
| 174 |
description: |
| 175 |
- Specifies the operation to be performed on the BGP process that is configured on the device. |
| 176 |
- In case of merged, the input configuration is merged with the existing BGP configuration on the device. |
| 177 |
- In case of deleted, the existing BGP configuration is removed from the device. |
| 178 |
- In case of replaced, the existing configuration of the specified BGP AS will be replaced with provided configuration. |
| 179 |
- In case of overridden, the existing BGP configuration will be overridden with the provided configuration. |
| 180 |
default: merged |
| 181 |
choices: ['merged', 'deleted', 'replaced', 'overridden'] |
| 182 |
type: str |
| 183 |
""" |
| 184 |
|
| 185 |
EXAMPLES = """ |
| 186 |
# Using "deleted" state |
| 187 |
# |
| 188 |
# Before state: |
| 189 |
# ------------- |
| 190 |
# |
| 191 |
# ! |
| 192 |
# router bgp 10 vrf VrfCheck1 |
| 193 |
# router-id 10.2.2.32 |
| 194 |
# route-map delay-timer 20 |
| 195 |
# log-neighbor-changes |
| 196 |
# ! |
| 197 |
# router bgp 11 vrf VrfCheck2 |
| 198 |
# log-neighbor-changes |
| 199 |
# bestpath as-path ignore |
| 200 |
# bestpath med missing-as-worst confed |
| 201 |
# bestpath compare-routerid |
| 202 |
# ! |
| 203 |
# router bgp 4 |
| 204 |
# router-id 10.2.2.4 |
| 205 |
# graceful-restart enable |
| 206 |
# graceful-restart restart-time 1 |
| 207 |
# graceful-restart stalepath-time 500 |
| 208 |
# route-map delay-timer 10 |
| 209 |
# bestpath as-path ignore |
| 210 |
# bestpath as-path confed |
| 211 |
# bestpath med missing-as-worst confed |
| 212 |
# bestpath compare-routerid |
| 213 |
# bestpath bandwidth default-weight |
| 214 |
# ! |
| 215 |
# |
| 216 |
- name: Delete BGP Global attributes |
| 217 |
dellemc.enterprise_sonic.sonic_bgp: |
| 218 |
config: |
| 219 |
- bgp_as: 4 |
| 220 |
router_id: 10.2.2.4 |
| 221 |
rt_delay: 10 |
| 222 |
log_neighbor_changes: false |
| 223 |
graceful_restart: |
| 224 |
stale_routes_time: 500 |
| 225 |
restart_time: 1 |
| 226 |
bestpath: |
| 227 |
as_path: |
| 228 |
confed: true |
| 229 |
ignore: true |
| 230 |
multipath_relax: false |
| 231 |
multipath_relax_as_set: true |
| 232 |
bandwidth: default_weight |
| 233 |
compare_routerid: true |
| 234 |
med: |
| 235 |
confed: true |
| 236 |
missing_as_worst: true |
| 237 |
- bgp_as: 10 |
| 238 |
router_id: 10.2.2.32 |
| 239 |
rt_delay: 20 |
| 240 |
log_neighbor_changes: true |
| 241 |
vrf_name: 'VrfCheck1' |
| 242 |
- bgp_as: 11 |
| 243 |
log_neighbor_changes: true |
| 244 |
vrf_name: 'VrfCheck2' |
| 245 |
bestpath: |
| 246 |
as_path: |
| 247 |
confed: false |
| 248 |
ignore: true |
| 249 |
multipath_relax_as_set: true |
| 250 |
compare_routerid: true |
| 251 |
med: |
| 252 |
confed: true |
| 253 |
missing_as_worst: true |
| 254 |
state: deleted |
| 255 |
|
| 256 |
|
| 257 |
# After state: |
| 258 |
# ------------ |
| 259 |
# |
| 260 |
# ! |
| 261 |
# router bgp 10 vrf VrfCheck1 |
| 262 |
# log-neighbor-changes |
| 263 |
# ! |
| 264 |
# router bgp 11 vrf VrfCheck2 |
| 265 |
# log-neighbor-changes |
| 266 |
# bestpath compare-routerid |
| 267 |
# ! |
| 268 |
# router bgp 4 |
| 269 |
# graceful-restart enable |
| 270 |
# log-neighbor-changes |
| 271 |
# bestpath compare-routerid |
| 272 |
# ! |
| 273 |
|
| 274 |
|
| 275 |
# Using "deleted" state |
| 276 |
# |
| 277 |
# Before state: |
| 278 |
# ------------- |
| 279 |
# |
| 280 |
# ! |
| 281 |
# router bgp 10 vrf VrfCheck1 |
| 282 |
# router-id 10.2.2.32 |
| 283 |
# route-map delay-timer 20 |
| 284 |
# log-neighbor-changes |
| 285 |
# ! |
| 286 |
# router bgp 11 vrf VrfCheck2 |
| 287 |
# graceful-restart enable |
| 288 |
# log-neighbor-changes |
| 289 |
# bestpath as-path ignore |
| 290 |
# bestpath med missing-as-worst confed |
| 291 |
# bestpath compare-routerid |
| 292 |
# bestpath bandwidth ignore-weight |
| 293 |
# ! |
| 294 |
# router bgp 4 |
| 295 |
# router-id 10.2.2.4 |
| 296 |
# route-map delay-timer 10 |
| 297 |
# bestpath as-path ignore |
| 298 |
# bestpath as-path confed |
| 299 |
# bestpath med missing-as-worst confed |
| 300 |
# bestpath compare-routerid |
| 301 |
# ! |
| 302 |
|
| 303 |
- name: Deletes all the bgp global configurations |
| 304 |
dellemc.enterprise_sonic.sonic_bgp: |
| 305 |
config: |
| 306 |
state: deleted |
| 307 |
|
| 308 |
# After state: |
| 309 |
# ------------ |
| 310 |
# |
| 311 |
# ! |
| 312 |
# ! |
| 313 |
|
| 314 |
|
| 315 |
# Using "merged" state |
| 316 |
# |
| 317 |
# Before state: |
| 318 |
# ------------- |
| 319 |
# |
| 320 |
# ! |
| 321 |
# router bgp 4 |
| 322 |
# router-id 10.1.1.4 |
| 323 |
# ! |
| 324 |
# |
| 325 |
- name: Merges provided configuration with device configuration |
| 326 |
dellemc.enterprise_sonic.sonic_bgp: |
| 327 |
config: |
| 328 |
- bgp_as: 4 |
| 329 |
router_id: 10.2.2.4 |
| 330 |
rt_delay: 10 |
| 331 |
log_neighbor_changes: false |
| 332 |
graceful_restart: |
| 333 |
enabled: true |
| 334 |
preserve_fw_state: true |
| 335 |
timers: |
| 336 |
holdtime: 20 |
| 337 |
keepalive_interval: 30 |
| 338 |
bestpath: |
| 339 |
as_path: |
| 340 |
confed: true |
| 341 |
ignore: true |
| 342 |
multipath_relax: false |
| 343 |
multipath_relax_as_set: true |
| 344 |
bandwidth: ignore-weight |
| 345 |
compare_routerid: true |
| 346 |
med: |
| 347 |
confed: true |
| 348 |
missing_as_worst: true |
| 349 |
always_compare_med: true |
| 350 |
max_med: |
| 351 |
on_startup: |
| 352 |
timer: 667 |
| 353 |
med_val: 7878 |
| 354 |
- bgp_as: 10 |
| 355 |
router_id: 10.2.2.32 |
| 356 |
rt_delay: 20 |
| 357 |
log_neighbor_changes: true |
| 358 |
vrf_name: 'VrfCheck1' |
| 359 |
- bgp_as: 11 |
| 360 |
log_neighbor_changes: true |
| 361 |
vrf_name: 'VrfCheck2' |
| 362 |
bestpath: |
| 363 |
as_path: |
| 364 |
confed: false |
| 365 |
ignore: true |
| 366 |
multipath_relax_as_set: true |
| 367 |
compare_routerid: true |
| 368 |
med: |
| 369 |
confed: true |
| 370 |
missing_as_worst: true |
| 371 |
state: merged |
| 372 |
|
| 373 |
# |
| 374 |
# After state: |
| 375 |
# ------------ |
| 376 |
# |
| 377 |
# ! |
| 378 |
# router bgp 10 vrf VrfCheck1 |
| 379 |
# router-id 10.2.2.32 |
| 380 |
# route-map delay-timer 20 |
| 381 |
# log-neighbor-changes |
| 382 |
# ! |
| 383 |
# router bgp 11 vrf VrfCheck2 |
| 384 |
# log-neighbor-changes |
| 385 |
# bestpath as-path ignore |
| 386 |
# bestpath med missing-as-worst confed |
| 387 |
# bestpath compare-routerid |
| 388 |
# ! |
| 389 |
# router bgp 4 |
| 390 |
# router-id 10.2.2.4 |
| 391 |
# graceful-restart enable |
| 392 |
# graceful-restart preserve-fw-state |
| 393 |
# route-map delay-timer 10 |
| 394 |
# bestpath as-path ignore |
| 395 |
# bestpath as-path confed |
| 396 |
# bestpath med missing-as-worst confed |
| 397 |
# bestpath compare-routerid |
| 398 |
# bestpath bandwidth ignore-weight |
| 399 |
# always-compare-med |
| 400 |
# max-med on-startup 667 7878 |
| 401 |
# timers 20 30 |
| 402 |
# |
| 403 |
# ! |
| 404 |
|
| 405 |
|
| 406 |
# Using "replaced" state |
| 407 |
# |
| 408 |
# Before state: |
| 409 |
# ------------- |
| 410 |
# |
| 411 |
# ! |
| 412 |
# router bgp 10 vrf VrfCheck1 |
| 413 |
# router-id 10.2.2.32 |
| 414 |
# log-neighbor-changes |
| 415 |
# timers 60 180 |
| 416 |
# ! |
| 417 |
# router bgp 4 |
| 418 |
# router-id 10.2.2.4 |
| 419 |
# max-med on-startup 667 7878 |
| 420 |
# bestpath as-path ignore |
| 421 |
# bestpath as-path confed |
| 422 |
# bestpath med missing-as-worst confed |
| 423 |
# bestpath compare-routerid |
| 424 |
# bestpath bandwidth default-weight |
| 425 |
# timers 20 30 |
| 426 |
# ! |
| 427 |
# |
| 428 |
|
| 429 |
- name: Replace device configuration of specified BGP AS with provided |
| 430 |
dellemc.enterprise_sonic.sonic_bgp: |
| 431 |
config: |
| 432 |
- bgp_as: 4 |
| 433 |
router_id: 10.2.2.44 |
| 434 |
log_neighbor_changes: true |
| 435 |
bestpath: |
| 436 |
as_path: |
| 437 |
confed: true |
| 438 |
bandwidth: skip_missing |
| 439 |
compare_routerid: true |
| 440 |
- bgp_as: 11 |
| 441 |
vrf_name: 'VrfCheck2' |
| 442 |
router_id: 10.2.2.33 |
| 443 |
log_neighbor_changes: true |
| 444 |
bestpath: |
| 445 |
as_path: |
| 446 |
confed: true |
| 447 |
ignore: true |
| 448 |
compare_routerid: true |
| 449 |
med: |
| 450 |
confed: true |
| 451 |
missing_as_worst: true |
| 452 |
state: replaced |
| 453 |
|
| 454 |
# |
| 455 |
# After state: |
| 456 |
# ------------ |
| 457 |
# |
| 458 |
# ! |
| 459 |
# router bgp 10 vrf VrfCheck1 |
| 460 |
# router-id 10.2.2.32 |
| 461 |
# log-neighbor-changes |
| 462 |
# timers 60 180 |
| 463 |
# ! |
| 464 |
# router bgp 11 vrf VrfCheck2 |
| 465 |
# router-id 10.2.2.33 |
| 466 |
# log-neighbor-changes |
| 467 |
# bestpath as-path ignore |
| 468 |
# bestpath as-path confed |
| 469 |
# bestpath med missing-as-worst confed |
| 470 |
# bestpath compare-routerid |
| 471 |
# timers 60 180 |
| 472 |
# ! |
| 473 |
# router bgp 4 |
| 474 |
# router-id 10.2.2.44 |
| 475 |
# log-neighbor-changes |
| 476 |
# bestpath as-path confed |
| 477 |
# bestpath compare-routerid |
| 478 |
# bestpath bandwidth skip_missing |
| 479 |
# timers 60 180 |
| 480 |
# ! |
| 481 |
|
| 482 |
|
| 483 |
# Using "overridden" state |
| 484 |
# |
| 485 |
# Before state: |
| 486 |
# ------------- |
| 487 |
# |
| 488 |
# ! |
| 489 |
# router bgp 10 vrf VrfCheck1 |
| 490 |
# router-id 10.2.2.32 |
| 491 |
# log-neighbor-changes |
| 492 |
# timers 60 180 |
| 493 |
# ! |
| 494 |
# router bgp 4 |
| 495 |
# router-id 10.2.2.4 |
| 496 |
# max-med on-startup 667 7878 |
| 497 |
# bestpath as-path ignore |
| 498 |
# bestpath as-path confed |
| 499 |
# bestpath med missing-as-worst confed |
| 500 |
# bestpath compare-routerid |
| 501 |
# bestpath bandwidth default-weight |
| 502 |
# timers 20 30 |
| 503 |
# ! |
| 504 |
# |
| 505 |
|
| 506 |
- name: Override device configuration of global BGP with provided configuration |
| 507 |
dellemc.enterprise_sonic.sonic_bgp: |
| 508 |
config: |
| 509 |
- bgp_as: 4 |
| 510 |
router_id: 10.2.2.44 |
| 511 |
log_neighbor_changes: true |
| 512 |
bestpath: |
| 513 |
as_path: |
| 514 |
confed: true |
| 515 |
compare_routerid: true |
| 516 |
- bgp_as: 11 |
| 517 |
vrf_name: 'VrfCheck2' |
| 518 |
router_id: 10.2.2.33 |
| 519 |
log_neighbor_changes: true |
| 520 |
bestpath: |
| 521 |
as_path: |
| 522 |
confed: true |
| 523 |
ignore: true |
| 524 |
compare_routerid: true |
| 525 |
timers: |
| 526 |
holdtime: 90 |
| 527 |
keepalive_interval: 30 |
| 528 |
state: overridden |
| 529 |
|
| 530 |
# |
| 531 |
# After state: |
| 532 |
# ------------ |
| 533 |
# |
| 534 |
# ! |
| 535 |
# router bgp 11 vrf VrfCheck2 |
| 536 |
# router-id 10.2.2.33 |
| 537 |
# log-neighbor-changes |
| 538 |
# bestpath as-path ignore |
| 539 |
# bestpath as-path confed |
| 540 |
# bestpath compare-routerid |
| 541 |
# timers 30 90 |
| 542 |
# ! |
| 543 |
# router bgp 4 |
| 544 |
# router-id 10.2.2.44 |
| 545 |
# log-neighbor-changes |
| 546 |
# bestpath as-path confed |
| 547 |
# bestpath compare-routerid |
| 548 |
# timers 60 180 |
| 549 |
# ! |
| 550 |
""" |
| 551 |
|
| 552 |
RETURN = """ |
| 553 |
before: |
| 554 |
description: The configuration prior to the module invocation. |
| 555 |
returned: always |
| 556 |
type: list |
| 557 |
sample: > |
| 558 |
The configuration returned is always in the same format |
| 559 |
as the parameters above. |
| 560 |
after: |
| 561 |
description: The resulting configuration module invocation. |
| 562 |
returned: when changed |
| 563 |
type: list |
| 564 |
sample: > |
| 565 |
The configuration returned is always in the same format |
| 566 |
as the parameters above. |
| 567 |
commands: |
| 568 |
description: The set of commands pushed to the remote device. |
| 569 |
returned: always |
| 570 |
type: list |
| 571 |
sample: ['command 1', 'command 2', 'command 3'] |
| 572 |
""" |
| 573 |
|
| 574 |
|
| 575 |
from ansible.module_utils.basic import AnsibleModule |
| 576 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.bgp.bgp import BgpArgs |
| 577 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.bgp.bgp import Bgp |
| 578 |
|
| 579 |
|
| 580 |
def main(): |
| 581 |
""" |
| 582 |
Main entry point for module execution |
| 583 |
|
| 584 |
:returns: the result form module invocation |
| 585 |
""" |
| 586 |
module = AnsibleModule(argument_spec=BgpArgs.argument_spec, |
| 587 |
supports_check_mode=True) |
| 588 |
|
| 589 |
result = Bgp(module).execute_module() |
| 590 |
module.exit_json(**result) |
| 591 |
|
| 592 |
|
| 593 |
if __name__ == '__main__': |
| 594 |
main() |