Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_bgp_neighbors.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright 2025 Dell Inc. or its subsidiaries. All Rights Reserved.
4 # GNU General Public License v3.0+
5 # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 """
8 The module file for sonic_bgp_neighbors
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_bgp_neighbors
17 version_added: 1.0.0
18 notes:
19 - Tested against Enterprise SONiC Distribution by Dell Technologies.
20 - Supports C(check_mode).
21 short_description: Manage a BGP neighbor and its parameters
22 description:
23 - This module provides configuration management of global BGP_NEIGHBORS parameters on devices running Enterprise SONiC.
24 - bgp_as and vrf_name must be created on the device in advance.
25 author: Abirami N (@abirami-n)
26 options:
27 config:
28 description: Specifies the BGP neighbors related configuration.
29 type: list
30 elements: dict
31 suboptions:
32 bgp_as:
33 description:
34 - Specifies the BGP autonomous system (AS) number which is already configured on the device.
35 type: str
36 required: True
37 vrf_name:
38 description:
39 - Specifies the VRF name which is already configured on the device.
40 default: default
41 type: str
42 peer_group:
43 description: Specifies the list of peer groups.
44 type: list
45 elements: dict
46 suboptions:
47 name:
48 description: Name of the peer group.
49 type: str
50 required: True
51 remote_as:
52 description:
53 - Remote AS of the BGP peer group to configure.
54 - peer_as and peer_type are mutually exclusive.
55 type: dict
56 suboptions:
57 peer_as:
58 description:
59 - Specifies remote AS number.
60 - The range is from 1 to 4294967295.
61 type: str
62 peer_type:
63 description:
64 - Specifies the type of BGP peer.
65 type: str
66 choices:
67 - internal
68 - external
69 bfd:
70 description:
71 - Enables or disables BFD.
72 type: dict
73 suboptions:
74 enabled:
75 description:
76 - Enables BFD liveliness check for a BGP peer.
77 type: bool
78 check_failure:
79 description:
80 - Link dataplane status with control plane.
81 type: bool
82 profile:
83 description:
84 - BFD Profile name.
85 type: str
86 advertisement_interval:
87 description:
88 - Specifies the minimum interval between sending BGP routing updates.
89 - The range is from 0 to 600.
90 type: int
91 timers:
92 description:
93 - Specifies BGP peer group timer related configurations.
94 type: dict
95 suboptions:
96 keepalive:
97 description:
98 - Frequency with which the device sends keepalive messages to its peer, in seconds.
99 - The range is from 0 to 65535.
100 type: int
101 holdtime:
102 description:
103 - Interval after not receiving a keepalive message that Enterprise SONiC declares a peer dead, in seconds.
104 - The range is from 0 to 65535.
105 type: int
106 connect_retry:
107 description:
108 - Time interval in seconds between attempts to establish a session with the peer.
109 - The range is from 1 to 65535.
110 type: int
111 capability:
112 description:
113 - Specifies capability attributes to this peer group.
114 type: dict
115 suboptions:
116 dynamic:
117 description:
118 - Enables or disables dynamic capability to this peer group.
119 type: bool
120 extended_nexthop:
121 description:
122 - Enables or disables advertise extended next-hop capability to the peer.
123 type: bool
124 auth_pwd:
125 description:
126 - Configuration for peer group authentication password.
127 type: dict
128 suboptions:
129 pwd:
130 description:
131 - Authentication password for the peer group.
132 type: str
133 required: True
134 encrypted:
135 description:
136 - Indicates whether the password is encrypted text.
137 type: bool
138 default: False
139 pg_description:
140 description:
141 - A textual description of the peer group.
142 type: str
143 disable_connected_check:
144 description:
145 - Disables EBGP conntected route check.
146 type: bool
147 dont_negotiate_capability:
148 description:
149 - Disables capability negotiation.
150 type: bool
151 ebgp_multihop:
152 description:
153 - Allow EBGP peers not on directly connected networks.
154 type: dict
155 suboptions:
156 enabled:
157 description:
158 - Enables the referenced group or peers to be indirectly connected.
159 type: bool
160 default: False
161 multihop_ttl:
162 description:
163 - Time-to-live value to use when packets are sent to the referenced group or peers and ebgp-multihop is enabled.
164 type: int
165 enforce_first_as:
166 description:
167 - Enforces the first AS for EBGP routes.
168 type: bool
169 enforce_multihop:
170 description:
171 - Enforces EBGP multihop performance for peer.
172 type: bool
173 extended_link_bandwidth:
174 version_added: 3.1.0
175 description:
176 - Configure the Link Bandwidth extended community for a BGP peer.
177 type: bool
178 local_address:
179 description:
180 - Set the local IP address to use for the session when sending BGP update messages.
181 type: str
182 local_as:
183 description:
184 - Specifies local autonomous system number.
185 type: dict
186 suboptions:
187 as:
188 description:
189 - Local autonomous system number.
190 type: str
191 required: True
192 no_prepend:
193 description:
194 - Do not prepend the local-as number in AS-Path advertisements.
195 type: bool
196 replace_as:
197 description:
198 - Replace the configured AS Number with the local-as number in AS-Path advertisements.
199 type: bool
200 override_capability:
201 description:
202 - Override capability negotiation result.
203 type: bool
204 passive:
205 description:
206 - Do not send open messages to this peer.
207 - Default value while adding a new peergroup is C(False).
208 type: bool
209 shutdown_msg:
210 description:
211 - Add a shutdown message.
212 type: str
213 solo:
214 description:
215 - Indicates that routes advertised by the peer should not be reflected back to the peer.
216 type: bool
217 strict_capability_match:
218 description:
219 - Enables strict capability negotiation match.
220 type: bool
221 ttl_security:
222 description:
223 - Enforces only the peers that are specified number of hops away will be allowed to become peers.
224 type: int
225 address_family:
226 description:
227 - Holds of list of address families associated to the peergroup.
228 type: dict
229 suboptions:
230 afis:
231 description:
232 - List of address families with afi, safi, activate and allowas-in parameters.
233 - afi and safi are required together.
234 type: list
235 elements: dict
236 suboptions:
237 afi:
238 description:
239 - Holds afi mode.
240 type: str
241 required: True
242 choices:
243 - ipv4
244 - ipv6
245 - l2vpn
246 safi:
247 description:
248 - Holds safi mode.
249 type: str
250 choices:
251 - unicast
252 - evpn
253 activate:
254 description:
255 - Enable or disable activate.
256 type: bool
257 allowas_in:
258 description:
259 - Criterion for accepting received advertisements containing the AS number
260 - of this BGP router intance in the AS PATH of received advertisements.
261 - The 'origin' option can not be set to true when a 'value' is set.
262 type: dict
263 suboptions:
264 origin:
265 description:
266 - Accept this BGP router instance's set AS as the origin.
267 type: bool
268 value:
269 description:
270 - Accept up to this number of occurrences of this BGP router's
271 - set AS in the AS-PATH of received advertisements.
272 - (Specify a number in the range 1-10.)
273 type: int
274 ip_afi:
275 description:
276 - Common configuration attributes for IPv4 and IPv6 unicast address families.
277 type: dict
278 suboptions:
279 default_policy_name:
280 description:
281 - Specifies routing policy definition.
282 type: str
283 send_default_route:
284 description:
285 - Enable or disable sending of default-route to the peer.
286 type: bool
287 default: False
288 prefix_limit:
289 description:
290 - Specifies prefix limit attributes for ipv4-unicast and ipv6-unicast.
291 type: dict
292 suboptions:
293 max_prefixes:
294 description:
295 - Maximum number of prefixes that will be accepted from the peer.
296 type: int
297 prevent_teardown:
298 description:
299 - Enable or disable teardown of BGP session when maximum prefix limit is exceeded.
300 type: bool
301 default: False
302 warning_threshold:
303 description:
304 - Threshold on number of prefixes that can be received from a peer before generation of warning messages.
305 - Expressed as a percentage of max-prefixes.
306 type: int
307 restart_timer:
308 description:
309 - Time interval in seconds after which the BGP session is re-established after being torn down.
310 type: int
311 discard_extra:
312 description:
313 - Enable or disable discard extra of BGP session when maximum prefix limit is exceeded.
314 type: bool
315 default: False
316 prefix_list_in:
317 description:
318 - Inbound route filtering policy for a peer.
319 type: str
320 prefix_list_out:
321 description:
322 - Outbound route filtering policy for a peer.
323 type: str
324 neighbors:
325 description: Specifies BGP neighbor-related configurations.
326 type: list
327 elements: dict
328 suboptions:
329 neighbor:
330 description:
331 - Neighbor router address.
332 type: str
333 required: True
334 remote_as:
335 description:
336 - Remote AS of the BGP neighbor to configure.
337 - peer_as and peer_type are mutually exclusive.
338 type: dict
339 suboptions:
340 peer_as:
341 description:
342 - Specifies remote AS number.
343 - The range is from 1 to 4294967295.
344 type: str
345 peer_type:
346 description:
347 - Specifies the type of BGP peer.
348 type: str
349 choices:
350 - internal
351 - external
352 bfd:
353 description:
354 - Enables or disables BFD.
355 type: dict
356 suboptions:
357 enabled:
358 description:
359 - Enables BFD liveliness check for a BGP neighbor.
360 type: bool
361 check_failure:
362 description:
363 - Link dataplane status with control plane.
364 type: bool
365 profile:
366 description:
367 - BFD Profile name.
368 type: str
369 advertisement_interval:
370 description:
371 - Specifies the minimum interval between sending BGP routing updates.
372 - The range is from 0 to 600.
373 type: int
374 peer_group:
375 description:
376 - The name of the peer group that the neighbor is a member of.
377 type: str
378 timers:
379 description:
380 - Specifies BGP neighbor timer-related configurations.
381 type: dict
382 suboptions:
383 keepalive:
384 description:
385 - Frequency with which the device sends keepalive messages to its peer, in seconds.
386 - The range is from 0 to 65535.
387 type: int
388 holdtime:
389 description:
390 - Interval after not receiving a keepalive message that SONiC declares a peer dead, in seconds.
391 - The range is from 0 to 65535.
392 type: int
393 connect_retry:
394 description:
395 - Time interval in seconds between attempts to establish a session with the peer.
396 - The range is from 1 to 65535.
397 type: int
398 capability:
399 description:
400 - Specifies capability attributes to this neighbor.
401 type: dict
402 suboptions:
403 dynamic:
404 description:
405 - Enables or disables dynamic capability to this neighbor.
406 type: bool
407 extended_nexthop:
408 description:
409 - Enables or disables advertise extended next-hop capability to the peer.
410 type: bool
411 auth_pwd:
412 description:
413 - Configuration for neighbor group authentication password.
414 type: dict
415 suboptions:
416 pwd:
417 description:
418 - Authentication password for the neighbor group.
419 type: str
420 required: True
421 encrypted:
422 description:
423 - Indicates whether the password is encrypted text.
424 type: bool
425 default: False
426 nbr_description:
427 description:
428 - A textual description of the neighbor.
429 type: str
430 disable_connected_check:
431 description:
432 - Disables EBGP conntected route check.
433 type: bool
434 dont_negotiate_capability:
435 description:
436 - Disables capability negotiation.
437 type: bool
438 ebgp_multihop:
439 description:
440 - Allow EBGP neighbors not on directly connected networks.
441 type: dict
442 suboptions:
443 enabled:
444 description:
445 - Enables the referenced group or neighbors to be indirectly connected.
446 type: bool
447 default: False
448 multihop_ttl:
449 description:
450 - Time-to-live value to use when packets are sent to the referenced group or neighbors and ebgp-multihop is enabled.
451 type: int
452 enforce_first_as:
453 description:
454 - Enforces the first AS for EBGP routes.
455 type: bool
456 enforce_multihop:
457 description:
458 - Enforces EBGP multihop performance for neighbor.
459 type: bool
460 extended_link_bandwidth:
461 version_added: 3.1.0
462 description:
463 - Configure the Link Bandwidth extended community for a BGP neighbor.
464 type: bool
465 local_address:
466 description:
467 - Set the local IP address to use for the session when sending BGP update messages.
468 type: str
469 local_as:
470 description:
471 - Specifies local autonomous system number.
472 type: dict
473 suboptions:
474 as:
475 description:
476 - Local autonomous system number.
477 type: str
478 required: True
479 no_prepend:
480 description:
481 - Do not prepend the local-as number in AS-Path advertisements.
482 type: bool
483 replace_as:
484 description:
485 - Replace the configured AS Number with the local-as number in AS-Path advertisements.
486 type: bool
487 override_capability:
488 description:
489 - Override capability negotiation result.
490 type: bool
491 passive:
492 description:
493 - Do not send open messages to this neighbor.
494 - Default value while adding a new neighbor is C(False).
495 type: bool
496 port:
497 description:
498 - Neighbor's BGP port.
499 type: int
500 shutdown_msg:
501 description:
502 - Add a shutdown message.
503 type: str
504 solo:
505 description:
506 - Indicates that routes advertised by the peer should not be reflected back to the peer.
507 type: bool
508 strict_capability_match:
509 description:
510 - Enables strict capability negotiation match.
511 type: bool
512 ttl_security:
513 description:
514 - Enforces only the neighbors that are specified number of hops away will be allowed to become neighbors.
515 type: int
516 v6only:
517 description:
518 - Enables BGP with v6 link-local only.
519 type: bool
520
521 state:
522 description:
523 - Specifies the operation to be performed on the BGP process that is configured on the device.
524 - In case of merged, the input configuration is merged with the existing BGP configuration on the device.
525 - In case of deleted, the existing BGP configuration is removed from the device.
526 - In case of replaced, the existing BGP configuration will be replaced with the input BGP configuration on the device.
527 - In case of overridden, the existing BGP configuration will be overriden with the input BGP configuration on the device.
528 default: merged
529 type: str
530 choices:
531 - merged
532 - deleted
533 - replaced
534 - overridden
535 """
536
537 EXAMPLES = """
538 # Using "deleted" state
539 #
540 # Before state:
541 # -------------
542 # router bgp 11 vrf VrfCheck2
543 # network import-check
544 # timers 60 180
545 # !
546 # router bgp 51 vrf VrfReg1
547 # network import-check
548 # timers 60 180
549 # !
550 # neighbor interface Eth1/3
551 # !
552 # router bgp 11
553 # network import-check
554 # timers 60 180
555 # !
556 # neighbor 192.168.1.4
557 # !
558 # peer-group SP1
559 # timers connect 30
560 # advertisement-interval 0
561 # bfd
562 # capability dynamic
563 # !
564 # peer-group SP2
565 # timers connect 30
566 # advertisement-interval 0
567 # !
568 #
569
570 - name: Deletes all BGP neighbors
571 dellemc.enterprise_sonic.sonic_bgp_neighbors:
572 config:
573 state: deleted
574
575 #
576 # After state:
577 # -------------
578 # router bgp 11 vrf VrfCheck2
579 # network import-check
580 # timers 60 180
581 # !
582 # router bgp 51 vrf VrfReg1
583 # network import-check
584 # timers 60 180
585 # !
586 # router bgp 11
587 # network import-check
588 # timers 60 180
589 # !
590 #
591
592 # Using "merged" state
593 #
594 # Before state:
595 # ------------
596 # router bgp 11 vrf VrfCheck2
597 # network import-check
598 # timers 60 180
599 # !
600 # router bgp 51 vrf VrfReg1
601 # network import-check
602 # timers 60 180
603 # !
604 # router bgp 11
605 # network import-check
606 # timers 60 180
607 # !
608
609 - name: "Adds sonic_bgp_neighbors"
610 dellemc.enterprise_sonic.sonic_bgp_neighbors:
611 config:
612 - bgp_as: 51
613 neighbors:
614 - neighbor: Eth1/2
615 auth_pwd:
616 pwd: 'pw123'
617 encrypted: false
618 dont_negotiate_capability: true
619 ebgp_multihop:
620 enabled: true
621 multihop_ttl: 1
622 enforce_first_as: true
623 enforce_multihop: true
624 local_address: 'Ethernet4'
625 local_as:
626 as: 2
627 no_prepend: true
628 replace_as: true
629 nbr_description: "description 1"
630 override_capability: true
631 passive: true
632 port: 3
633 shutdown_msg: 'msg1'
634 solo: true
635 - neighbor: 1.1.1.1
636 disable_connected_check: true
637 ttl_security: 5
638 - bgp_as: 51
639 vrf_name: VrfReg1
640 peer_group:
641 - name: SPINE
642 bfd:
643 check_failure: true
644 enabled: true
645 profile: 'profile 1'
646 capability:
647 dynamic: true
648 extended_nexthop: true
649 auth_pwd:
650 pwd: 'U2FsdGVkX1/4sRsZ624wbAJfDmagPLq2LsGDOcW/47M='
651 encrypted: true
652 dont_negotiate_capability: true
653 ebgp_multihop:
654 enabled: true
655 multihop_ttl: 1
656 enforce_first_as: true
657 enforce_multihop: true
658 extended_link_bandwidth: true
659 local_address: 'Ethernet4'
660 local_as:
661 as: 2
662 no_prepend: true
663 replace_as: true
664 pg_description: 'description 1'
665 override_capability: true
666 passive: true
667 solo: true
668 remote_as:
669 peer_as: 4
670 - name: SPINE1
671 disable_connected_check: true
672 shutdown_msg: "msg1"
673 strict_capability_match: true
674 timers:
675 keepalive: 30
676 holdtime: 15
677 connect_retry: 25
678 ttl_security: 5
679 address_family:
680 afis:
681 - afi: ipv4
682 safi: unicast
683 activate: true
684 allowas_in:
685 origin: true
686 - afi: ipv6
687 safi: unicast
688 activate: true
689 allowas_in:
690 value: 5
691 neighbors:
692 - neighbor: Eth1/3
693 remote_as:
694 peer_as: 10
695 peer_group: SPINE
696 advertisement_interval: 15
697 extended_link_bandwidth: true
698 timers:
699 keepalive: 30
700 holdtime: 15
701 connect_retry: 25
702 bfd:
703 check_failure: true
704 enabled: true
705 profile: 'profile 1'
706 capability:
707 dynamic: true
708 extended_nexthop: true
709 auth_pwd:
710 pwd: 'U2FsdGVkX199MZ7YOPkOR9O6wEZmtGSgiDfnlcN9hBg='
711 encrypted: true
712 nbr_description: 'description 2'
713 strict_capability_match: true
714 v6only: true
715 - neighbor: 192.168.1.4
716 state: merged
717
718 #
719 # After state:
720 # ------------
721 # !
722 # router bgp 11 vrf VrfCheck2
723 # network import-check
724 # timers 60 180
725 # !
726 # router bgp 51 vrf VrfReg1
727 # network import-check
728 # timers 60 180
729 # !
730 # peer-group SPINE1
731 # timers 15 30
732 # timers connect 25
733 # advertisement-interval 0
734 # shutdown message msg1
735 # disable-connected-check
736 # strict-capability-match
737 # ttl-security hops 5
738 # !
739 # peer-group SPINE
740 # description "description 1"
741 # ebgp-multihop 1
742 # remote-as 4
743 # timers connect 30
744 # advertisement-interval 0
745 # bfd check-control-plane-failure profile "profile 1"
746 # update-source interface Ethernet4
747 # capability dynamic
748 # capability extended-nexthop
749 # dont-capability-negotiate
750 # enforce-first-as
751 # enforce-multihop
752 # extended-link-bandwidth
753 # local-as 2 no-prepend replace-as
754 # override-capability
755 # passive
756 # password U2FsdGVkX1/4sRsZ624wbAJfDmagPLq2LsGDOcW/47M= encrypted
757 # solo
758 # address-family ipv4 unicast
759 # activate
760 # allowas-in origin
761 # send-community both
762 # !
763 # address-family ipv6 unicast
764 # activate
765 # allowas-in 5
766 # send-community both
767 # !
768 # neighbor interface Eth1/3
769 # description "description 2"
770 # peer-group SPINE
771 # remote-as 10
772 # timers 15 30
773 # timers connect 25
774 # bfd check-control-plane-failure profile "profile 1"
775 # advertisement-interval 15
776 # capability extended-nexthop
777 # capability dynamic
778 # extended-link-bandwidth
779 # v6only
780 # password U2FsdGVkX199MZ7YOPkOR9O6wEZmtGSgiDfnlcN9hBg= encrypted
781 # strict-capability-match
782 # !
783 # neighbor 192.168.1.4
784 # !
785 # router bgp 51
786 # network import-check
787 # timers 60 180
788 # !
789 # neighbor interface Eth1/2
790 # description "description 1"
791 # shutdown message msg1
792 # ebgp-multihop 1
793 # remote-as external
794 # update-source interface Ethernet4
795 # dont-capability-negotiate
796 # enforce-first-as
797 # enforce-multihop
798 # local-as 2 no-prepend replace-as
799 # override-capability
800 # passive
801 # password U2FsdGVkX1+bxMf9TKOhaXRNNaHmywiEVDF2lJ2c000= encrypted
802 # port 3
803 # solo
804 # neighbor 1.1.1.1
805 # disable-connected-check
806 # ttl-security hops 5
807 # router bgp 11
808 # network import-check
809 # timers 60 180
810 #
811
812 # Using "deleted" state
813 #
814 # Before state:
815 # ------------
816 # !
817 # router bgp 11 vrf VrfCheck2
818 # network import-check
819 # timers 60 180
820 # !
821 # router bgp 51 vrf VrfReg1
822 # network import-check
823 # timers 60 180
824 # !
825 # peer-group SPINE
826 # bfd
827 # remote-as 4
828 # timers connect 30
829 # advertisement-interval 0
830 # !
831 # neighbor interface Eth1/3
832 # peer-group SPINE
833 # remote-as 10
834 # timers 15 30
835 # advertisement-interval 15
836 # bfd
837 # capability extended-nexthop
838 # capability dynamic
839 # !
840 # neighbor 192.168.1.4
841 # !
842 # router bgp 11
843 # network import-check
844 # timers 60 180
845 # !
846 # peer-group SP
847 # timers connect 30
848 # advertisement-interval 0
849 # !
850 # neighbor interface Eth1/3
851 #
852
853 - name: "Deletes sonic_bgp_neighbors and peer-groups specific to vrfname"
854 dellemc.enterprise_sonic.sonic_bgp_neighbors:
855 config:
856 - bgp_as: 51
857 vrf_name: VrfReg1
858 state: deleted
859
860 # After state:
861 # ------------
862 # !
863 # router bgp 11 vrf VrfCheck2
864 # network import-check
865 # timers 60 180
866 # !
867 # router bgp 51 vrf VrfReg1
868 # network import-check
869 # timers 60 180
870 # !
871 # router bgp 11
872 # network import-check
873 # timers 60 180
874 # !
875 # peer-group SP
876 # timers connect 30
877 # advertisement-interval 0
878 # !
879 # neighbor interface Eth1/3
880 #
881
882 # Using "deleted" state
883 #
884 # Before state:
885 # -------------
886 #
887 # router bgp 51 vrf VrfReg1
888 # network import-check
889 # timers 60 180
890 # !
891 # peer-group SPINE
892 # bfd
893 # remote-as 4
894 # timers connect 30
895 # advertisement-interval 0
896 # !
897 # neighbor interface Eth1/3
898 # peer-group SPINE
899 # remote-as 10
900 # timers 15 30
901 # advertisement-interval 15
902 # bfd
903 # capability extended-nexthop
904 # capability dynamic
905 # extended-link-bandwidth
906 # !
907 # neighbor 192.168.1.4
908 # !
909
910 - name: "Deletes specific sonic_bgp_neighbors"
911 dellemc.enterprise_sonic.sonic_bgp_neighbors:
912 config:
913 - bgp_as: 51
914 neighbors:
915 - neighbor: Eth1/2
916 auth_pwd:
917 pwd: 'pw123'
918 encrypted: false
919 dont_negotiate_capability: true
920 ebgp_multihop:
921 enabled: true
922 multihop_ttl: 1
923 enforce_first_as: true
924 enforce_multihop: true
925 local_address: 'Ethernet4'
926 local_as:
927 as: 2
928 no_prepend: true
929 replace_as: true
930 nbr_description: 'description 1'
931 override_capability: true
932 passive: true
933 port: 3
934 shutdown_msg: 'msg1'
935 solo: true
936 - neighbor: 1.1.1.1
937 disable_connected_check: true
938 ttl_security: 5
939 - bgp_as: 51
940 vrf_name: VrfReg1
941 peer_group:
942 - name: SPINE
943 bfd:
944 check_failure: true
945 enabled: true
946 profile: 'profile 1'
947 capability:
948 dynamic: true
949 extended_nexthop: true
950 auth_pwd:
951 pwd: 'U2FsdGVkX1/4sRsZ624wbAJfDmagPLq2LsGDOcW/47M='
952 encrypted: true
953 dont_negotiate_capability: true
954 ebgp_multihop:
955 enabled: true
956 multihop_ttl: 1
957 enforce_first_as: true
958 enforce_multihop: true
959 local_address: 'Ethernet4'
960 local_as:
961 as: 2
962 no_prepend: true
963 replace_as: true
964 pg_description: 'description 1'
965 override_capability: true
966 passive: true
967 solo: true
968 remote_as:
969 peer_as: 4
970 - name: SPINE1
971 disable_connected_check: true
972 shutdown_msg: "msg1"
973 strict_capability_match: true
974 timers:
975 keepalive: 30
976 holdtime: 15
977 connect_retry: 25
978 ttl_security: 5
979 neighbors:
980 - neighbor: Eth1/3
981 remote_as:
982 peer_as: 10
983 peer_group: SPINE
984 advertisement_interval: 15
985 timers:
986 keepalive: 30
987 holdtime: 15
988 connect_retry: 25
989 bfd:
990 check_failure: true
991 enabled: true
992 profile: 'profile 1'
993 capability:
994 dynamic: true
995 extended_nexthop: true
996 auth_pwd:
997 pwd: 'U2FsdGVkX199MZ7YOPkOR9O6wEZmtGSgiDfnlcN9hBg='
998 encrypted: true
999 extended_link_bandwidth: true
1000 nbr_description: 'description 2'
1001 strict_capability_match: true
1002 v6only: true
1003 - neighbor: 192.168.1.4
1004 state: deleted
1005
1006 #
1007 # After state:
1008 # -------------
1009 #
1010 # router bgp 51 vrf VrfReg1
1011 # network import-check
1012 # timers 60 180
1013 # !
1014 # peer-group SPINE1
1015 # timers connect 30
1016 # advertisement-interval 0
1017 # !
1018 # peer-group SPINE
1019 # timers connect 30
1020 # advertisement-interval 0
1021 # !
1022 # neighbor interface Eth1/3
1023 # !
1024 # neighbor interface Eth1/2
1025 # !
1026 # neighbor 1.1.1.1
1027 #
1028
1029 # Using "merged" state
1030 #
1031 # Before state:
1032 # -------------
1033 #
1034 # sonic# show running-configuration bgp peer-group vrf default
1035 # (No bgp peer-group configuration present)
1036
1037 - name: "Configure BGP peer-group prefix-list attributes"
1038 dellemc.enterprise_sonic.sonic_bgp_neighbors:
1039 config:
1040 - bgp_as: 51
1041 peer_group:
1042 - name: SPINE
1043 address_family:
1044 afis:
1045 - afi: ipv4
1046 safi: unicast
1047 ip_afi:
1048 default_policy_name: rmap_reg1
1049 send_default_route: true
1050 prefix_limit:
1051 max_prefixes: 1
1052 prevent_teardown: true
1053 warning_threshold: 80
1054 prefix_list_in: p1
1055 prefix_list_out: p2
1056 state: merged
1057
1058 # After state:
1059 # ------------
1060 #
1061 # sonic# show running-configuration bgp peer-group vrf default
1062 # !
1063 # peer-group SPINE
1064 # timers connect 30
1065 # advertisement-interval 0
1066 # !
1067 # address-family ipv4 unicast
1068 # default-originate route-map rmap_reg1
1069 # prefix-list p1 in
1070 # prefix-list p2 out
1071 # send-community both
1072 # maximum-prefix 1 80 warning-only
1073 #
1074
1075 # Using "merged" state
1076 #
1077 # Before state:
1078 # -------------
1079 #
1080 # sonic# show running-configuration bgp peer-group vrf default
1081 # (No bgp peer-group configuration present)
1082
1083 - name: "Configure BGP peer-group prefix-list attributes"
1084 dellemc.enterprise_sonic.sonic_bgp_neighbors:
1085 config:
1086 - bgp_as: 51
1087 peer_group:
1088 - name: SPINE
1089 address_family:
1090 afis:
1091 - afi: ipv4
1092 safi: unicast
1093 ip_afi:
1094 default_policy_name: rmap_reg1
1095 send_default_route: true
1096 prefix_limit:
1097 max_prefixes: 2
1098 discard_extra: true
1099 warning_threshold: 86
1100 prefix_list_in: p1
1101 prefix_list_out: p2
1102 state: merged
1103
1104 # After state:
1105 # ------------
1106 #
1107 # sonic# show running-configuration bgp peer-group vrf default
1108 # !
1109 # peer-group SPINE
1110 # timers connect 30
1111 # advertisement-interval 0
1112 # !
1113 # address-family ipv4 unicast
1114 # default-originate route-map rmap_reg1
1115 # prefix-list p1 in
1116 # prefix-list p2 out
1117 # send-community both
1118 # maximum-prefix 2 86 discard-extra
1119 #
1120
1121 # Using "deleted" state
1122 #
1123 # Before state:
1124 # -------------
1125 #
1126 # sonic# show running-configuration bgp peer-group vrf default
1127 # !
1128 # peer-group SPINE
1129 # timers connect 30
1130 # advertisement-interval 0
1131 # !
1132 # address-family ipv6 unicast
1133 # default-originate route-map rmap_reg2
1134 # prefix-list p1 in
1135 # prefix-list p2 out
1136 # send-community both
1137 # maximum-prefix 5 90 restart 2
1138
1139 - name: "Delete BGP peer-group prefix-list attributes"
1140 dellemc.enterprise_sonic.sonic_bgp_neighbors:
1141 config:
1142 - bgp_as: 51
1143 peer_group:
1144 - name: SPINE
1145 address_family:
1146 afis:
1147 - afi: ipv6
1148 safi: unicast
1149 ip_afi:
1150 default_policy_name: rmap_reg2
1151 send_default_route: true
1152 prefix_limit:
1153 max_prefixes: 5
1154 warning_threshold: 90
1155 restart-timer: 2
1156 prefix_list_in: p1
1157 prefix_list_out: p2
1158 state: deleted
1159
1160 # After state:
1161 # ------------
1162 #
1163 # sonic# show running-configuration bgp peer-group vrf default
1164 # !
1165 # peer-group SPINE
1166 # timers connect 30
1167 # advertisement-interval 0
1168 # !
1169 # address-family ipv6 unicast
1170 # send-community both
1171 # !
1172
1173 #
1174 # Using "replaced" state
1175 #
1176 # Before state:
1177 # ------------
1178 # !
1179 # router bgp 51 vrf VrfCheck2
1180 # network import-check
1181 # timers 60 180
1182 # !
1183 # router bgp 51 vrf VrfReg1
1184 # network import-check
1185 # timers 60 180
1186 # !
1187 # peer-group SPINE3
1188 # bfd
1189 # remote-as 4
1190 # timers connect 30
1191 # advertisement-interval 0
1192 # !
1193 # neighbor interface Eth1/3
1194 # remote-as 10
1195 # timers 15 30
1196 # advertisement-interval 15
1197 # bfd
1198 # capability extended-nexthop
1199 # capability dynamic
1200 # !
1201 # neighbor 192.168.1.4
1202 # !
1203 # router bgp 51
1204 # network import-check
1205 # timers 60 18
1206 # !
1207 # peer-group SP
1208 # timers connect 30
1209 # advertisement-interval 0
1210 # !
1211 # neighbor interface Eth1/3
1212 #
1213
1214 - name: "Replaces peer-groups specific to vrfname"
1215 dellemc.enterprise_sonic.sonic_bgp_neighbors:
1216 config:
1217 - bgp_as: 51
1218 vrf_name: VrfReg1
1219 peer_group:
1220 - name: SPINE3
1221 remote_as:
1222 peer_type: internal
1223 - name: SPINE4
1224 address_family:
1225 afis:
1226 - afi: ipv4
1227 safi: unicast
1228 allowas_in:
1229 origin: true
1230 state: replaced
1231
1232 # After state:
1233 # ------------
1234 # !
1235 # router bgp 51 vrf VrfCheck2
1236 # network import-check
1237 # timers 60 180
1238 # !
1239 # router bgp 51 vrf VrfReg1
1240 # network import-check
1241 # timers 60 180
1242 # !
1243 # peer-group SPINE3
1244 # remote-as internal
1245 # timers connect 30
1246 # advertisement-interval 0
1247 # !
1248 # peer-group SPINE4
1249 # timers connect 30
1250 # advertisement-interval 0
1251 # !
1252 # address-family ipv4 unicast
1253 # allowas-in origin
1254 # send-community both
1255 # !
1256 # neighbor interface Eth1/3
1257 # remote-as 10
1258 # timers 15 30
1259 # advertisement-interval 15
1260 # bfd
1261 # capability extended-nexthop
1262 # capability dynamic
1263 # !
1264 # neighbor 192.168.1.4
1265 # !
1266 # router bgp 51
1267 # network import-check
1268 # timers 60 18
1269 # !
1270 # peer-group SP
1271 # timers connect 30
1272 # advertisement-interval 0
1273 # !
1274 # neighbor interface Eth1/3
1275 #
1276 #
1277
1278 # Using "replaced" state
1279 #
1280 # Before state:
1281 # ------------
1282 # !
1283 # router bgp 51 vrf VrfCheck2
1284 # network import-check
1285 # timers 60 180
1286 # !
1287 # router bgp 51 vrf VrfReg1
1288 # network import-check
1289 # timers 60 180
1290 # !
1291 # peer-group SPINE
1292 # bfd
1293 # remote-as 4
1294 # timers connect 30
1295 # advertisement-interval 0
1296 # extended-link-bandwidth
1297 # !
1298 # neighbor 192.168.1.1
1299 # peer-group SPINE
1300 # remote-as 10
1301 # timers 15 30
1302 # advertisement-interval 15
1303 # bfd
1304 # capability extended-nexthop
1305 # capability dynamic
1306 # !
1307 # neighbor 192.168.1.4
1308 # !
1309 # router bgp 51
1310 # network import-check
1311 # timers 60 18
1312 # !
1313 # peer-group SP
1314 # timers connect 30
1315 # advertisement-interval 0
1316 # !
1317 # neighbor interface Eth1/3
1318 #
1319
1320 - name: "Replaces sonic_bgp_neighbors specific to vrfname"
1321 dellemc.enterprise_sonic.sonic_bgp_neighbors:
1322 config:
1323 - bgp_as: 51
1324 vrf_name: VrfReg1
1325 neighbors:
1326 - neighbor: 192.168.1.1
1327 bfd:
1328 enabled: true
1329 capability:
1330 extended_nexthop: true
1331 dynamic: true
1332 state: replaced
1333
1334 # After state:
1335 # ------------
1336 # !
1337 # router bgp 51 vrf VrfCheck2
1338 # network import-check
1339 # timers 60 180
1340 # !
1341 # router bgp 51 vrf VrfReg1
1342 # network import-check
1343 # timers 60 180
1344 # !
1345 # peer-group SPINE
1346 # bfd
1347 # remote-as 4
1348 # timers connect 30
1349 # advertisement-interval 0
1350 # extended-link-bandwidth
1351 # !
1352 # neighbor 192.168.1.1
1353 # bfd
1354 # capability extended-nexthop
1355 # capability dynamic
1356 # !
1357 # neighbor 192.168.1.4
1358 # !
1359 # router bgp 51
1360 # network import-check
1361 # timers 60 18
1362 # !
1363 # peer-group SP
1364 # timers connect 30
1365 # advertisement-interval 0
1366 # !
1367 # neighbor interface Eth1/3
1368 #
1369
1370 # Using "overridden" state
1371 #
1372 # Before state:
1373 # ------------
1374 # !
1375 # router bgp 51 vrf VrfCheck2
1376 # network import-check
1377 # timers 60 180
1378 # !
1379 # router bgp 51 vrf VrfReg1
1380 # network import-check
1381 # timers 60 180
1382 # !
1383 # peer-group SPINE
1384 # bfd
1385 # remote-as 4
1386 # timers connect 30
1387 # advertisement-interval 0
1388 # !
1389 # neighbor interface Eth1/3
1390 # peer-group SPINE
1391 # remote-as 10
1392 # timers 15 30
1393 # advertisement-interval 15
1394 # bfd
1395 # capability extended-nexthop
1396 # capability dynamic
1397 # !
1398 # neighbor 192.168.1.4
1399 # !
1400 # router bgp 51
1401 # network import-check
1402 # timers 60 18
1403 # !
1404 # peer-group SP
1405 # timers connect 30
1406 # advertisement-interval 0
1407 # !
1408 # neighbor interface Eth1/3
1409 #
1410
1411 - name: "Override sonic_bgp_neighbors and peer-groups specific to vrfname"
1412 dellemc.enterprise_sonic.sonic_bgp_neighbors:
1413 config:
1414 - bgp_as: 51
1415 vrf_name: VrfReg1
1416 peer_group:
1417 - name: SPINE3
1418 remote_as:
1419 peer_type: internal
1420 - name: SPINE4
1421 address_family:
1422 afis:
1423 - afi: ipv4
1424 safi: unicast
1425 allowas_in:
1426 origin: true
1427 state: overridden
1428
1429 # After state:
1430 # ------------
1431 # !
1432 # router bgp 51 vrf VrfReg1
1433 # network import-check
1434 # timers 60 180
1435 # !
1436 # peer-group SPINE3
1437 # remote-as internal
1438 # timers connect 30
1439 # advertisement-interval 0
1440 # !
1441 # peer-group SPINE4
1442 # timers connect 30
1443 # advertisement-interval 0
1444 # !
1445 # address-family ipv4 unicast
1446 # allowas-in origin
1447 # send-community both
1448 # !
1449 #
1450 """
1451
1452 RETURN = """
1453 before:
1454 description: The configuration prior to the module invocation.
1455 returned: always
1456 type: list
1457 sample: >
1458 The configuration returned is always in the same format
1459 as the parameters above.
1460 after:
1461 description: The resulting configuration module invocation.
1462 returned: when changed
1463 type: list
1464 sample: >
1465 The configuration returned is always in the same format
1466 as the parameters above.
1467 after_generated:
1468 description: The generated configuration module invocation.
1469 returned: when C(check_mode)
1470 type: list
1471 sample: >
1472 The configuration returned will always be in the same format
1473 as the parameters above.
1474 commands:
1475 description: The set of commands pushed to the remote device.
1476 returned: always
1477 type: list
1478 sample: ['command 1', 'command 2', 'command 3']
1479 """
1480
1481
1482 from ansible.module_utils.basic import AnsibleModule
1483 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.bgp_neighbors.bgp_neighbors import Bgp_neighborsArgs
1484 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.bgp_neighbors.bgp_neighbors import Bgp_neighbors
1485
1486
1487 def main():
1488 """
1489 Main entry point for module execution
1490
1491 :returns: the result form module invocation
1492 """
1493 module = AnsibleModule(argument_spec=Bgp_neighborsArgs.argument_spec,
1494 supports_check_mode=True)
1495
1496 result = Bgp_neighbors(module).execute_module()
1497 module.exit_json(**result)
1498
1499
1500 if __name__ == '__main__':
1501 main()