diff --git a/changelogs/fragments/bgp_address_family.yaml b/changelogs/fragments/bgp_address_family.yaml new file mode 100644 index 00000000..266c3d81 --- /dev/null +++ b/changelogs/fragments/bgp_address_family.yaml @@ -0,0 +1,12 @@ +--- +major_changes: + - Aligned with version 1.3+ configuration - aggregate_address, maximum_paths, network, and redistribute + moved from `bgp_global` module. These are now Address-family specific. + - Many neighbor attributes also moved from `bgp_global` to `bgp_address_family` module. + - Redistribute, network stanza - added support for modifiers (metric, backdoor etc as per T6829) + - Support for 1.3+ VyOS only + +minor_changes: + - as_number - Added support for 1.4+ "system-as. 1.3 embedded as_number is still supported" + - fix tests for 1.4+ bgp_address_family + - updated documentation diff --git a/changelogs/fragments/bgp_global.yaml b/changelogs/fragments/bgp_global.yaml new file mode 100644 index 00000000..e528ab39 --- /dev/null +++ b/changelogs/fragments/bgp_global.yaml @@ -0,0 +1,10 @@ +--- +minor_changes: + - Added support for `solo` neighbor attribute + - as_number - Added support for 1.4+ "system-as. 1.3 embedded as_number is still supported" + - Fixed tests for 1.4+ bgp_global + - updated documentation + - Aligned with version 1.3+ configuration - aggregate_address, maximum_paths, network, and redistribute + Removed to `bgp_address_family` module. + - Many configuration attributes moved from `bgp_global` to `bgp_address_family` module. + - Support for 1.3+ VyOS only diff --git a/docs/vyos.vyos.vyos_bgp_address_family_module.rst b/docs/vyos.vyos.vyos_bgp_address_family_module.rst index ec4a6398..e17dfdd7 100644 --- a/docs/vyos.vyos.vyos_bgp_address_family_module.rst +++ b/docs/vyos.vyos.vyos_bgp_address_family_module.rst @@ -1,2202 +1,2203 @@ .. _vyos.vyos.vyos_bgp_address_family_module: ********************************* vyos.vyos.vyos_bgp_address_family ********************************* **BGP Address Family resource module** Version added: 1.0.0 .. contents:: :local: :depth: 1 Synopsis -------- - This module manages BGP address family configuration of interfaces on devices running VYOS. +- Tested against VYOS 1.3, 1.4 Parameters ---------- .. raw:: html
Parameter Choices/Defaults Comments
config
dictionary
A dict of BGP global configuration for interfaces.
address_family
list / elements=dictionary
BGP address-family parameters.
afi
string
    Choices:
  • ipv4
  • ipv6
BGP address family settings.
aggregate_address
list / elements=dictionary
BGP aggregate network.
as_set
boolean
    Choices:
  • no
  • yes
Generate AS-set path information for this aggregate address.
prefix
string
BGP aggregate network.
summary_only
boolean
    Choices:
  • no
  • yes
Announce the aggregate summary network only.
networks
list / elements=dictionary
BGP network
backdoor
boolean
    Choices:
  • no
  • yes
Network as a backdoor route.
path_limit
integer
AS path hop count limit
prefix
string
BGP network address
route_map
string
Route-map to modify route attributes
redistribute
list / elements=dictionary
Redistribute routes from other protocols into BGP
metric
integer
Metric for redistributed routes.
protocol
string
    Choices:
  • connected
  • kernel
  • ospf
  • ospfv3
  • rip
  • ripng
  • static
types of routes to be redistributed.
route_map
string
Route map to filter redistributed routes
table
string
Redistribute non-main Kernel Routing Table.
as_number
integer
AS number
neighbors
list / elements=dictionary
BGP neighbor
address_family
list / elements=dictionary
address family.
afi
string
    Choices:
  • ipv4
  • ipv6
BGP neighbor parameters.
allowas_in
integer
Number of occurrences of AS number.
as_override
boolean
    Choices:
  • no
  • yes
AS for routes sent to this neighbor to be the local AS.
attribute_unchanged
dictionary
BGP attributes are sent unchanged.
as_path
boolean
    Choices:
  • no
  • yes
as_path attribute
med
boolean
    Choices:
  • no
  • yes
med attribute
next_hop
boolean
    Choices:
  • no
  • yes
next_hop attribute
capability
dictionary
Advertise capabilities to this neighbor.
dynamic
boolean
    Choices:
  • no
  • yes
Advertise dynamic capability to this neighbor.
orf
string
    Choices:
  • send
  • receive
Advertise ORF capability to this neighbor.
default_originate
string
Send default route to this neighbor
distribute_list
list / elements=dictionary
Access-list to filter route updates to/from this neighbor.
acl
integer
Access-list number.
action
string
    Choices:
  • export
  • import
Access-list to filter outgoing/incoming route updates to this neighbor
filter_list
list / elements=dictionary
As-path-list to filter route updates to/from this neighbor.
action
string
    Choices:
  • export
  • import
filter outgoing/incoming route updates
path_list
string
As-path-list to filter
maximum_prefix
integer
Maximum number of prefixes to accept from this neighbor nexthop-self Nexthop for routes sent to this neighbor to be the local router.
nexthop_local
boolean
    Choices:
  • no
  • yes
Nexthop attributes.
nexthop_self
boolean
    Choices:
  • no
  • yes
Nexthop for routes sent to this neighbor to be the local router.
peer_group
string
IPv4 peer group for this peer
prefix_list
list / elements=dictionary
Prefix-list to filter route updates to/from this neighbor.
action
string
    Choices:
  • export
  • import
filter outgoing/incoming route updates
prefix_list
string
Prefix-list to filter
remove_private_as
boolean
    Choices:
  • no
  • yes
Remove private AS numbers from AS path in outbound route updates
route_map
list / elements=dictionary
Route-map to filter route updates to/from this neighbor.
action
string
    Choices:
  • export
  • import
filter outgoing/incoming route updates
route_map
string
route-map to filter
route_reflector_client
boolean
    Choices:
  • no
  • yes
Neighbor as a route reflector client
route_server_client
boolean
    Choices:
  • no
  • yes
Neighbor is route server client
soft_reconfiguration
boolean
    Choices:
  • no
  • yes
Soft reconfiguration for neighbor
unsupress_map
string
Route-map to selectively unsuppress suppressed routes
weight
integer
Default weight for routes from this neighbor
neighbor_address
string
BGP neighbor address (v4/v6).
running_config
string
This option is used only with state parsed.
The value of this option should be the output received from the VYOS device by executing the command show configuration command | match bgp.
The state parsed reads the configuration from running_config option and transforms it into Ansible structured data as per the resource module's argspec and the value is then returned in the parsed key within the result.
state
string
    Choices:
  • merged ←
  • replaced
  • deleted
  • gathered
  • parsed
  • rendered
  • purged
  • overridden
The state the configuration should be left in.

Examples -------- .. code-block:: yaml # Using merged # Before state # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # vyos@vyos:~$ - name: Merge provided configuration with device configuration vyos.vyos.vyos_bgp_address_family: config: as_number: "100" address_family: - afi: "ipv4" redistribute: - protocol: "static" metric: 50 neighbors: - neighbor_address: "20.33.1.1/24" address_family: - afi: "ipv4" allowas_in: 4 as_override: true attribute_unchanged: med: true - afi: "ipv6" default_originate: "map01" distribute_list: - action: "export" acl: 10 - neighbor_address: "100.11.34.12" address_family: - afi: "ipv4" maximum_prefix: 45 nexthop_self: true route_map: - action: "export" route_map: "map01" - action: "import" route_map: "map01" weight: 50 # After State: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 100 address-family ipv4-unicast redistribute static metric '50' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast allowas-in number '4' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast as-override # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast attribute-unchanged med # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast default-originate route-map 'map01' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast distribute-list export '10' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast maximum-prefix '45' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast nexthop-self # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast route-map export 'map01' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast route-map import 'map01' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast weight '50' # vyos@vyos:~$ # # Module Execution: # # "after": { # "address_family": [ # { # "afi": "ipv4", # "redistribute": [ # { # "metric": 50, # "protocol": "static" # } # ] # } # ], # "as_number": 100, # "neighbors": [ # { # "address_family": [ # { # "afi": "ipv4", # "maximum_prefix": 45, # "nexthop_self": true, # "route_map": [ # { # "action": "export", # "route_map": "map01" # }, # { # "action": "import", # "route_map": "map01" # } # ], # "weight": 50 # } # ], # "neighbor_address": "100.11.34.12" # }, # { # "address_family": [ # { # "afi": "ipv4", # "allowas_in": 4, # "as_override": true, # "attribute_unchanged": { # "med": true # } # }, # { # "afi": "ipv6", # "default_originate": "map01", # "distribute_list": [ # { # "acl": 10, # "action": "export" # } # ] # } # ], # "neighbor_address": "20.33.1.1/24" # } # ] # }, # "before": {}, # "changed": true, # "commands": [ # "set protocols bgp 100 address-family ipv4-unicast redistribute static metric 50", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast allowas-in number 4", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast as-override", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast attribute-unchanged med", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast default-originate route-map map01", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast distribute-list export 10", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast maximum-prefix 45", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast nexthop-self", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast route-map export map01", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast route-map import map01", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast weight 50" # ], # # Using replaced: # Before state: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 100 address-family ipv4-unicast redistribute static metric '50' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast allowas-in number '4' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast as-override # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast attribute-unchanged med # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast default-originate route-map 'map01' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast distribute-list export '10' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast maximum-prefix '45' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast nexthop-self # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast route-map export 'map01' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast route-map import 'map01' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast weight '50' # vyos@vyos:~$ - name: Replace provided configuration with device configuration vyos.vyos.vyos_bgp_address_family: config: as_number: "100" neighbors: - neighbor_address: "100.11.34.12" address_family: - afi: "ipv4" allowas_in: 4 as_override: true attribute_unchanged: med: true - afi: "ipv6" default_originate: "map01" distribute_list: - action: "export" acl: 10 - neighbor_address: "20.33.1.1/24" address_family: - afi: "ipv6" maximum_prefix: 45 nexthop_self: true state: replaced # After State: # # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 100 address-family ipv4-unicast redistribute static metric '50' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast maximum-prefix '45' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast nexthop-self # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast allowas-in number '4' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast as-override # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast attribute-unchanged med # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast default-originate route-map 'map01' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast distribute-list export '10' # vyos@vyos:~$ # # # # Module Execution: # "after": { # "address_family": [ # { # "afi": "ipv4", # "redistribute": [ # { # "metric": 50, # "protocol": "static" # } # ] # } # ], # "as_number": 100, # "neighbors": [ # { # "address_family": [ # { # "afi": "ipv4", # "allowas_in": 4, # "as_override": true, # "attribute_unchanged": { # "med": true # } # }, # { # "afi": "ipv6", # "default_originate": "map01", # "distribute_list": [ # { # "acl": 10, # "action": "export" # } # ] # } # ], # "neighbor_address": "100.11.34.12" # }, # { # "address_family": [ # { # "afi": "ipv4" # }, # { # "afi": "ipv6", # "maximum_prefix": 45, # "nexthop_self": true # } # ], # "neighbor_address": "20.33.1.1/24" # } # ] # }, # "before": { # "address_family": [ # { # "afi": "ipv4", # "redistribute": [ # { # "metric": 50, # "protocol": "static" # } # ] # } # ], # "as_number": 100, # "neighbors": [ # { # "address_family": [ # { # "afi": "ipv4", # "maximum_prefix": 45, # "nexthop_self": true, # "route_map": [ # { # "action": "export", # "route_map": "map01" # }, # { # "action": "import", # "route_map": "map01" # } # ], # "weight": 50 # } # ], # "neighbor_address": "100.11.34.12" # }, # { # "address_family": [ # { # "afi": "ipv4", # "allowas_in": 4, # "as_override": true, # "attribute_unchanged": { # "med": true # } # }, # { # "afi": "ipv6", # "default_originate": "map01", # "distribute_list": [ # { # "acl": 10, # "action": "export" # } # ] # } # ], # "neighbor_address": "20.33.1.1/24" # } # ] # }, # "changed": true, # "commands": [ # "delete protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast distribute-list", # "delete protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast default-originate", # "delete protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast attribute-unchanged", # "delete protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast as-override", # "delete protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast allowas-in", # "delete protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast weight", # "delete protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast route-map", # "delete protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast nexthop-self", # "delete protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast maximum-prefix", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast allowas-in number 4", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast as-override", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast attribute-unchanged med", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast default-originate route-map map01", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast distribute-list export 10", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast maximum-prefix 45", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast nexthop-self" # ], # Using overridden # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 100 address-family ipv4-unicast network 35.1.1.0/24 backdoor # set protocols bgp 100 address-family ipv4-unicast redistribute static metric '50' # set protocols bgp 100 address-family ipv6-unicast aggregate-address 6601:1:1:1::/64 summary-only # set protocols bgp 100 address-family ipv6-unicast network 5001:1:1:1::/64 route-map 'map01' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast maximum-prefix '45' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast nexthop-self # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast allowas-in number '4' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast as-override # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast attribute-unchanged med # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast default-originate route-map 'map01' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast distribute-list export '10' # vyos@vyos:~$ - name: Override vyos.vyos.vyos_bgp_address_family: config: as_number: "100" neighbors: - neighbor_address: "100.11.34.12" address_family: - afi: "ipv6" maximum_prefix: 45 nexthop_self: true route_map: - action: "import" route_map: "map01" address_family: - afi: "ipv4" aggregate_address: - prefix: "60.9.2.0/24" summary_only: true - afi: "ipv6" redistribute: - protocol: "static" metric: 50 state: overridden # After State # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 100 address-family ipv4-unicast aggregate-address 60.9.2.0/24 summary-only # set protocols bgp 100 address-family ipv6-unicast redistribute static metric '50' # set protocols bgp 100 neighbor 20.33.1.1/24 # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast maximum-prefix '45' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast nexthop-self # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast route-map import 'map01' # vyos@vyos:~$ # Module Execution: # "after": { # "address_family": [ # { # "afi": "ipv4", # "aggregate_address": [ # { # "prefix": "60.9.2.0/24", # "summary_only": true # } # ] # }, # { # "afi": "ipv6", # "redistribute": [ # { # "metric": 50, # "protocol": "static" # } # ] # } # ], # "as_number": 100, # "neighbors": [ # { # "address_family": [ # { # "afi": "ipv4" # }, # { # "afi": "ipv6", # "maximum_prefix": 45, # "nexthop_self": true, # "route_map": [ # { # "action": "import", # "route_map": "map01" # } # ] # } # ], # "neighbor_address": "100.11.34.12" # } # ] # }, # "before": { # "address_family": [ # { # "afi": "ipv4", # "networks": [ # { # "backdoor": true, # "prefix": "35.1.1.0/24" # } # ], # "redistribute": [ # { # "metric": 50, # "protocol": "static" # } # ] # }, # { # "afi": "ipv6", # "aggregate_address": [ # { # "prefix": "6601:1:1:1::/64", # "summary_only": true # } # ], # "networks": [ # { # "prefix": "5001:1:1:1::/64", # "route_map": "map01" # } # ] # } # ], # "as_number": 100, # "neighbors": [ # { # "address_family": [ # { # "afi": "ipv4", # "allowas_in": 4, # "as_override": true, # "attribute_unchanged": { # "med": true # } # }, # { # "afi": "ipv6", # "default_originate": "map01", # "distribute_list": [ # { # "acl": 10, # "action": "export" # } # ] # } # ], # "neighbor_address": "100.11.34.12" # }, # { # "address_family": [ # { # "afi": "ipv4" # }, # { # "afi": "ipv6", # "maximum_prefix": 45, # "nexthop_self": true # } # ], # "neighbor_address": "20.33.1.1/24" # } # ] # }, # "changed": true, # "commands": [ # "delete protocols bgp 100 neighbor 20.33.1.1/24 address-family", # "delete protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast distribute-list", # "delete protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast default-originate", # "delete protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast attribute-unchanged", # "delete protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast as-override", # "delete protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast allowas-in", # "delete protocols bgp 100 address-family ipv6 aggregate-address", # "delete protocols bgp 100 address-family ipv6 network", # "delete protocols bgp 100 address-family ipv4 network", # "delete protocols bgp 100 address-family ipv4 redistribute", # "set protocols bgp 100 address-family ipv4-unicast aggregate-address 60.9.2.0/24 summary-only", # "set protocols bgp 100 address-family ipv6-unicast redistribute static metric 50", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast maximum-prefix 45", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast nexthop-self", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast route-map import map01" # ], # # Using deleted: # Before State: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 100 address-family ipv4-unicast aggregate-address 60.9.2.0/24 summary-only # set protocols bgp 100 address-family ipv4-unicast redistribute static metric '50' # set protocols bgp 100 address-family ipv6-unicast redistribute static metric '50' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast allowas-in number '4' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast as-override # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast attribute-unchanged med # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast default-originate route-map 'map01' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast distribute-list export '10' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast maximum-prefix '45' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast nexthop-self # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast route-map export 'map01' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast route-map import 'map01' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast weight '50' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast maximum-prefix '45' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast nexthop-self # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast route-map import 'map01' # vyos@vyos:~$ - name: Delete vyos.vyos.vyos_bgp_address_family: config: as_number: "100" neighbors: - neighbor_address: "20.33.1.1/24" address_family: - afi: "ipv6" - neighbor_address: "100.11.34.12" address_family: - afi: "ipv4" state: deleted # After State: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 100 address-family ipv6-unicast redistribute static metric '50' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast allowas-in number '4' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast as-override # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast attribute-unchanged med # set protocols bgp 100 neighbor 100.11.34.12 # vyos@vyos:~$ # # # Module Execution: # # "after": { # "address_family": [ # { # "afi": "ipv6", # "redistribute": [ # { # "metric": 50, # "protocol": "static" # } # ] # } # ], # "as_number": 100, # "neighbors": [ # { # "address_family": [ # { # "afi": "ipv4", # "allowas_in": 4, # "as_override": true, # "attribute_unchanged": { # "med": true # } # } # ], # "neighbor_address": "20.33.1.1/24" # } # ] # }, # "before": { # "address_family": [ # { # "afi": "ipv4", # "aggregate_address": [ # { # "prefix": "60.9.2.0/24", # "summary_only": true # } # ], # "redistribute": [ # { # "metric": 50, # "protocol": "static" # } # ] # }, # { # "afi": "ipv6", # "redistribute": [ # { # "metric": 50, # "protocol": "static" # } # ] # } # ], # "as_number": 100, # "neighbors": [ # { # "address_family": [ # { # "afi": "ipv4", # "maximum_prefix": 45, # "nexthop_self": true, # "route_map": [ # { # "action": "export", # "route_map": "map01" # }, # { # "action": "import", # "route_map": "map01" # } # ], # "weight": 50 # }, # { # "afi": "ipv6", # "maximum_prefix": 45, # "nexthop_self": true, # "route_map": [ # { # "action": "import", # "route_map": "map01" # } # ] # } # ], # "neighbor_address": "100.11.34.12" # }, # { # "address_family": [ # { # "afi": "ipv4", # "allowas_in": 4, # "as_override": true, # "attribute_unchanged": { # "med": true # } # }, # { # "afi": "ipv6", # "default_originate": "map01", # "distribute_list": [ # { # "acl": 10, # "action": "export" # } # ] # } # ], # "neighbor_address": "20.33.1.1/24" # } # ] # }, # "changed": true, # "commands": [ # "delete protocols bgp 100 address-family ipv4-unicast", # "delete protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast", # "delete protocols bgp 100 neighbor 100.11.34.12 address-family" # ], # # using parsed: # parsed.cfg # set protocols bgp 65536 address-family ipv4-unicast aggregate-address 192.0.2.0/24 as-set # set protocols bgp 65536 address-family ipv4-unicast network 192.1.13.0/24 route-map 'map01' # set protocols bgp 65536 address-family ipv4-unicast network 192.2.13.0/24 backdoor # set protocols bgp 65536 address-family ipv6-unicast redistribute ripng metric '20' # set protocols bgp 65536 neighbor 192.0.2.25 address-family ipv4-unicast route-map export 'map01' # set protocols bgp 65536 neighbor 192.0.2.25 address-family ipv4-unicast soft-reconfiguration inbound # set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged next-hop - name: parse configs vyos.vyos.vyos_bgp_address_family: running_config: "{{ lookup('file', './parsed.cfg') }}" state: parsed # Module execution result: # # "parsed": { # "address_family": [ # { # "afi": "ipv4", # "aggregate_address": [ # { # "as_set": true, # "prefix": "192.0.2.0/24" # } # ], # "networks": [ # { # "prefix": "192.1.13.0/24", # "route_map": "map01" # }, # { # "backdoor": true, # "prefix": "192.2.13.0/24" # } # ] # }, # { # "afi": "ipv6", # "redistribute": [ # { # "metric": 20, # "protocol": "ripng" # } # ] # } # ], # "as_number": 65536, # "neighbors": [ # { # "address_family": [ # { # "afi": "ipv4", # "route_map": [ # { # "action": "export", # "route_map": "map01" # } # ], # "soft_reconfiguration": true # } # ], # "neighbor_address": "192.0.2.25" # }, # { # "address_family": [ # { # "afi": "ipv6", # "attribute_unchanged": { # "next_hop": true # } # } # ], # "neighbor_address": "203.0.113.5" # } # ] # # Using gathered: # Native config: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 100 address-family ipv4-unicast network 35.1.1.0/24 backdoor # set protocols bgp 100 address-family ipv4-unicast redistribute static metric '50' # set protocols bgp 100 address-family ipv6-unicast aggregate-address 6601:1:1:1::/64 summary-only # set protocols bgp 100 address-family ipv6-unicast network 5001:1:1:1::/64 route-map 'map01' # set protocols bgp 100 address-family ipv6-unicast redistribute static metric '50' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast allowas-in number '4' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast as-override # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast attribute-unchanged med # set protocols bgp 100 neighbor 100.11.34.12 - name: gather configs vyos.vyos.vyos_bgp_address_family: state: gathered # Module execution result: # # "gathered": { # "address_family": [ # { # "afi": "ipv4", # "networks": [ # { # "backdoor": true, # "prefix": "35.1.1.0/24" # } # ], # "redistribute": [ # { # "metric": 50, # "protocol": "static" # } # ] # }, # { # "afi": "ipv6", # "aggregate_address": [ # { # "prefix": "6601:1:1:1::/64", # "summary_only": true # } # ], # "networks": [ # { # "prefix": "5001:1:1:1::/64", # "route_map": "map01" # } # ], # "redistribute": [ # { # "metric": 50, # "protocol": "static" # } # ] # } # ], # "as_number": 100, # "neighbors": [ # { # "address_family": [ # { # "afi": "ipv4", # "allowas_in": 4, # "as_override": true, # "attribute_unchanged": { # "med": true # } # } # ], # "neighbor_address": "20.33.1.1/24" # } # ] # Using rendered: - name: Render vyos.vyos.vyos_bgp_address_family: config: as_number: "100" address_family: - afi: "ipv4" redistribute: - protocol: "static" metric: 50 neighbors: - neighbor_address: "20.33.1.1/24" address_family: - afi: "ipv4" allowas_in: 4 as_override: true attribute_unchanged: med: true - afi: "ipv6" default_originate: "map01" distribute_list: - action: "export" acl: 10 - neighbor_address: "100.11.34.12" address_family: - afi: "ipv4" maximum_prefix: 45 nexthop_self: true route_map: - action: "export" route_map: "map01" - action: "import" route_map: "map01" weight: 50 state: rendered # Module Execution: # "rendered": [ # "set protocols bgp 100 address-family ipv4-unicast redistribute static metric 50", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast allowas-in number 4", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast as-override", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast attribute-unchanged med", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast default-originate route-map map01", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast distribute-list export 10", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast maximum-prefix 45", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast nexthop-self", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast route-map export map01", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast route-map import map01", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast weight 50" # ] Return Values ------------- Common return values are documented `here `_, the following are the fields unique to this module: .. raw:: html
Key Returned Description
after
dictionary
when changed
The resulting configuration after module execution.

Sample:
This output will always be in the same format as the module argspec.
before
dictionary
when state is merged, replaced, overridden, deleted or purged
The configuration prior to the module execution.

Sample:
This output will always be in the same format as the module argspec.
commands
list
when state is merged, replaced, overridden, deleted or purged
The set of commands pushed to the remote device.

Sample:
['sample command 1', 'sample command 2', 'sample command 3']
gathered
list
when state is gathered
Facts about the network resource gathered from the remote device as structured data.

Sample:
This output will always be in the same format as the module argspec.
parsed
list
when state is parsed
The device native config provided in running_config option parsed into structured data as per module argspec.

Sample:
This output will always be in the same format as the module argspec.
rendered
list
when state is rendered
The provided configuration in the task rendered in device-native format (offline).

Sample:
['sample command 1', 'sample command 2', 'sample command 3']


Status ------ Authors ~~~~~~~ - Gomathi Selvi Srinivasan (@GomathiselviS) diff --git a/docs/vyos.vyos.vyos_bgp_global_module.rst b/docs/vyos.vyos.vyos_bgp_global_module.rst index 4479124c..64a1b7e0 100644 --- a/docs/vyos.vyos.vyos_bgp_global_module.rst +++ b/docs/vyos.vyos.vyos_bgp_global_module.rst @@ -1,3192 +1,2423 @@ .. _vyos.vyos.vyos_bgp_global_module: ************************* vyos.vyos.vyos_bgp_global ************************* **BGP global resource module** Version added: 1.0.0 .. contents:: :local: :depth: 1 Synopsis -------- - This module manages BGP global configuration of interfaces on devices running VYOS. +- Tested against VYOS 1.3, 1.4 Parameters ---------- .. raw:: html - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - - - - - - - + - - - - - - - + - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Parameter Choices/Defaults Comments
config
dictionary
A dict of BGP global configuration for interfaces.
-
- aggregate_address - -
- list - / elements=dictionary -
-
- -
BGP aggregate network.
-
-
- as_set - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Generate AS-set path information for this aggregate address.
-
-
- prefix - -
- string -
-
- -
BGP aggregate network.
-
-
- summary_only - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Announce the aggregate summary network only.
-
as_number
integer
AS number.
bgp_params
dictionary
BGP parameters
always_compare_med
boolean
    Choices:
  • no
  • yes
Always compare MEDs from different neighbors
bestpath
dictionary
Default bestpath selection mechanism
as_path
string
    Choices:
  • confed
  • ignore
AS-path attribute comparison parameters
compare_routerid
boolean
    Choices:
  • no
  • yes
Compare the router-id for identical EBGP paths
med
string
    Choices:
  • confed
  • missing-as-worst
MED attribute comparison parameters
cluster_id
string
Route-reflector cluster-id
confederation
list / elements=dictionary
AS confederation parameters
identifier
integer
Confederation AS identifier
peers
integer
Peer ASs in the BGP confederation
dampening
dictionary
Enable route-flap dampening
half_life
integer
Half-life penalty in seconds
max_suppress_time
integer
Maximum duration to suppress a stable route
re_use
integer
Time to start reusing a route
start_suppress_time
integer
When to start suppressing a route
default
dictionary
BGP defaults
local_pref
integer
Default local preference
no_ipv4_unicast
boolean
    Choices:
  • no
  • yes
-
Deactivate IPv4 unicast for a peer by default
+
Deactivate IPv4 unicast for a peer by default + Deprecated: Unavailable after 1.4
deterministic_med
boolean
    Choices:
  • no
  • yes
Compare MEDs between different peers in the same AS
disable_network_import_check
boolean
    Choices:
  • no
  • yes
Disable IGP route check for network statements
distance
list / elements=dictionary
Administrative distances for BGP routes
prefix
integer
Administrative distance for a specific BGP prefix
type
string
    Choices:
  • external
  • internal
  • local
Type of route
value
integer
distance
enforce_first_as
boolean
    Choices:
  • no
  • yes
Require first AS in the path to match peer's AS
graceful_restart
integer
Maximum time to hold onto restarting peer's stale paths
log_neighbor_changes
boolean
    Choices:
  • no
  • yes
Log neighbor up/down changes and reset reason
no_client_to_client_reflection
boolean
    Choices:
  • no
  • yes
Disable client to client route reflection
no_fast_external_failover
boolean
    Choices:
  • no
  • yes
Disable immediate session reset if peer's connected link goes down
router_id
string
BGP router-id
scan_time
integer
BGP route scanner interval
-
- maximum_paths - -
- list - / elements=dictionary -
-
- -
BGP multipaths
-
-
- count - -
- integer -
-
- -
No. of paths.
-
-
- path - -
- string -
-
- -
BGP multipaths
-
neighbor
list / elements=dictionary
BGP neighbor
address
string
BGP neighbor address (v4/v6).
advertisement_interval
integer
Minimum interval for sending routing updates.
- allowas_in + capability
- integer + dictionary
-
Number of occurrences of AS number.
+
Advertise capabilities to this neighbor.
+
- as_override + dynamic
boolean
    Choices:
  • no
  • yes
-
AS for routes sent to this neighbor to be the local AS.
+
Advertise dynamic capability to this neighbor.
-
- attribute_unchanged - -
- dictionary -
-
- -
BGP attributes are sent unchanged.
-
- as_path + extended_nexthop
boolean
    Choices:
  • no
  • yes
-
as_path
+
Advertise extended nexthop capability to this neighbor.
+
- med + default_originate
- boolean + string
-
    Choices: -
  • no
  • -
  • yes
  • -
-
med
+
Send default route to this neighbor
+
- next_hop + description
- boolean + string
-
    Choices: -
  • no
  • -
  • yes
  • -
-
next_hop
+
Description of the neighbor
- capability + disable_capability_negotiation
- dictionary + boolean
+
    Choices: +
  • no
  • +
  • yes
  • +
-
Advertise capabilities to this neighbor.
+
Disbale capability negotiation with the neighbor
+
- dynamic + disable_connected_check
boolean
    Choices:
  • no
  • yes
-
Advertise dynamic capability to this neighbor.
+
Disable check to see if EBGP peer's address is a connected route.
+
- orf + disable_send_community
string
    Choices: -
  • send
  • -
  • receive
  • +
  • extended
  • +
  • standard
-
Advertise ORF capability to this neighbor.
+
Disable sending community attributes to this neighbor.
- default_originate + ebgp_multihop
- string + integer
-
Send default route to this neighbor
+
Allow this EBGP neighbor to not be on a directly connected network. Specify the number hops.
- description + local_as
- string + integer
-
Description of the neighbor
+
local as number not to be prepended to updates from EBGP peers
- disable_capability_negotiation + override_capability
boolean
    Choices:
  • no
  • yes
-
Disbale capability negotiation with the neighbor
+
Ignore capability negotiation with specified neighbor.
- disable_connected_check + passive
boolean
    Choices:
  • no
  • yes
-
Disable check to see if EBGP peer's address is a connected route.
+
Do not initiate a session with this neighbor
- disable_send_community + password
string
-
    Choices: -
  • extended
  • -
  • standard
  • -
-
Disable sending community attributes to this neighbor.
+
BGP MD5 password
- distribute_list + peer_group
- list - / elements=dictionary + boolean
+
    Choices: +
  • no
  • +
  • yes
  • +
-
Access-list to filter route updates to/from this neighbor.
+
True if all the configs under this neighbor key is for peer group template.
+
- acl + peer_group_name
- integer + string
-
Access-list number.
+
IPv4 peer group for this peer
+
- action + port
- string + integer
-
    Choices: -
  • export
  • -
  • import
  • -
-
Access-list to filter outgoing/incoming route updates to this neighbor
+
Neighbor's BGP port
- ebgp_multihop + remote_as
integer
-
Allow this EBGP neighbor to not be on a directly connected network. Specify the number hops.
+
Neighbor BGP AS number
- filter_list - -
- list - / elements=dictionary -
-
- -
As-path-list to filter route updates to/from this neighbor.
-
-
- action - -
- string -
-
-
    Choices: -
  • export
  • -
  • import
  • -
-
-
filter outgoing/incoming route updates
-
-
- path_list - -
- string -
-
- -
As-path-list to filter
-
-
- local_as - -
- integer -
-
- -
local as number not to be prepended to updates from EBGP peers
-
-
- maximum_prefix - -
- integer -
-
- -
Maximum number of prefixes to accept from this neighbor nexthop-self Nexthop for routes sent to this neighbor to be the local router.
-
-
- nexthop_self - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Nexthop for routes sent to this neighbor to be the local router.
-
-
- override_capability - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Ignore capability negotiation with specified neighbor.
-
-
- passive - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Do not initiate a session with this neighbor
-
-
- password - -
- string -
-
- -
BGP MD5 password
-
-
- peer_group - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
True if all the configs under this neighbor key is for peer group template.
-
-
- peer_group_name - -
- string -
-
- -
IPv4 peer group for this peer
-
-
- port - -
- integer -
-
- -
Neighbor's BGP port
-
-
- prefix_list - -
- list - / elements=dictionary -
-
- -
Prefix-list to filter route updates to/from this neighbor.
-
-
- action - -
- string -
-
-
    Choices: -
  • export
  • -
  • import
  • -
-
-
filter outgoing/incoming route updates
-
-
- prefix_list - -
- string -
-
- -
Prefix-list to filter
-
-
- remote_as - -
- integer -
-
- -
Neighbor BGP AS number
-
-
- remove_private_as - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Remove private AS numbers from AS path in outbound route updates
-
-
- route_map - -
- list - / elements=dictionary -
-
- -
Route-map to filter route updates to/from this neighbor.
-
-
- action - -
- string -
-
-
    Choices: -
  • export
  • -
  • import
  • -
-
-
filter outgoing/incoming route updates
-
-
- route_map - -
- string -
-
- -
route-map to filter
-
-
- route_reflector_client - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Neighbor as a route reflector client
-
-
- route_server_client - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Neighbor is route server client
-
-
- shutdown + shutdown
boolean
    Choices:
  • no
  • yes
Administratively shut down neighbor
- soft_reconfiguration + solo
boolean
    Choices:
  • no
  • yes
-
Soft reconfiguration for neighbor
+
Do not send back prefixes learned from the neighbor
strict_capability_match
boolean
    Choices:
  • no
  • yes
Enable strict capability negotiation
timers
dictionary
Neighbor timers
connect
integer
BGP connect timer for this neighbor.
holdtime
integer
BGP hold timer for this neighbor
keepalive
integer
BGP keepalive interval for this neighbor
ttl_security
integer
-
Ttl security mechanism for this BGP peer
-
-
- unsuppress_map - -
- string -
-
- -
Route-map to selectively unsuppress suppressed routes
+
Number of the maximum number of hops to the BGP peer
update_source
string
Source IP of routing updates
-
- weight - -
- integer -
-
- -
Default weight for routes from this neighbor
-
-
- network - -
- list - / elements=dictionary -
-
- -
BGP network
-
-
- address - -
- string -
-
- -
BGP network address
-
-
- backdoor - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Network as a backdoor route
-
-
- route_map - -
- string -
-
- -
Route-map to modify route attributes
-
-
- redistribute - -
- list - / elements=dictionary -
-
- -
Redistribute routes from other protocols into BGP
-
-
- metric - -
- integer -
-
- -
Metric for redistributed routes.
-
-
- protocol - -
- string -
-
-
    Choices: -
  • connected
  • -
  • kernel
  • -
  • ospf
  • -
  • rip
  • -
  • static
  • -
-
-
types of routes to be redistributed.
-
-
- route_map - -
- string -
-
- -
Route map to filter redistributed routes
-
timers
dictionary
BGP protocol timers
holdtime
integer
Hold time interval
keepalive
integer
Keepalive interval
running_config
string
This option is used only with state parsed.
The value of this option should be the output received from the EOS device by executing the command show running-config | section bgp.
The state parsed reads the configuration from running_config option and transforms it into Ansible structured data as per the resource module's argspec and the value is then returned in the parsed key within the result.
state
string
    Choices:
  • deleted
  • merged ←
  • purged
  • replaced
  • gathered
  • rendered
  • parsed
The state the configuration should be left in.
State purged removes all the BGP configurations from the target device. Use caution with this state.('delete protocols bgp <x>')
State deleted only removes BGP attributes that this modules manages and does not negate the BGP process completely. Thereby, preserving address-family related configurations under BGP context.
Running states deleted and replaced will result in an error if there are address-family configuration lines present under neighbor context that is is to be removed. Please use the vyos.vyos.vyos_bgp_address_family module for prior cleanup.
Refer to examples for more details.

Examples -------- .. code-block:: yaml # Using merged # Before state # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # vyos@vyos:~$ - name: Merge provided configuration with device configuration vyos.vyos.vyos_bgp_global: config: as_number: "65536" aggregate_address: - prefix: "203.0.113.0/24" as_set: true - prefix: "192.0.2.0/24" summary_only: true network: - address: "192.1.13.0/24" backdoor: true redistribute: - protocol: "kernel" metric: 45 - protocol: "connected" route_map: "map01" maximum_paths: - path: "ebgp" count: 20 - path: "ibgp" count: 55 timers: keepalive: 35 bgp_params: bestpath: as_path: "confed" compare_routerid: true default: no_ipv4_unicast: true router_id: "192.1.2.9" confederation: - peers: 20 - peers: 55 - identifier: 66 neighbor: - address: "192.0.2.25" disable_connected_check: true timers: holdtime: 30 keepalive: 10 - address: "203.0.113.5" attribute_unchanged: as_path: true med: true ebgp_multihop: 2 remote_as: 101 update_source: "192.0.2.25" - address: "5001::64" maximum_prefix: 34 distribute_list: - acl: 20 action: "export" - acl: 40 action: "import" state: merged # After State # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 65536 aggregate-address 192.0.2.0/24 'summary-only' # set protocols bgp 65536 aggregate-address 203.0.113.0/24 'as-set' # set protocols bgp 65536 maximum-paths ebgp '20' # set protocols bgp 65536 maximum-paths ibgp '55' # set protocols bgp 65536 neighbor 192.0.2.25 'disable-connected-check' # set protocols bgp 65536 neighbor 192.0.2.25 timers holdtime '30' # set protocols bgp 65536 neighbor 192.0.2.25 timers keepalive '10' # set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'as-path' # set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'med' # set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'next-hop' # set protocols bgp 65536 neighbor 203.0.113.5 ebgp-multihop '2' # set protocols bgp 65536 neighbor 203.0.113.5 remote-as '101' # set protocols bgp 65536 neighbor 203.0.113.5 update-source '192.0.2.25' # set protocols bgp 65536 neighbor 5001::64 distribute-list export '20' # set protocols bgp 65536 neighbor 5001::64 distribute-list import '40' # set protocols bgp 65536 neighbor 5001::64 maximum-prefix '34' # set protocols bgp 65536 network 192.1.13.0/24 'backdoor' # set protocols bgp 65536 parameters bestpath as-path 'confed' # set protocols bgp 65536 parameters bestpath 'compare-routerid' # set protocols bgp 65536 parameters confederation identifier '66' # set protocols bgp 65536 parameters confederation peers '20' # set protocols bgp 65536 parameters confederation peers '55' # set protocols bgp 65536 parameters default 'no-ipv4-unicast' # set protocols bgp 65536 parameters router-id '192.1.2.9' # set protocols bgp 65536 redistribute connected route-map 'map01' # set protocols bgp 65536 redistribute kernel metric '45' # set protocols bgp 65536 timers keepalive '35' # vyos@vyos:~$ # # # Module Execution: # # "after": { # "aggregate_address": [ # { # "prefix": "192.0.2.0/24", # "summary_only": true # }, # { # "prefix": "203.0.113.0/24", # "as_set": true # } # ], # "as_number": 65536, # "bgp_params": { # "bestpath": { # "as_path": "confed", # "compare_routerid": true # }, # "confederation": [ # { # "identifier": 66 # }, # { # "peers": 20 # }, # { # "peers": 55 # } # ], # "default": { # "no_ipv4_unicast": true # }, # "router_id": "192.1.2.9" # }, # "maximum_paths": [ # { # "count": 20, # "path": "ebgp" # }, # { # "count": 55, # "path": "ibgp" # } # ], # "neighbor": [ # { # "address": "192.0.2.25", # "disable_connected_check": true, # "timers": { # "holdtime": 30, # "keepalive": 10 # } # }, # { # "address": "203.0.113.5", # "attribute_unchanged": { # "as_path": true, # "med": true, # "next_hop": true # }, # "ebgp_multihop": 2, # "remote_as": 101, # "update_source": "192.0.2.25" # }, # { # "address": "5001::64", # "distribute_list": [ # { # "acl": 20, # "action": "export" # }, # { # "acl": 40, # "action": "import" # } # ], # "maximum_prefix": 34 # } # ], # "network": [ # { # "address": "192.1.13.0/24", # "backdoor": true # } # ], # "redistribute": [ # { # "protocol": "connected", # "route_map": "map01" # }, # { # "metric": 45, # "protocol": "kernel" # } # ], # "timers": { # "keepalive": 35 # } # }, # "before": {}, # "changed": true, # "commands": [ # "set protocols bgp 65536 neighbor 192.0.2.25 disable-connected-check", # "set protocols bgp 65536 neighbor 192.0.2.25 timers holdtime 30", # "set protocols bgp 65536 neighbor 192.0.2.25 timers keepalive 10", # "set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged as-path", # "set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged med", # "set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged next-hop", # "set protocols bgp 65536 neighbor 203.0.113.5 ebgp-multihop 2", # "set protocols bgp 65536 neighbor 203.0.113.5 remote-as 101", # "set protocols bgp 65536 neighbor 203.0.113.5 update-source 192.0.2.25", # "set protocols bgp 65536 neighbor 5001::64 maximum-prefix 34", # "set protocols bgp 65536 neighbor 5001::64 distribute-list export 20", # "set protocols bgp 65536 neighbor 5001::64 distribute-list import 40", # "set protocols bgp 65536 redistribute kernel metric 45", # "set protocols bgp 65536 redistribute connected route-map map01", # "set protocols bgp 65536 network 192.1.13.0/24 backdoor", # "set protocols bgp 65536 aggregate-address 203.0.113.0/24 as-set", # "set protocols bgp 65536 aggregate-address 192.0.2.0/24 summary-only", # "set protocols bgp 65536 parameters bestpath as-path confed", # "set protocols bgp 65536 parameters bestpath compare-routerid", # "set protocols bgp 65536 parameters default no-ipv4-unicast", # "set protocols bgp 65536 parameters router-id 192.1.2.9", # "set protocols bgp 65536 parameters confederation peers 20", # "set protocols bgp 65536 parameters confederation peers 55", # "set protocols bgp 65536 parameters confederation identifier 66", # "set protocols bgp 65536 maximum-paths ebgp 20", # "set protocols bgp 65536 maximum-paths ibgp 55", # "set protocols bgp 65536 timers keepalive 35" # ], # Using replaced: # -------------- # Before state: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 65536 aggregate-address 192.0.2.0/24 'summary-only' # set protocols bgp 65536 aggregate-address 203.0.113.0/24 'as-set' # set protocols bgp 65536 maximum-paths ebgp '20' # set protocols bgp 65536 maximum-paths ibgp '55' # set protocols bgp 65536 neighbor 192.0.2.25 'disable-connected-check' # set protocols bgp 65536 neighbor 192.0.2.25 timers holdtime '30' # set protocols bgp 65536 neighbor 192.0.2.25 timers keepalive '10' # set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'as-path' # set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'med' # set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'next-hop' # set protocols bgp 65536 neighbor 203.0.113.5 ebgp-multihop '2' # set protocols bgp 65536 neighbor 203.0.113.5 remote-as '101' # set protocols bgp 65536 neighbor 203.0.113.5 update-source '192.0.2.25' # set protocols bgp 65536 neighbor 5001::64 distribute-list export '20' # set protocols bgp 65536 neighbor 5001::64 distribute-list import '40' # set protocols bgp 65536 neighbor 5001::64 maximum-prefix '34' # set protocols bgp 65536 network 192.1.13.0/24 'backdoor' # set protocols bgp 65536 parameters bestpath as-path 'confed' # set protocols bgp 65536 parameters bestpath 'compare-routerid' # set protocols bgp 65536 parameters confederation identifier '66' # set protocols bgp 65536 parameters confederation peers '20' # set protocols bgp 65536 parameters confederation peers '55' # set protocols bgp 65536 parameters default 'no-ipv4-unicast' # set protocols bgp 65536 parameters router-id '192.1.2.9' # set protocols bgp 65536 redistribute connected route-map 'map01' # set protocols bgp 65536 redistribute kernel metric '45' # set protocols bgp 65536 timers keepalive '35' # vyos@vyos:~$ - name: Replace vyos.vyos.vyos_bgp_global: config: as_number: "65536" network: - address: "203.0.113.0/24" route_map: map01 redistribute: - protocol: "static" route_map: "map01" neighbor: - address: "192.0.2.40" advertisement_interval: 72 capability: orf: "receive" bgp_params: bestpath: as_path: "confed" state: replaced # After state: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 65536 neighbor 192.0.2.40 advertisement-interval '72' # set protocols bgp 65536 neighbor 192.0.2.40 capability orf prefix-list 'receive' # set protocols bgp 65536 network 203.0.113.0/24 route-map 'map01' # set protocols bgp 65536 parameters bestpath as-path 'confed' # set protocols bgp 65536 redistribute static route-map 'map01' # vyos@vyos:~$ # # # Module Execution: # # "after": { # "as_number": 65536, # "bgp_params": { # "bestpath": { # "as_path": "confed" # } # }, # "neighbor": [ # { # "address": "192.0.2.40", # "advertisement_interval": 72, # "capability": { # "orf": "receive" # } # } # ], # "network": [ # { # "address": "203.0.113.0/24", # "route_map": "map01" # } # ], # "redistribute": [ # { # "protocol": "static", # "route_map": "map01" # } # ] # }, # "before": { # "aggregate_address": [ # { # "prefix": "192.0.2.0/24", # "summary_only": true # }, # { # "prefix": "203.0.113.0/24", # "as_set": true # } # ], # "as_number": 65536, # "bgp_params": { # "bestpath": { # "as_path": "confed", # "compare_routerid": true # }, # "confederation": [ # { # "identifier": 66 # }, # { # "peers": 20 # }, # { # "peers": 55 # } # ], # "default": { # "no_ipv4_unicast": true # }, # "router_id": "192.1.2.9" # }, # "maximum_paths": [ # { # "count": 20, # "path": "ebgp" # }, # { # "count": 55, # "path": "ibgp" # } # ], # "neighbor": [ # { # "address": "192.0.2.25", # "disable_connected_check": true, # "timers": { # "holdtime": 30, # "keepalive": 10 # } # }, # { # "address": "203.0.113.5", # "attribute_unchanged": { # "as_path": true, # "med": true, # "next_hop": true # }, # "ebgp_multihop": 2, # "remote_as": 101, # "update_source": "192.0.2.25" # }, # { # "address": "5001::64", # "distribute_list": [ # { # "acl": 20, # "action": "export" # }, # { # "acl": 40, # "action": "import" # } # ], # "maximum_prefix": 34 # } # ], # "network": [ # { # "address": "192.1.13.0/24", # "backdoor": true # } # ], # "redistribute": [ # { # "protocol": "connected", # "route_map": "map01" # }, # { # "metric": 45, # "protocol": "kernel" # } # ], # "timers": { # "keepalive": 35 # } # }, # "changed": true, # "commands": [ # "delete protocols bgp 65536 timers", # "delete protocols bgp 65536 maximum-paths ", # "delete protocols bgp 65536 maximum-paths ", # "delete protocols bgp 65536 parameters router-id 192.1.2.9", # "delete protocols bgp 65536 parameters default", # "delete protocols bgp 65536 parameters confederation", # "delete protocols bgp 65536 parameters bestpath compare-routerid", # "delete protocols bgp 65536 aggregate-address", # "delete protocols bgp 65536 network 192.1.13.0/24", # "delete protocols bgp 65536 redistribute kernel", # "delete protocols bgp 65536 redistribute kernel", # "delete protocols bgp 65536 redistribute connected", # "delete protocols bgp 65536 redistribute connected", # "delete protocols bgp 65536 neighbor 5001::64", # "delete protocols bgp 65536 neighbor 203.0.113.5", # "delete protocols bgp 65536 neighbor 192.0.2.25", # "set protocols bgp 65536 neighbor 192.0.2.40 advertisement-interval 72", # "set protocols bgp 65536 neighbor 192.0.2.40 capability orf prefix-list receive", # "set protocols bgp 65536 redistribute static route-map map01", # "set protocols bgp 65536 network 203.0.113.0/24 route-map map01" # ], # Using deleted: # ------------- # Before state: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 65536 neighbor 192.0.2.40 advertisement-interval '72' # set protocols bgp 65536 neighbor 192.0.2.40 capability orf prefix-list 'receive' # set protocols bgp 65536 network 203.0.113.0/24 route-map 'map01' # set protocols bgp 65536 parameters bestpath as-path 'confed' # set protocols bgp 65536 redistribute static route-map 'map01' # vyos@vyos:~$ - name: Delete configuration vyos.vyos.vyos_bgp_global: config: as_number: "65536" state: deleted # After state: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp '65536' # vyos@vyos:~$ # # # Module Execution: # # "after": { # "as_number": 65536 # }, # "before": { # "as_number": 65536, # "bgp_params": { # "bestpath": { # "as_path": "confed" # } # }, # "neighbor": [ # { # "address": "192.0.2.40", # "advertisement_interval": 72, # "capability": { # "orf": "receive" # } # } # ], # "network": [ # { # "address": "203.0.113.0/24", # "route_map": "map01" # } # ], # "redistribute": [ # { # "protocol": "static", # "route_map": "map01" # } # ] # }, # "changed": true, # "commands": [ # "delete protocols bgp 65536 neighbor 192.0.2.40", # "delete protocols bgp 65536 redistribute", # "delete protocols bgp 65536 network", # "delete protocols bgp 65536 parameters" # ], # Using purged: # Before state: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 65536 aggregate-address 192.0.2.0/24 'summary-only' # set protocols bgp 65536 aggregate-address 203.0.113.0/24 'as-set' # set protocols bgp 65536 maximum-paths ebgp '20' # set protocols bgp 65536 maximum-paths ibgp '55' # set protocols bgp 65536 neighbor 192.0.2.25 'disable-connected-check' # set protocols bgp 65536 neighbor 192.0.2.25 timers holdtime '30' # set protocols bgp 65536 neighbor 192.0.2.25 timers keepalive '10' # set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'as-path' # set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'med' # set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'next-hop' # set protocols bgp 65536 neighbor 203.0.113.5 ebgp-multihop '2' # set protocols bgp 65536 neighbor 203.0.113.5 remote-as '101' # set protocols bgp 65536 neighbor 203.0.113.5 update-source '192.0.2.25' # set protocols bgp 65536 neighbor 5001::64 distribute-list export '20' # set protocols bgp 65536 neighbor 5001::64 distribute-list import '40' # set protocols bgp 65536 neighbor 5001::64 maximum-prefix '34' # set protocols bgp 65536 network 192.1.13.0/24 'backdoor' # set protocols bgp 65536 parameters bestpath as-path 'confed' # set protocols bgp 65536 parameters bestpath 'compare-routerid' # set protocols bgp 65536 parameters confederation identifier '66' # set protocols bgp 65536 parameters confederation peers '20' # set protocols bgp 65536 parameters confederation peers '55' # set protocols bgp 65536 parameters default 'no-ipv4-unicast' # set protocols bgp 65536 parameters router-id '192.1.2.9' # set protocols bgp 65536 redistribute connected route-map 'map01' # set protocols bgp 65536 redistribute kernel metric '45' # set protocols bgp 65536 timers keepalive '35' # vyos@vyos:~$ - name: Purge configuration vyos.vyos.vyos_bgp_global: config: as_number: "65536" state: purged # After state: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # vyos@vyos:~$ # # Module Execution: # # "after": {}, # "before": { # "aggregate_address": [ # { # "prefix": "192.0.2.0/24", # "summary_only": true # }, # { # "prefix": "203.0.113.0/24", # "as_set": true # } # ], # "as_number": 65536, # "bgp_params": { # "bestpath": { # "as_path": "confed", # "compare_routerid": true # }, # "confederation": [ # { # "identifier": 66 # }, # { # "peers": 20 # }, # { # "peers": 55 # } # ], # "default": { # "no_ipv4_unicast": true # }, # "router_id": "192.1.2.9" # }, # "maximum_paths": [ # { # "count": 20, # "path": "ebgp" # }, # { # "count": 55, # "path": "ibgp" # } # ], # "neighbor": [ # { # "address": "192.0.2.25", # "disable_connected_check": true, # "timers": { # "holdtime": 30, # "keepalive": 10 # } # }, # { # "address": "203.0.113.5", # "attribute_unchanged": { # "as_path": true, # "med": true, # "next_hop": true # }, # "ebgp_multihop": 2, # "remote_as": 101, # "update_source": "192.0.2.25" # }, # { # "address": "5001::64", # "distribute_list": [ # { # "acl": 20, # "action": "export" # }, # { # "acl": 40, # "action": "import" # } # ], # "maximum_prefix": 34 # } # ], # "network": [ # { # "address": "192.1.13.0/24", # "backdoor": true # } # ], # "redistribute": [ # { # "protocol": "connected", # "route_map": "map01" # }, # { # "metric": 45, # "protocol": "kernel" # } # ], # "timers": { # "keepalive": 35 # } # }, # "changed": true, # "commands": [ # "delete protocols bgp 65536" # ], # Deleted in presence of address family under neighbors: # Before state: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 65536 neighbor 192.0.2.43 advertisement-interval '72' # set protocols bgp 65536 neighbor 192.0.2.43 capability 'dynamic' # set protocols bgp 65536 neighbor 192.0.2.43 'disable-connected-check' # set protocols bgp 65536 neighbor 192.0.2.43 timers holdtime '30' # set protocols bgp 65536 neighbor 192.0.2.43 timers keepalive '10' # set protocols bgp 65536 neighbor 203.0.113.0 address-family 'ipv6-unicast' # set protocols bgp 65536 neighbor 203.0.113.0 capability orf prefix-list 'receive' # set protocols bgp 65536 network 203.0.113.0/24 route-map 'map01' # set protocols bgp 65536 parameters 'always-compare-med' # set protocols bgp 65536 parameters bestpath as-path 'confed' # set protocols bgp 65536 parameters bestpath 'compare-routerid' # set protocols bgp 65536 parameters dampening half-life '33' # set protocols bgp 65536 parameters dampening max-suppress-time '20' # set protocols bgp 65536 parameters dampening re-use '60' # set protocols bgp 65536 parameters dampening start-suppress-time '5' # set protocols bgp 65536 parameters default 'no-ipv4-unicast' # set protocols bgp 65536 parameters distance global external '66' # set protocols bgp 65536 parameters distance global internal '20' # set protocols bgp 65536 parameters distance global local '10' # set protocols bgp 65536 redistribute static route-map 'map01' # vyos@vyos:~$ ^C # vyos@vyos:~$ - name: Delete configuration vyos.vyos.vyos_bgp_global: config: as_number: "65536" state: deleted # Module Execution: # # "changed": false, # "invocation": { # "module_args": { # "config": { # "aggregate_address": null, # "as_number": 65536, # "bgp_params": null, # "maximum_paths": null, # "neighbor": null, # "network": null, # "redistribute": null, # "timers": null # }, # "running_config": null, # "state": "deleted" # } # }, # "msg": "Use the _bgp_address_family module to delete the address_family under neighbor 203.0.113.0, before replacing/deleting the neighbor." # } # using gathered: # -------------- # Before state: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 65536 neighbor 192.0.2.43 advertisement-interval '72' # set protocols bgp 65536 neighbor 192.0.2.43 capability 'dynamic' # set protocols bgp 65536 neighbor 192.0.2.43 'disable-connected-check' # set protocols bgp 65536 neighbor 192.0.2.43 timers holdtime '30' # set protocols bgp 65536 neighbor 192.0.2.43 timers keepalive '10' # set protocols bgp 65536 neighbor 203.0.113.0 address-family 'ipv6-unicast' # set protocols bgp 65536 neighbor 203.0.113.0 capability orf prefix-list 'receive' # set protocols bgp 65536 network 203.0.113.0/24 route-map 'map01' # set protocols bgp 65536 parameters 'always-compare-med' # set protocols bgp 65536 parameters bestpath as-path 'confed' # set protocols bgp 65536 parameters bestpath 'compare-routerid' # set protocols bgp 65536 parameters dampening half-life '33' # set protocols bgp 65536 parameters dampening max-suppress-time '20' # set protocols bgp 65536 parameters dampening re-use '60' # set protocols bgp 65536 parameters dampening start-suppress-time '5' # set protocols bgp 65536 parameters default 'no-ipv4-unicast' # set protocols bgp 65536 parameters distance global external '66' # set protocols bgp 65536 parameters distance global internal '20' # set protocols bgp 65536 parameters distance global local '10' # set protocols bgp 65536 redistribute static route-map 'map01' # vyos@vyos:~$ ^C - name: gather configs vyos.vyos.vyos_bgp_global: state: gathered # Module Execution: # "gathered": { # "as_number": 65536, # "bgp_params": { # "always_compare_med": true, # "bestpath": { # "as_path": "confed", # "compare_routerid": true # }, # "default": { # "no_ipv4_unicast": true # }, # "distance": [ # { # "type": "external", # "value": 66 # }, # { # "type": "internal", # "value": 20 # }, # { # "type": "local", # "value": 10 # } # ] # }, # "neighbor": [ # { # "address": "192.0.2.43", # "advertisement_interval": 72, # "capability": { # "dynamic": true # }, # "disable_connected_check": true, # "timers": { # "holdtime": 30, # "keepalive": 10 # } # }, # { # "address": "203.0.113.0", # "capability": { # "orf": "receive" # } # } # ], # "network": [ # { # "address": "203.0.113.0/24", # "route_map": "map01" # } # ], # "redistribute": [ # { # "protocol": "static", # "route_map": "map01" # } # ] # }, # # Using parsed: # ------------ # parsed.cfg # set protocols bgp 65536 neighbor 192.0.2.43 advertisement-interval '72' # set protocols bgp 65536 neighbor 192.0.2.43 capability 'dynamic' # set protocols bgp 65536 neighbor 192.0.2.43 'disable-connected-check' # set protocols bgp 65536 neighbor 192.0.2.43 timers holdtime '30' # set protocols bgp 65536 neighbor 192.0.2.43 timers keepalive '10' # set protocols bgp 65536 neighbor 203.0.113.0 address-family 'ipv6-unicast' # set protocols bgp 65536 neighbor 203.0.113.0 capability orf prefix-list 'receive' # set protocols bgp 65536 network 203.0.113.0/24 route-map 'map01' # set protocols bgp 65536 parameters 'always-compare-med' # set protocols bgp 65536 parameters bestpath as-path 'confed' # set protocols bgp 65536 parameters bestpath 'compare-routerid' # set protocols bgp 65536 parameters dampening half-life '33' # set protocols bgp 65536 parameters dampening max-suppress-time '20' # set protocols bgp 65536 parameters dampening re-use '60' # set protocols bgp 65536 parameters dampening start-suppress-time '5' # set protocols bgp 65536 parameters default 'no-ipv4-unicast' # set protocols bgp 65536 parameters distance global external '66' # set protocols bgp 65536 parameters distance global internal '20' # set protocols bgp 65536 parameters distance global local '10' # set protocols bgp 65536 redistribute static route-map 'map01' - name: parse configs vyos.vyos.vyos_bgp_global: running_config: "{{ lookup('file', './parsed.cfg') }}" state: parsed tags: - parsed # Module execution: # "parsed": { # "as_number": 65536, # "bgp_params": { # "always_compare_med": true, # "bestpath": { # "as_path": "confed", # "compare_routerid": true # }, # "default": { # "no_ipv4_unicast": true # }, # "distance": [ # { # "type": "external", # "value": 66 # }, # { # "type": "internal", # "value": 20 # }, # { # "type": "local", # "value": 10 # } # ] # }, # "neighbor": [ # { # "address": "192.0.2.43", # "advertisement_interval": 72, # "capability": { # "dynamic": true # }, # "disable_connected_check": true, # "timers": { # "holdtime": 30, # "keepalive": 10 # } # }, # { # "address": "203.0.113.0", # "capability": { # "orf": "receive" # } # } # ], # "network": [ # { # "address": "203.0.113.0/24", # "route_map": "map01" # } # ], # "redistribute": [ # { # "protocol": "static", # "route_map": "map01" # } # ] # } # # Using rendered: # -------------- - name: Render vyos.vyos.vyos_bgp_global: config: as_number: "65536" network: - address: "203.0.113.0/24" route_map: map01 redistribute: - protocol: "static" route_map: "map01" bgp_params: always_compare_med: true dampening: start_suppress_time: 5 max_suppress_time: 20 half_life: 33 re_use: 60 distance: - type: "internal" value: 20 - type: "local" value: 10 - type: "external" value: 66 bestpath: as_path: "confed" compare_routerid: true default: no_ipv4_unicast: true neighbor: - address: "192.0.2.43" disable_connected_check: true advertisement_interval: 72 capability: dynamic: true timers: holdtime: 30 keepalive: 10 - address: "203.0.113.0" capability: orf: "receive" state: rendered # Module Execution: # "rendered": [ # "set protocols bgp 65536 neighbor 192.0.2.43 disable-connected-check", # "set protocols bgp 65536 neighbor 192.0.2.43 advertisement-interval 72", # "set protocols bgp 65536 neighbor 192.0.2.43 capability dynamic", # "set protocols bgp 65536 neighbor 192.0.2.43 timers holdtime 30", # "set protocols bgp 65536 neighbor 192.0.2.43 timers keepalive 10", # "set protocols bgp 65536 neighbor 203.0.113.0 capability orf prefix-list receive", # "set protocols bgp 65536 redistribute static route-map map01", # "set protocols bgp 65536 network 203.0.113.0/24 route-map map01", # "set protocols bgp 65536 parameters always-compare-med", # "set protocols bgp 65536 parameters dampening half-life 33", # "set protocols bgp 65536 parameters dampening max-suppress-time 20", # "set protocols bgp 65536 parameters dampening re-use 60", # "set protocols bgp 65536 parameters dampening start-suppress-time 5", # "set protocols bgp 65536 parameters distance global internal 20", # "set protocols bgp 65536 parameters distance global local 10", # "set protocols bgp 65536 parameters distance global external 66", # "set protocols bgp 65536 parameters bestpath as-path confed", # "set protocols bgp 65536 parameters bestpath compare-routerid", # "set protocols bgp 65536 parameters default no-ipv4-unicast" # ] Return Values ------------- Common return values are documented `here `_, the following are the fields unique to this module: .. raw:: html
Key Returned Description
after
dictionary
when changed
The resulting configuration after module execution.

Sample:
This output will always be in the same format as the module argspec.
before
dictionary
when state is merged, replaced, overridden, deleted or purged
The configuration prior to the module execution.

Sample:
This output will always be in the same format as the module argspec.
commands
list
when state is merged, replaced, overridden, deleted or purged
The set of commands pushed to the remote device.

Sample:
['set protocols bgp 65536 redistribute static route-map map01', 'set protocols bgp 65536 network 203.0.113.0/24 route-map map01', 'set protocols bgp 65536 parameters always-compare-med']
gathered
list
when state is gathered
Facts about the network resource gathered from the remote device as structured data.

Sample:
This output will always be in the same format as the module argspec.
parsed
list
when state is parsed
The device native config provided in running_config option parsed into structured data as per module argspec.

Sample:
This output will always be in the same format as the module argspec.
rendered
list
when state is rendered
The provided configuration in the task rendered in device-native format (offline).

Sample:
['set protocols bgp 65536 redistribute static route-map map01', 'set protocols bgp 65536 network 203.0.113.0/24 route-map map01', 'set protocols bgp 65536 parameters always-compare-med']


Status ------ Authors ~~~~~~~ - Gomathi Selvi Srinivasan (@GomathiselviS) diff --git a/plugins/module_utils/network/vyos/argspec/bgp_global/bgp_global.py b/plugins/module_utils/network/vyos/argspec/bgp_global/bgp_global.py index b647ea91..42fb5abf 100644 --- a/plugins/module_utils/network/vyos/argspec/bgp_global/bgp_global.py +++ b/plugins/module_utils/network/vyos/argspec/bgp_global/bgp_global.py @@ -1,278 +1,173 @@ # -*- coding: utf-8 -*- # Copyright 2024 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function __metaclass__ = type ############################################# # WARNING # ############################################# # # This file is auto generated by the # cli_rm_builder. # # Manually editing this file is not advised. # # To update the argspec make the desired changes # in the module docstring and re-run # cli_rm_builder. # ############################################# """ The arg spec for the vyos_bgp_global module """ class Bgp_globalArgs(object): # pylint: disable=R0903 """The arg spec for the vyos_bgp_global module""" argument_spec = { "config": { "type": "dict", "options": { "as_number": {"type": "int"}, - "aggregate_address": { - "type": "list", - "elements": "dict", - "options": { - "prefix": {"type": "str"}, - "as_set": {"type": "bool"}, - "summary_only": {"type": "bool"}, - }, - }, - "maximum_paths": { - "type": "list", - "elements": "dict", - "options": {"path": {"type": "str"}, "count": {"type": "int"}}, - }, "neighbor": { "type": "list", "elements": "dict", "options": { "address": {"type": "str"}, "advertisement_interval": {"type": "int"}, - "allowas_in": {"type": "int"}, - "as_override": {"type": "bool"}, - "attribute_unchanged": { - "type": "dict", - "options": { - "as_path": {"type": "bool"}, - "med": {"type": "bool"}, - "next_hop": {"type": "bool"}, - }, - }, "capability": { "type": "dict", "options": { "dynamic": {"type": "bool"}, - "orf": { - "type": "str", - "choices": ["send", "receive"], - }, + "extended_nexthop": {"type": "bool"}, }, }, "default_originate": {"type": "str"}, "description": {"type": "str"}, "disable_capability_negotiation": {"type": "bool"}, "disable_connected_check": {"type": "bool"}, "disable_send_community": { "type": "str", "choices": ["extended", "standard"], }, - "distribute_list": { - "type": "list", - "elements": "dict", - "options": { - "action": { - "type": "str", - "choices": ["export", "import"], - }, - "acl": {"type": "int"}, - }, - }, "ebgp_multihop": {"type": "int"}, - "filter_list": { - "type": "list", - "elements": "dict", - "options": { - "action": { - "type": "str", - "choices": ["export", "import"], - }, - "path_list": {"type": "str"}, - }, - }, "local_as": {"type": "int"}, - "maximum_prefix": {"type": "int"}, - "nexthop_self": {"type": "bool"}, "override_capability": {"type": "bool"}, "passive": {"type": "bool"}, "password": {"type": "str", "no_log": True}, "peer_group_name": {"type": "str"}, "peer_group": {"type": "bool"}, "port": {"type": "int"}, - "prefix_list": { - "type": "list", - "elements": "dict", - "options": { - "action": { - "type": "str", - "choices": ["export", "import"], - }, - "prefix_list": {"type": "str"}, - }, - }, "remote_as": {"type": "int"}, - "remove_private_as": {"type": "bool"}, - "route_map": { - "type": "list", - "elements": "dict", - "options": { - "action": { - "type": "str", - "choices": ["export", "import"], - }, - "route_map": {"type": "str"}, - }, - }, - "route_reflector_client": {"type": "bool"}, - "route_server_client": {"type": "bool"}, + "solo": {"type": "bool"}, "shutdown": {"type": "bool"}, - "soft_reconfiguration": {"type": "bool"}, "strict_capability_match": {"type": "bool"}, - "unsuppress_map": {"type": "str"}, - "update_source": {"type": "str"}, - "weight": {"type": "int"}, - "ttl_security": {"type": "int"}, "timers": { "type": "dict", "options": { "connect": {"type": "int"}, "holdtime": {"type": "int"}, "keepalive": {"type": "int"}, }, }, - }, - }, - "network": { - "type": "list", - "elements": "dict", - "options": { - "address": {"type": "str"}, - "backdoor": {"type": "bool"}, - "route_map": {"type": "str"}, - }, - }, - "redistribute": { - "type": "list", - "elements": "dict", - "options": { - "protocol": { - "type": "str", - "choices": [ - "connected", - "kernel", - "ospf", - "rip", - "static", - ], - }, - "route_map": {"type": "str"}, - "metric": {"type": "int"}, + "ttl_security": {"type": "int"}, + "update_source": {"type": "str"}, }, }, "timers": { "type": "dict", "options": { "keepalive": {"type": "int"}, "holdtime": {"type": "int"}, }, }, "bgp_params": { "type": "dict", "options": { "always_compare_med": {"type": "bool"}, "bestpath": { "type": "dict", "options": { "as_path": { "type": "str", "choices": ["confed", "ignore"], }, "compare_routerid": {"type": "bool"}, "med": { "type": "str", "choices": ["confed", "missing-as-worst"], }, }, }, "cluster_id": {"type": "str"}, "confederation": { "type": "list", "elements": "dict", "options": { "identifier": {"type": "int"}, "peers": {"type": "int"}, }, }, "dampening": { "type": "dict", "options": { "half_life": {"type": "int"}, "max_suppress_time": {"type": "int"}, "re_use": {"type": "int"}, "start_suppress_time": {"type": "int"}, }, }, "default": { "type": "dict", "options": { "local_pref": {"type": "int"}, "no_ipv4_unicast": {"type": "bool"}, }, }, "deterministic_med": {"type": "bool"}, "disable_network_import_check": {"type": "bool"}, "distance": { "type": "list", "elements": "dict", "options": { "type": { "type": "str", "choices": ["external", "internal", "local"], }, "value": {"type": "int"}, "prefix": {"type": "int"}, }, }, "enforce_first_as": {"type": "bool"}, "graceful_restart": {"type": "int"}, "log_neighbor_changes": {"type": "bool"}, "no_client_to_client_reflection": {"type": "bool"}, "no_fast_external_failover": {"type": "bool"}, "router_id": {"type": "str"}, "scan_time": {"type": "int"}, }, }, }, }, "state": { "type": "str", "choices": [ "deleted", "merged", "purged", "replaced", "gathered", "rendered", "parsed", ], "default": "merged", }, "running_config": {"type": "str"}, } # pylint: disable=C0301 diff --git a/plugins/module_utils/network/vyos/config/bgp_address_family/bgp_address_family.py b/plugins/module_utils/network/vyos/config/bgp_address_family/bgp_address_family.py index 1b075adb..0e6bec81 100644 --- a/plugins/module_utils/network/vyos/config/bgp_address_family/bgp_address_family.py +++ b/plugins/module_utils/network/vyos/config/bgp_address_family/bgp_address_family.py @@ -1,355 +1,407 @@ # # -*- coding: utf-8 -*- # Copyright 2021 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # from __future__ import absolute_import, division, print_function __metaclass__ = type """ The vyos_bgp_address_family config file. It is in this file where the current configuration (as dict) is compared to the provided configuration (as dict) and the command set necessary to bring the current configuration to its desired end-state is created. """ import re from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( dict_merge, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_address_family import ( Bgp_address_familyTemplate, ) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_address_family_14 import ( + Bgp_address_familyTemplate14, +) + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_os_version + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.version import LooseVersion + class Bgp_address_family(ResourceModule): """ The vyos_bgp_address_family config class """ def __init__(self, module): super(Bgp_address_family, self).__init__( empty_fact_val={}, facts_module=Facts(module), module=module, resource="bgp_address_family", tmplt=Bgp_address_familyTemplate(), ) self.parsers = [] + def _validate_template(self): + version = get_os_version(self._module) + if LooseVersion(version) >= LooseVersion("1.4"): + self._tmplt = Bgp_address_familyTemplate14() + else: + self._tmplt = Bgp_address_familyTemplate() + + def parse(self): + """ override parse to check template """ + self._validate_template() + return super().parse() + + def get_parser(self, name): + """get_parsers""" + self._validate_template() + return super().get_parser(name) + def execute_module(self): """Execute the module :rtype: A dictionary :returns: The result from module execution """ + self._validate_template() if self.state not in ["parsed", "gathered"]: self.generate_commands() self.run_commands() return self.result def generate_commands(self): """Generate configuration commands to send based on want, have and desired state. """ wantd = {} haved = {} - if self.want.get("as_number") == self.have.get("as_number") or not self.have: + if (self.want.get("as_number") == self.have.get("as_number") or + not self.have or + LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4")): if self.want: wantd = {self.want["as_number"]: self.want} if self.have: haved = {self.have["as_number"]: self.have} else: self._module.fail_json(msg="Only one bgp instance is allowed per device") # turn all lists of dicts into dicts prior to merge for entry in wantd, haved: self._bgp_af_list_to_dict(entry) # if state is merged, merge want onto have and then compare if self.state == "merged": wantd = dict_merge(haved, wantd) # if state is deleted, empty out wantd and set haved to wantd if self.state == "deleted": for k, have in iteritems(haved): self._delete_af(wantd, have) wantd = {} if self.state == "overridden": for k, have in iteritems(haved): if k not in wantd: self._compare(want={}, have=have) for k, want in iteritems(wantd): self._compare(want=want, have=haved.pop(k, {})) def _compare(self, want, have): """Leverages the base class `compare()` method and populates the list of commands to be run by comparing the `want` and `have` data with the `parsers` defined for the Bgp_address_family network resource. """ + if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"): + self._compare_asn(want, have) + self._compare_af(want, have) self._compare_neighbors(want, have) # Do the negation first command_set = [] for cmd in self.commands: if cmd not in command_set: if "delete" in cmd: command_set.insert(0, cmd) else: command_set.append(cmd) self.commands = command_set def _compare_af(self, want, have): waf = want.get("address_family", {}) haf = have.get("address_family", {}) for name, entry in iteritems(waf): self._compare_lists( entry, have=haf.get(name, {}), as_number=want["as_number"], afi=name, ) for name, entry in iteritems(haf): if name not in waf.keys() and self.state == "replaced": continue self._compare_lists({}, entry, as_number=have["as_number"], afi=name) def _delete_af(self, want, have): for as_num, entry in iteritems(want): for afi, af_entry in iteritems(entry.get("address_family", {})): if have.get("address_family"): for hafi, hentry in iteritems(have["address_family"]): if hafi == afi: self.commands.append( self._tmplt.render( { "as_number": as_num, "address_family": {"afi": afi}, }, "address_family", True, ), ) for neigh, neigh_entry in iteritems(entry.get("neighbors", {})): if have.get("neighbors"): for hneigh, hnentry in iteritems(have["neighbors"]): if hneigh == neigh: if not neigh_entry.get("address_family"): self.commands.append( self._tmplt.render( { "as_number": as_num, "neighbors": {"neighbor_address": neigh}, }, "neighbors", True, ), ) else: for k in neigh_entry["address_family"].keys(): if ( hnentry.get("address_family") and k in hnentry["address_family"].keys() ): self.commands.append( self._tmplt.render( { "as_number": as_num, "neighbors": { "neighbor_address": neigh, "address_family": {"afi": k}, }, }, "neighbors.address_family", True, ), ) def _compare_neighbors(self, want, have): parsers = [ "neighbors.allowas_in", "neighbors.as_override", "neighbors.attribute_unchanged.as_path", "neighbors.attribute_unchanged.med", "neighbors.attribute_unchanged.next_hop", "neighbors.capability_dynamic", "neighbors.capability_orf", "neighbors.default_originate", "neighbors.distribute_list", "neighbors.prefix_list", "neighbors.filter_list", "neighbors.maximum_prefix", "neighbors.nexthop_local", "neighbors.nexthop_self", "neighbors.peer_group", "neighbors.remove_private_as", "neighbors.route_map", "neighbors.route_reflector_client", "neighbors.route_server_client", "neighbors.soft_reconfiguration", "neighbors.unsuppress_map", "neighbors.weight", ] wneigh = want.get("neighbors", {}) hneigh = have.get("neighbors", {}) for name, entry in iteritems(wneigh): for afi, af_entry in iteritems(entry.get("address_family")): for k, val in iteritems(af_entry): w = { "as_number": want["as_number"], "neighbors": { "neighbor_address": name, "address_family": {"afi": afi, k: val}, }, } h = {} if hneigh.get(name): if hneigh[name]["address_family"].get(afi): if hneigh[name]["address_family"][afi].get(k): h = { "as_number": want["as_number"], "neighbors": { "neighbor_address": name, "address_family": { "afi": afi, k: hneigh[name]["address_family"][afi].pop(k, {}), }, }, } self.compare( parsers=parsers, want=w, have=h, ) for name, entry in iteritems(hneigh): if name not in wneigh.keys(): # remove surplus config for overridden and replaced if self.state != "replaced": self.commands.append( self._tmplt.render( { "as_number": have["as_number"], "neighbors": {"neighbor_address": name}, }, "neighbors", True, ), ) continue for hafi, haf_entry in iteritems(entry.get("address_family")): # remove surplus configs for given neighbor - replace and overridden for k, val in iteritems(haf_entry): h = { "as_number": have["as_number"], "neighbors": { "neighbor_address": name, "address_family": {"afi": hafi, k: val}, }, } self.compare(parsers=parsers, want={}, have=h) def _compare_lists(self, want, have, as_number, afi): parsers = [ "aggregate_address", + "network", "network.backdoor", "network.path_limit", "network.route_map", + "redistribute", "redistribute.metric", "redistribute.route_map", "redistribute.table", ] + + if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"): + delete_asn = "" + else: + delete_asn = " " + str(as_number) + for attrib in ["redistribute", "networks", "aggregate_address"]: wdict = want.pop(attrib, {}) hdict = have.pop(attrib, {}) for key, entry in iteritems(wdict): if entry != hdict.get(key, {}): self.compare( parsers=parsers, want={ "as_number": as_number, "address_family": {"afi": afi, attrib: entry}, }, have={ "as_number": as_number, "address_family": { "afi": afi, attrib: hdict.pop(key, {}), }, }, ) hdict.pop(key, {}) # remove remaining items in have for replaced if not wdict and hdict: attrib = re.sub("_", "-", attrib) attrib = re.sub("networks", "network", attrib) self.commands.append( - "delete protocols bgp " - + str(as_number) + "delete protocols bgp" + + delete_asn + " " + "address-family " + afi + " " + attrib, ) hdict = {} for key, entry in iteritems(hdict): self.compare( parsers=parsers, want={}, have={ "as_number": as_number, "address_family": {"afi": afi, attrib: entry}, }, ) + # de-duplicate child commands if parent command is present + for val in (self.commands): + for val2 in self.commands: + if val != val2 and val2.startswith(val): + self.commands.remove(val2) + + def _compare_asn(self, want, have): + if want.get("as_number") and not have.get("as_number"): + self.commands.append( + "set protocols bgp " + + "system-as " + + str(want.get("as_number")), + ) def _bgp_af_list_to_dict(self, entry): for name, proc in iteritems(entry): if "address_family" in proc: af_dict = {} for entry in proc.get("address_family"): if "networks" in entry: network_dict = {} for n_entry in entry.get("networks", []): network_dict.update({n_entry["prefix"]: n_entry}) entry["networks"] = network_dict if "aggregate_address" in entry: agg_dict = {} for a_entry in entry.get("aggregate_address", []): agg_dict.update({a_entry["prefix"]: a_entry}) entry["aggregate_address"] = agg_dict if "redistribute" in entry: redis_dict = {} for r_entry in entry.get("redistribute", []): proto_key = r_entry.get("protocol", "table") redis_dict.update({proto_key: r_entry}) entry["redistribute"] = redis_dict for af in proc.get("address_family"): af_dict.update({af["afi"]: af}) proc["address_family"] = af_dict if "neighbors" in proc: neigh_dict = {} for entry in proc.get("neighbors", []): neigh_dict.update({entry["neighbor_address"]: entry}) proc["neighbors"] = neigh_dict self._bgp_af_list_to_dict(proc["neighbors"]) diff --git a/plugins/module_utils/network/vyos/config/bgp_global/bgp_global.py b/plugins/module_utils/network/vyos/config/bgp_global/bgp_global.py index c4a85020..91a5af12 100644 --- a/plugins/module_utils/network/vyos/config/bgp_global/bgp_global.py +++ b/plugins/module_utils/network/vyos/config/bgp_global/bgp_global.py @@ -1,407 +1,417 @@ # # -*- coding: utf-8 -*- # Copyright 2021 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # from __future__ import absolute_import, division, print_function __metaclass__ = type """ The vyos_bgp_global config file. It is in this file where the current configuration (as dict) is compared to the provided configuration (as dict) and the command set necessary to bring the current configuration to its desired end-state is created. """ -import re from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module import ( ResourceModule, ) from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import ( dict_merge, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import Facts from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_global import ( Bgp_globalTemplate, ) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_global_14 import ( + Bgp_globalTemplate14, +) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.version import ( + LooseVersion, +) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_os_version class Bgp_global(ResourceModule): """ The vyos_bgp_global config class """ def __init__(self, module): super(Bgp_global, self).__init__( empty_fact_val={}, facts_module=Facts(module), module=module, resource="bgp_global", tmplt=Bgp_globalTemplate(), ) self.parsers = [] + def _validate_template(self): + version = get_os_version(self._module) + if LooseVersion(version) >= LooseVersion("1.4"): + self._tmplt = Bgp_globalTemplate14() + else: + self._tmplt = Bgp_globalTemplate() + + def parse(self): + """override parse to check template""" + self._validate_template() + return super().parse() + + def get_parser(self, name): + """get_parsers""" + self._validate_template() + return super().get_parser(name) + def execute_module(self): """Execute the module :rtype: A dictionary :returns: The result from module execution """ + version = get_os_version(self._module) + if LooseVersion(version) >= LooseVersion("1.4"): + self._asn_mod = "" + else: + self._asn_mod = " " + str(self.have.get("as_number")) + self._validate_template() if self.state not in ["parsed", "gathered"]: self.generate_commands() self.run_commands() return self.result def generate_commands(self): """Generate configuration commands to send based on want, have and desired state. """ wantd = {} haved = {} - if self.want.get("as_number") == self.have.get("as_number") or not self.have: + if ( + self.want.get("as_number") == self.have.get("as_number") + or not self.have + or LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4") + ): if self.want: wantd = {self.want["as_number"]: self.want} if self.have: haved = {self.have["as_number"]: self.have} else: self._module.fail_json(msg="Only one bgp instance is allowed per device") # turn all lists of dicts into dicts prior to merge for entry in wantd, haved: self._bgp_global_list_to_dict(entry) # if state is merged, merge want onto have and then compare if self.state == "merged": wantd = dict_merge(haved, wantd) # if state is deleted, empty out wantd and set haved to wantd if self.state == "purged": h_del = {} for k, v in iteritems(haved): if k in wantd or not wantd: h_del.update({k: v}) for num, entry in iteritems(h_del): self.commands.append(self._tmplt.render({"as_number": num}, "router", True)) wantd = {} if self.state == "deleted": self._compare(want={}, have=self.have) wantd = {} for k, want in iteritems(wantd): self._compare(want=want, have=haved.pop(k, {})) def _compare(self, want, have): """Leverages the base class `compare()` method and populates the list of commands to be run by comparing the `want` and `have` data with the `parsers` defined for the Bgp_global network resource. """ + if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"): + self._compare_asn(want, have) + parsers = ["maximum_paths", "timers"] self._compare_neighbor(want, have) - self._compare_lists(want, have) self._compare_bgp_params(want, have) for name, entry in iteritems(want): if name != "as_number": self.compare( parsers=parsers, want={"as_number": want["as_number"], name: entry}, have={ "as_number": want["as_number"], name: have.pop(name, {}), }, ) for name, entry in iteritems(have): if name != "as_number": self.compare( parsers=parsers, want={}, have={"as_number": have["as_number"], name: entry}, ) # Do the negation first command_set = [] for cmd in self.commands: if cmd not in command_set: if "delete" in cmd: command_set.insert(0, cmd) else: command_set.append(cmd) self.commands = command_set def _compare_neighbor(self, want, have): parsers = [ "neighbor.advertisement_interval", "neighbor.allowas_in", "neighbor.as_override", "neighbor.attribute_unchanged.as_path", "neighbor.attribute_unchanged.med", "neighbor.attribute_unchanged.next_hop", "neighbor.capability_dynamic", "neighbor.capability_orf", "neighbor.default_originate", "neighbor.description", "neighbor.disable_capability_negotiation", "neighbor.disable_connected_check", "neighbor.disable_send_community", "neighbor.distribute_list", "neighbor.ebgp_multihop", "neighbor.filter_list", "neighbor.local_as", "neighbor.maximum_prefix", "neighbor.nexthop_self", "neighbor.override_capability", "neighbor.passive", "neighbor.password", "neighbor.peer_group_name", "neighbor.port", "neighbor.prefix_list", "neighbor.remote_as", "neighbor.remove_private_as", "neighbor.route_map", "neighbor.route_reflector_client", "neighbor.route_server_client", "neighbor.shutdown", "neighbor.soft_reconfiguration", "neighbor.strict_capability_match", "neighbor.unsuppress_map", "neighbor.update_source", "neighbor.weight", "neighbor.ttl_security", "neighbor.timers", - "network.backdoor", - "network.route_map", ] + wneigh = want.pop("neighbor", {}) hneigh = have.pop("neighbor", {}) self._compare_neigh_lists(wneigh, hneigh) + for name, entry in iteritems(wneigh): for k, v in entry.items(): if k == "address": continue if hneigh.get(name): h = {"address": name, k: hneigh[name].pop(k, {})} else: h = {} self.compare( parsers=parsers, want={ "as_number": want["as_number"], "neighbor": {"address": name, k: v}, }, have={"as_number": want["as_number"], "neighbor": h}, ) for name, entry in iteritems(hneigh): if name not in wneigh.keys(): if self._check_af(name): msg = "Use the _bgp_address_family module to delete the address_family under neighbor {0}, before replacing/deleting the neighbor.".format( name, ) self._module.fail_json(msg=msg) else: self.commands.append( - "delete protocols bgp " + str(have["as_number"]) + " neighbor " + name, + "delete protocols bgp" + self._asn_mod + " neighbor " + name, ) continue for k, v in entry.items(): self.compare( parsers=parsers, want={}, have={ "as_number": have["as_number"], "neighbor": {"address": name, k: v}, }, ) def _compare_bgp_params(self, want, have): parsers = [ "bgp_params.always_compare_med", "bgp_params.bestpath.as_path", "bgp_params.bestpath.compare_routerid", "bgp_params.bestpath.med", "bgp_params.cluster_id", "bgp_params.confederation", "bgp_params.dampening_half_life", "bgp_params.dampening_max_suppress_time", "bgp_params.dampening_re_use", "bgp_params.dampening_start_suppress_time", "bgp_params.default", "bgp_params.deterministic_med", "bgp_params.disbale_network_import_check", "bgp_params.enforce_first_as", "bgp_params.graceful_restart", "bgp_params.log_neighbor_changes", "bgp_params.no_client_to_client_reflection", "bgp_params.no_fast_external_failover", "bgp_params.routerid", "bgp_params.scan_time", ] + wbgp = want.pop("bgp_params", {}) hbgp = have.pop("bgp_params", {}) for name, entry in iteritems(wbgp): if name == "confederation": if entry != hbgp.pop(name, {}): self.addcmd( { "as_number": want["as_number"], "bgp_params": {name: entry}, }, "bgp_params.confederation", False, ) elif name == "distance": if entry != hbgp.pop(name, {}): distance_parsers = [ "bgp_params.distance.global", "bgp_params.distance.prefix", ] for distance_type in entry: self.compare( parsers=distance_parsers, want={ "as_number": want["as_number"], "bgp_params": {name: distance_type}, }, have={ "as_number": want["as_number"], "bgp_params": {name: hbgp.pop(name, {})}, }, ) else: self.compare( parsers=parsers, want={ "as_number": want["as_number"], "bgp_params": {name: entry}, }, have={ "as_number": want["as_number"], "bgp_params": {name: hbgp.pop(name, {})}, }, ) if not wbgp and hbgp: - self.commands.append("delete protocols bgp " + str(have["as_number"]) + " parameters") + self.commands.append("delete protocols bgp" + self._asn_mod + " parameters") hbgp = {} for name, entry in iteritems(hbgp): if name == "confederation": self.commands.append( - "delete protocols bgp " + str(have["as_number"]) + " parameters confederation", + "delete protocols bgp" + self._asn_mod + " parameters confederation", ) elif name == "distance": distance_parsers = [ "bgp_params.distance.global", "bgp_params.distance.prefix", ] self.compare( parsers=distance_parsers, want={}, have={ "as_number": have["as_number"], "bgp_params": {name: entry[0]}, }, ) else: self.compare( parsers=parsers, want={}, have={ "as_number": have["as_number"], "bgp_params": {name: entry}, }, ) - def _compare_lists(self, want, have): - parsers = [ - "network.backdoor", - "network.route_map", - "redistribute.metric", - "redistribute.route_map", - "aggregate_address", - ] - for attrib in ["redistribute", "network", "aggregate_address"]: - wdict = want.pop(attrib, {}) - hdict = have.pop(attrib, {}) - for key, entry in iteritems(wdict): - if entry != hdict.get(key, {}): - self.compare( - parsers=parsers, - want={"as_number": want["as_number"], attrib: entry}, - have=hdict.pop(key, {}), - ) - hdict.pop(key, {}) - # remove remaining items in have for replaced - if not wdict and hdict: - attrib = re.sub("_", "-", attrib) - self.commands.append( - "delete protocols bgp " + str(have["as_number"]) + " " + attrib, - ) - hdict = {} - for key, entry in iteritems(hdict): - self.compare( - parsers=parsers, - want={}, - have={"as_number": have["as_number"], attrib: entry}, - ) - def _compare_neigh_lists(self, want, have): for attrib in [ "distribute_list", "filter_list", "prefix_list", "route_map", ]: wdict = want.pop(attrib, {}) hdict = have.pop(attrib, {}) for key, entry in iteritems(wdict): if entry != hdict.pop(key, {}): self.addcmd(entry, "neighbor.{0}".format(attrib), False) # remove remaining items in have for replaced for entry in hdict.values(): self.addcmd(entry, "neighbor.{0}".format(attrib), True) def _bgp_global_list_to_dict(self, entry): for name, proc in iteritems(entry): if "neighbor" in proc: neigh_dict = {} for entry in proc.get("neighbor", []): neigh_dict.update({entry["address"]: entry}) proc["neighbor"] = neigh_dict if "network" in proc: network_dict = {} for entry in proc.get("network", []): network_dict.update({entry["address"]: entry}) proc["network"] = network_dict if "aggregate_address" in proc: agg_dict = {} for entry in proc.get("aggregate_address", []): agg_dict.update({entry["prefix"]: entry}) proc["aggregate_address"] = agg_dict if "redistribute" in proc: redis_dict = {} for entry in proc.get("redistribute", []): redis_dict.update({entry["protocol"]: entry}) proc["redistribute"] = redis_dict + def _compare_asn(self, want, have): + if want.get("as_number") and not have.get("as_number"): + self.commands.append( + "set protocols bgp " + "system-as" + " " + str(want.get("as_number")), + ) + def _check_af(self, neighbor): af_present = False if self._connection: config_lines = self._get_config(self._connection).splitlines() for line in config_lines: - if "address-family" in line: - af_present = True + if neighbor in line: + if "address-family" in line: + af_present = True return af_present def _get_config(self, connection): return connection.get( - 'show configuration commands | match "set protocols bgp .* neighbor"', + 'show configuration commands | match "set protocols bgp .*neighbor"', ) diff --git a/plugins/module_utils/network/vyos/facts/bgp_address_family/bgp_address_family.py b/plugins/module_utils/network/vyos/facts/bgp_address_family/bgp_address_family.py index 629ffc50..3386bd66 100644 --- a/plugins/module_utils/network/vyos/facts/bgp_address_family/bgp_address_family.py +++ b/plugins/module_utils/network/vyos/facts/bgp_address_family/bgp_address_family.py @@ -1,89 +1,99 @@ # -*- coding: utf-8 -*- # Copyright 2021 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function __metaclass__ = type """ The vyos bgp_address_family fact class It is in this file the configuration is collected from the device for a given resource, parsed, and the facts tree is populated based on the configuration. """ import re from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.bgp_address_family.bgp_address_family import ( Bgp_address_familyArgs, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_address_family import ( Bgp_address_familyTemplate, ) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_address_family_14 import ( + Bgp_address_familyTemplate14, +) + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_os_version + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.version import LooseVersion class Bgp_address_familyFacts(object): """The vyos bgp_address_family facts class""" def __init__(self, module, subspec="config", options="options"): self._module = module self.argument_spec = Bgp_address_familyArgs.argument_spec def get_device_data(self, connection): return connection.get('show configuration commands | match "set protocols bgp"') def populate_facts(self, connection, ansible_facts, data=None): """Populate the facts for Bgp_address_family network resource :param connection: the device connection :param ansible_facts: Facts dictionary :param data: previously collected conf :rtype: dictionary :returns: facts """ facts = {} objs = [] config_lines = [] if not data: data = self.get_device_data(connection) for resource in data.splitlines(): - if "address-family" in resource: + if "address-family" in resource or "system-as" in resource: config_lines.append(re.sub("'", "", resource)) - # parse native config using the Bgp_address_family template - bgp_address_family_parser = Bgp_address_familyTemplate(lines=config_lines) + # parse native config using the Bgp_address_family template based on version + if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"): + bgp_address_family_parser = Bgp_address_familyTemplate14(lines=config_lines) + else: + bgp_address_family_parser = Bgp_address_familyTemplate(lines=config_lines) objs = bgp_address_family_parser.parse() if objs: if "address_family" in objs: objs["address_family"] = list(objs["address_family"].values()) for af in objs["address_family"]: if "networks" in af: af["networks"] = sorted(af["networks"], key=lambda k: k["prefix"]) if "aggregate_address" in af: af["aggregate_address"] = sorted( af["aggregate_address"], key=lambda k: k["prefix"], ) if "neighbors" in objs: objs["neighbors"] = list(objs["neighbors"].values()) objs["neighbors"] = sorted(objs["neighbors"], key=lambda k: k["neighbor_address"]) for neigh in objs["neighbors"]: if "address_family" in neigh: neigh["address_family"] = list(neigh["address_family"].values()) ansible_facts["ansible_network_resources"].pop("bgp_address_family", None) params = utils.remove_empties(utils.validate_config(self.argument_spec, {"config": objs})) facts["bgp_address_family"] = params.get("config", []) ansible_facts["ansible_network_resources"].update(facts) return ansible_facts diff --git a/plugins/module_utils/network/vyos/facts/bgp_global/bgp_global.py b/plugins/module_utils/network/vyos/facts/bgp_global/bgp_global.py index fe341357..dd793681 100644 --- a/plugins/module_utils/network/vyos/facts/bgp_global/bgp_global.py +++ b/plugins/module_utils/network/vyos/facts/bgp_global/bgp_global.py @@ -1,81 +1,93 @@ # -*- coding: utf-8 -*- # Copyright 2021 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function __metaclass__ = type """ The vyos bgp_global fact class It is in this file the configuration is collected from the device for a given resource, parsed, and the facts tree is populated based on the configuration. """ import re from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import utils from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.bgp_global.bgp_global import ( Bgp_globalArgs, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_global import ( Bgp_globalTemplate, ) +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_global_14 import ( + Bgp_globalTemplate14, +) + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import get_os_version + +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.utils.version import LooseVersion + class Bgp_globalFacts(object): """The vyos bgp_global facts class""" def __init__(self, module, subspec="config", options="options"): self._module = module self.argument_spec = Bgp_globalArgs.argument_spec def get_device_data(self, connection): return connection.get('show configuration commands | match "set protocols bgp"') def populate_facts(self, connection, ansible_facts, data=None): """Populate the facts for Bgp_global network resource :param connection: the device connection :param ansible_facts: Facts dictionary :param data: previously collected conf :rtype: dictionary :returns: facts """ facts = {} objs = {} config_lines = [] if not data: data = self.get_device_data(connection) for resource in data.splitlines(): if "address-family" not in resource: config_lines.append(re.sub("'", "", resource)) - bgp_global_parser = Bgp_globalTemplate(lines=config_lines, module=self._module) + if LooseVersion(get_os_version(self._module)) >= LooseVersion("1.4"): + bgp_global_parser = Bgp_globalTemplate14(lines=config_lines, module=self._module) + else: + bgp_global_parser = Bgp_globalTemplate(lines=config_lines, module=self._module) + objs = bgp_global_parser.parse() if "neighbor" in objs: objs["neighbor"] = list(objs["neighbor"].values()) objs["neighbor"] = sorted(objs["neighbor"], key=lambda k: k["address"]) if "network" in objs: objs["network"] = sorted(objs["network"], key=lambda k: k["address"]) if "aggregate_address" in objs: objs["aggregate_address"] = sorted(objs["aggregate_address"], key=lambda k: k["prefix"]) ansible_facts["ansible_network_resources"].pop("bgp_global", None) params = utils.remove_empties( bgp_global_parser.validate_config(self.argument_spec, {"config": objs}, redact=True), ) facts["bgp_global"] = params.get("config", []) ansible_facts["ansible_network_resources"].update(facts) return ansible_facts diff --git a/plugins/module_utils/network/vyos/rm_templates/bgp_address_family.py b/plugins/module_utils/network/vyos/rm_templates/bgp_address_family.py index c996a74a..f8f86cd2 100644 --- a/plugins/module_utils/network/vyos/rm_templates/bgp_address_family.py +++ b/plugins/module_utils/network/vyos/rm_templates/bgp_address_family.py @@ -1,1377 +1,1450 @@ # -*- coding: utf-8 -*- # Copyright 2021 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function __metaclass__ = type """ The Bgp_address_family parser templates file. This contains a list of parser definitions and associated functions that facilitates both facts gathering and native command generation for the given network resource. """ import re from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) def _tmplt_bgp_af_aggregate_address(config_data): afi = config_data["address_family"]["afi"] + "-unicast" command = "protocols bgp {as_number} address-family ".format(**config_data) config_data = config_data["address_family"] if config_data["aggregate_address"].get("as_set"): command += afi + " aggregate-address {prefix} as-set".format( **config_data["aggregate_address"], ) if config_data["aggregate_address"].get("summary_only"): command += afi + " aggregate-address {prefix} summary-only".format( **config_data["aggregate_address"], ) return command -def _tmplt_bgp_af_redistribute_metric(config_data): - if config_data["address_family"]["redistribute"].get("metric"): - afi = config_data["address_family"]["afi"] + "-unicast" - command = "protocols bgp {as_number} address-family ".format(**config_data) - if config_data["address_family"]["redistribute"].get("metric"): - command += afi + " redistribute {protocol} metric {metric}".format( - **config_data["address_family"]["redistribute"], - ) - return command - - -def _tmplt_bgp_af_redistribute_route_map(config_data): - if config_data["address_family"]["redistribute"].get("route_map"): - afi = config_data["address_family"]["afi"] + "-unicast" - command = "protocols bgp {as_number} address-family ".format(**config_data) - if config_data["address_family"]["redistribute"].get("route_map"): - command += afi + " redistribute {protocol} route-map {route_map}".format( - **config_data["address_family"]["redistribute"], - ) - return command - - -def _tmplt_bgp_af_redistribute_table(config_data): - if config_data["address_family"]["redistribute"].get("table"): - afi = config_data["address_family"]["afi"] + "-unicast" - command = "protocols bgp {as_number} address-family ".format(**config_data) - if config_data["address_family"]["redistribute"].get("table"): - command += afi + " table {table}".format( - **config_data["address_family"]["redistribute"], - ) - return command +def _tmplt_bgp_af_redistribute(config_data): + afi = config_data["address_family"]["afi"] + "-unicast" + command = "protocols bgp {as_number} address-family ".format(**config_data) + config_data = config_data["address_family"]["redistribute"] + command += afi + " redistribute {protocol}".format(**config_data) + if config_data.get("metric"): + command += " metric {metric}".format(**config_data) + elif config_data.get("route_map"): + command += " route-map {route_map}".format(**config_data) + elif config_data.get("table"): + command += " table {table}".format(**config_data) + return command -def _tmplt_bgp_af_delete_redistribute(config_data): +def _tmplt_bgp_af_redistribute_delete(config_data): afi = config_data["address_family"]["afi"] + "-unicast" command = "protocols bgp {as_number} address-family ".format(**config_data) - config_data = config_data["address_family"] - command += afi + " redistribute {protocol}".format(**config_data["redistribute"]) + config_data = config_data["address_family"]["redistribute"] + command += afi + " redistribute {protocol}".format(**config_data) + if config_data.get("metric"): + command += " metric" + elif config_data.get("route_map"): + command += " route-map" + elif config_data.get("table"): + command += " table" return command def _tmplt_bgp_af_neighbor_distribute_list(config_data): command = [] afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" cmd = "protocols bgp {as_number} neighbor ".format(**config_data) cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"]) config_data = config_data["neighbors"]["address_family"] for list_el in config_data["distribute_list"]: command.append( cmd + afi + " distribute-list " + list_el["action"] + " " + str(list_el["acl"]), ) return command def _tmplt_bgp_af_neighbor_route_map(config_data): command = [] afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" cmd = "protocols bgp {as_number} neighbor ".format(**config_data) cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"]) config_data = config_data["neighbors"]["address_family"] for list_el in config_data["route_map"]: command.append( cmd + afi + " route-map " + list_el["action"] + " " + str(list_el["route_map"]), ) return command def _tmplt_bgp_af_neighbor_prefix_list(config_data): command = [] afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" cmd = "protocols bgp {as_number} neighbor ".format(**config_data) cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"]) config_data = config_data["neighbors"]["address_family"] for list_el in config_data["prefix_list"]: command.append( cmd + afi + " prefix-list " + list_el["action"] + " " + str(list_el["prefix_list"]), ) return command def _tmplt_bgp_af_neighbor_filter_list(config_data): command = [] afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" cmd = "protocols bgp {as_number} neighbor ".format(**config_data) cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"]) config_data = config_data["neighbors"]["address_family"] for list_el in config_data["filter_list"]: command.append( cmd + afi + " filter-list " + list_el["action"] + " " + str(list_el["path_list"]), ) return command def _tmplt_bgp_af_neighbor_attribute(config_data): command = [] afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" cmd = "protocols bgp {as_number} neighbor ".format(**config_data) cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"]) config_data = config_data["neighbors"]["address_family"] for k in config_data["attribute_unchanged"].keys(): if config_data["attribute_unchanged"][k]: k = re.sub("_", "-", k) c = cmd + afi + " attribute-unchanged " + k command.append(c) return command def _tmplt_bgp_af_neighbor_delete(config_data): afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" command = "protocols bgp {as_number} ".format(**config_data) command += ( "neighbor {neighbor_address} address-family ".format(**config_data["neighbors"]) + afi ) config_data = config_data["neighbors"]["address_family"] if config_data.get("allowas_in"): command += " allowas-in" elif config_data.get("as_override"): command += " as-override" elif config_data.get("attribute_unchanged"): command += " attribute-unchanged" elif config_data.get("capability"): command += " capability" elif config_data.get("default_originate"): command += " default-originate" elif config_data.get("maximum_prefix"): command += " maximum-prefix" elif config_data.get("nexthop_local"): command += " nexthop-local" elif config_data.get("nexthop_self"): command += " nexthop-self" elif config_data.get("peer_group"): command += " peer-group" elif config_data.get("remote_private_as"): command += " remote-private-as" elif config_data.get("route_reflector_client"): command += " route-reflector-client" elif config_data.get("route_server_client"): command += " route-server-client" elif config_data.get("soft_reconfiguration"): command += " soft-reconfiguration" elif config_data.get("unsuppress_map"): command += " unsuppress-map" elif config_data.get("weight"): command += " weight" elif config_data.get("filter_list"): command += " filter-list" elif config_data.get("prefix_list"): command += " prefix-list" elif config_data.get("distribute_list"): command += " distribute-list" elif config_data.get("route_map"): command += " route-map" return command def _tmplt_bgp_af_neighbor(config_data): afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" command = "protocols bgp {as_number} ".format(**config_data) command += ( "neighbor {neighbor_address} address-family ".format(**config_data["neighbors"]) + afi ) config_data = config_data["neighbors"]["address_family"] if config_data.get("allowas_in"): command += " allowas-in number {allowas_in}".format(**config_data) elif config_data.get("as_override"): command += " as-override" elif config_data.get("capability"): command += " capability " if config_data["capability"].get("dynamic"): command += "dynamic" elif config_data["capability"].get("orf"): command += " prefix-list {orf}".format(**config_data["capability"]) elif config_data.get("default_originate"): command += " default-originate route-map {default_originate}".format(**config_data) elif config_data.get("maximum_prefix"): command += " maximum-prefix {maximum_prefix}".format(**config_data) elif config_data.get("nexthop_local"): command += " nexthop-local" elif config_data.get("nexthop_self"): command += " nexthop-self" elif config_data.get("peer_group"): command += " peer-group {peer_group}".format(**config_data) elif config_data.get("remote_private_as"): command += " remote-private-as" elif config_data.get("route_reflector_client"): command += " route-reflector-client" elif config_data.get("route_server_client"): command += " route-server-client" elif config_data.get("soft_reconfiguration"): command += " soft-reconfiguration inbound" elif config_data.get("unsuppress_map"): command += " unsuppress-map {unsuppress_map}".format(**config_data) elif config_data.get("weight"): command += " weight {weight}".format(**config_data) return command +def _tmplt_bgp_af_network(config_data): + afi = config_data["address_family"]["afi"] + "-unicast" + command = "protocols bgp {as_number} address-family ".format(**config_data) + config_data = config_data["address_family"]["networks"] + command += afi + " network {prefix}".format(**config_data) + if config_data.get("backdoor"): + command += " backdoor" + elif config_data.get("route_map"): + command += " route-map {route_map}".format(**config_data) + return command + + +def _tmplt_bgp_af_network_delete(config_data): + afi = config_data["address_family"]["afi"] + "-unicast" + command = "protocols bgp {as_number} address-family ".format(**config_data) + config_data = config_data["address_family"]["networks"] + command += afi + " network {prefix}".format(**config_data) + if config_data.get("backdoor"): + command += " backdoor" + elif config_data.get("route_map"): + command += " route_map" + return command + + class Bgp_address_familyTemplate(NetworkTemplate): def __init__(self, lines=None, module=None): prefix = {"set": "set", "remove": "delete"} super(Bgp_address_familyTemplate, self).__init__( lines=lines, tmplt=self, prefix=prefix, module=module, ) # fmt: off PARSERS = [ { "name": "address_family", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+address-family \s+(?P\S+)-unicast *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast", "compval": "as_number", "result": { "as_number": "{{ as_num }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", }, }, }, }, { "name": "aggregate_address", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+address-family \s+(?P\S+)-unicast \s+aggregate-address \s+(?P
\S+) \s*(?Pas-set)* \s*(?Psummary-only)* $""", re.VERBOSE, ), "setval": _tmplt_bgp_af_aggregate_address, "remval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast aggregate-address" + " {{ address_family.aggregate_address.prefix }}", "compval": "address_family.aggregate_address", "result": { "as_number": "{{ as_num }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "aggregate_address": [ { "prefix": "{{ address }}", "as_set": "{{ True if as_set is defined }}", "summary_only": "{{ True if summary_only is defined }}", }, ], }, }, }, }, + { + "name": "network", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+(?P\d+) + \s+address-family + \s+(?P\S+)-unicast + \s+network + \s+(?P
\S+) + $""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_network, + "remval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast network {{ address_family.networks.prefix }}", + "compval": "address_family.networks.prefix", + "result": { + "as_number": "{{ as_num }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "networks": [ + { + "prefix": "{{ address }}", + }, + ], + }, + }, + }, + }, { "name": "network.backdoor", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+address-family \s+(?P\S+)-unicast \s+network \s+(?P
\S+) \s+backdoor *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast network {{ address_family.networks.prefix }} backdoor", - "remval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast network {{ address_family.networks.prefix }}", + "setval": _tmplt_bgp_af_network, + "remval": _tmplt_bgp_af_network_delete, "compval": "address_family.networks.backdoor", "result": { "as_number": "{{ as_num }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "networks": [ { "prefix": "{{ address }}", "backdoor": "{{ True }}", }, ], }, }, }, }, { "name": "network.path_limit", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+address-family \s+(?P\S+)-unicast \s+network \s+(?P
\S+) \s+path-limit \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast network" + - "{{ address_family.networks.prefix }} path-limit {{ address_family.networks.path_limit }}", - "remval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast network {{ address_family.networks.address }}", + "setval": _tmplt_bgp_af_network, + "remval": _tmplt_bgp_af_network_delete, "compval": "address_family.networks.path_limit", "result": { "as_number": "{{ as_num }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "networks": [ { "prefix": "{{ address }}", "path_limit": "{{ limit|int }}", }, ], }, }, }, }, { "name": "network.route_map", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+address-family \s+(?P\S+)-unicast \s+network \s+(?P
\S+) \s+route-map \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast network" + - " {{ address_family.networks.prefix }} route-map {{ address_family.networks.route_map }}", - "remval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast network {{ address_family.networks.prefix }}", + "setval": _tmplt_bgp_af_network, + "remval": _tmplt_bgp_af_network_delete, "compval": "address_family.networks.route_map", "result": { "as_number": "{{ as_num }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "networks": [ { "prefix": "{{ address }}", "route_map": "{{ map }}", }, ], }, }, }, }, + { + "name": "redistribute", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+(?P\d+) + \s+address-family + \s+(?P\S+)-unicast + \s+redistribute + \s+(?P\S+) + $""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_redistribute, + "remval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast redistribute {{ address_family.redistribute.protocol }}", + "compval": "address_family.redistribute.protocol", + "result": { + "as_number": "{{ as_num }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "redistribute": [ + { + "protocol": "{{ proto }}", + }, + ], + }, + }, + }, + }, { "name": "redistribute.metric", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+address-family \s+(?P\S+)-unicast \s+redistribute \s+(?P\S+) \s+metric \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": _tmplt_bgp_af_redistribute_metric, - "remval": _tmplt_bgp_af_delete_redistribute, + "setval": _tmplt_bgp_af_redistribute, + "remval": _tmplt_bgp_af_redistribute_delete, "compval": "address_family.redistribute.metric", "result": { "as_number": "{{ as_num }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "redistribute": [ { "protocol": "{{ proto }}", "metric": "{{ val|int }}", }, ], }, }, }, }, { "name": "redistribute.route_map", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+address-family \s+(?P\S+)-unicast \s+redistribute \s+(?P\S+) \s+route-map \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": _tmplt_bgp_af_redistribute_route_map, - "remval": _tmplt_bgp_af_delete_redistribute, + "setval": _tmplt_bgp_af_redistribute, + "remval": _tmplt_bgp_af_redistribute_delete, "compval": "address_family.redistribute.route_map", "result": { "as_number": "{{ as_num }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "redistribute": [ { "protocol": "{{ proto }}", "route_map": "{{ map }}", }, ], }, }, }, }, { "name": "redistribute.table", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+address-family \s+(?P\S+)-unicast \s+redistribute \s+table \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": _tmplt_bgp_af_redistribute_table, - "remval": _tmplt_bgp_af_delete_redistribute, + "setval": _tmplt_bgp_af_redistribute, + "remval": _tmplt_bgp_af_redistribute_delete, "compval": "address_family.redistribute.table", "result": { "as_number": "{{ as_num }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "redistribute": [ { "table": "{{ tab }}", }, ], }, }, }, }, { "name": "neighbors", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbors.neighbor_address }} address-family", "compval": "neighbors", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", }, }, }, }, { "name": "neighbors.address_family", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbors.neighbor_address }} address-family {{ neighbors.address_family.afi }}-unicast", "compval": "neighbors", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", }, }, }, }, }, }, { "name": "neighbors.allowas_in", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+allowas-in \s+number \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.allowas_in", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "allowas_in": "{{ num }}", }, }, }, }, }, }, { "name": "neighbors.as_override", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+as-override *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.as_override", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "as_override": "{{ True }}", }, }, }, }, }, }, { "name": "neighbors.attribute_unchanged.as_path", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+attribute-unchanged \s+(?Pas-path) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor_attribute, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.attribute_unchanged.as_path", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "attribute_unchanged": { "as_path": "{{ True }}", }, }, }, }, }, }, }, { "name": "neighbors.attribute_unchanged.med", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+attribute-unchanged \s+(?Pmed) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor_attribute, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.attribute_unchanged.med", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "attribute_unchanged": { "med": "{{ True }}", }, }, }, }, }, }, }, { "name": "neighbors.attribute_unchanged.next_hop", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+attribute-unchanged \s+(?Pnext-hop) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor_attribute, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.attribute_unchanged.next_hop", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "attribute_unchanged": { "next_hop": "{{ True }}", }, }, }, }, }, }, }, { "name": "neighbors.capability_dynamic", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+capability \s+dynamic *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.capability.dynamic", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "capability": { "dynamic": "{{ true }}", }, }, }, }, }, }, }, { "name": "neighbors.capability_orf", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+capability \s+prefix-list \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.capability.orf", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "capability": { "orf": "{{ orf }}", }, }, }, }, }, }, }, { "name": "neighbors.default_originate", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+default-originate \s+route-map \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.default_originate", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "default_originate": "{{ map }}", }, }, }, }, }, }, { "name": "neighbors.distribute_list", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+distribute-list \s+(?Pexport|import) \s+(?P\d+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor_distribute_list, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.distribute_list", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "distribute_list": [ { "action": "{{ action }}", "acl": "{{ list }}", }, ], }, }, }, }, }, }, { "name": "neighbors.prefix_list", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+prefix-list \s+(?Pexport|import) \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor_prefix_list, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.prefix_list", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "prefix_list": [ { "action": "{{ action }}", "prefix_list": "{{ list }}", }, ], }, }, }, }, }, }, { "name": "neighbors.filter_list", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+filter-list \s+(?Pexport|import) \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor_filter_list, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.filter_list", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "filter_list": [ { "action": "{{ action }}", "path_list": "{{ list }}", }, ], }, }, }, }, }, }, { "name": "neighbors.maximum_prefix", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+maximum-prefix \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.maximum_prefix", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "maximum_prefix": "{{ num }}", }, }, }, }, }, }, { "name": "neighbors.nexthop_local", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+nexthop-local *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.nexthop_local", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "nexthop_local": "{{ True }}", }, }, }, }, }, }, { "name": "neighbors.nexthop_self", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+nexthop-self *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.nexthop_self", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "nexthop_self": "{{ True }}", }, }, }, }, }, }, { "name": "neighbors.peer_group", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+peer-group \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.peer_group", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "peer_group": "{{ name }}", }, }, }, }, }, }, { "name": "neighbors.remove_private_as", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+remove-private-as *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.remove_private_as", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "remove_private_as": "{{ True }}", }, }, }, }, }, }, { "name": "neighbors.route_map", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+route-map \s+(?Pexport|import) \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor_route_map, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.route_map", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "route_map": [ { "action": "{{ action }}", "route_map": "{{ map }}", }, ], }, }, }, }, }, }, { "name": "neighbors.route_reflector_client", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+route-reflector-client *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.route_reflector_client", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "route_reflector_client": "{{ True }}", }, }, }, }, }, }, { "name": "neighbors.route_server_client", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+route-server-client *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.route_server_client", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "route_server_client": "{{ True }}", }, }, }, }, }, }, { "name": "neighbors.soft_reconfiguration", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+soft-reconfiguration \s+inbound *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.soft_reconfiguration", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "soft_reconfiguration": "{{ True }}", }, }, }, }, }, }, { "name": "neighbors.unsuppress_map", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+unsuppress-map \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.unsuppress_map", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "unsuppress_map": "{{ map }}", }, }, }, }, }, }, { "name": "neighbors.weight", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+weight \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.weight", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "weight": "{{ num }}", }, }, }, }, }, }, ] # fmt: on diff --git a/plugins/module_utils/network/vyos/rm_templates/bgp_address_family.py b/plugins/module_utils/network/vyos/rm_templates/bgp_address_family_14.py similarity index 87% copy from plugins/module_utils/network/vyos/rm_templates/bgp_address_family.py copy to plugins/module_utils/network/vyos/rm_templates/bgp_address_family_14.py index c996a74a..fd4c9de9 100644 --- a/plugins/module_utils/network/vyos/rm_templates/bgp_address_family.py +++ b/plugins/module_utils/network/vyos/rm_templates/bgp_address_family_14.py @@ -1,1377 +1,1433 @@ # -*- coding: utf-8 -*- # Copyright 2021 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function __metaclass__ = type """ The Bgp_address_family parser templates file. This contains a list of parser definitions and associated functions that facilitates both facts gathering and native command generation for the given network resource. """ import re from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) def _tmplt_bgp_af_aggregate_address(config_data): afi = config_data["address_family"]["afi"] + "-unicast" - command = "protocols bgp {as_number} address-family ".format(**config_data) + command = "protocols bgp address-family ".format(**config_data) config_data = config_data["address_family"] if config_data["aggregate_address"].get("as_set"): command += afi + " aggregate-address {prefix} as-set".format( **config_data["aggregate_address"], ) if config_data["aggregate_address"].get("summary_only"): command += afi + " aggregate-address {prefix} summary-only".format( **config_data["aggregate_address"], ) return command -def _tmplt_bgp_af_redistribute_metric(config_data): - if config_data["address_family"]["redistribute"].get("metric"): - afi = config_data["address_family"]["afi"] + "-unicast" - command = "protocols bgp {as_number} address-family ".format(**config_data) - if config_data["address_family"]["redistribute"].get("metric"): - command += afi + " redistribute {protocol} metric {metric}".format( - **config_data["address_family"]["redistribute"], - ) - return command - - -def _tmplt_bgp_af_redistribute_route_map(config_data): - if config_data["address_family"]["redistribute"].get("route_map"): - afi = config_data["address_family"]["afi"] + "-unicast" - command = "protocols bgp {as_number} address-family ".format(**config_data) - if config_data["address_family"]["redistribute"].get("route_map"): - command += afi + " redistribute {protocol} route-map {route_map}".format( - **config_data["address_family"]["redistribute"], - ) - return command - - -def _tmplt_bgp_af_redistribute_table(config_data): - if config_data["address_family"]["redistribute"].get("table"): - afi = config_data["address_family"]["afi"] + "-unicast" - command = "protocols bgp {as_number} address-family ".format(**config_data) - if config_data["address_family"]["redistribute"].get("table"): - command += afi + " table {table}".format( - **config_data["address_family"]["redistribute"], - ) - return command +def _tmplt_bgp_af_redistribute(config_data): + afi = config_data["address_family"]["afi"] + "-unicast" + command = "protocols bgp address-family ".format(**config_data) + config_data = config_data["address_family"]["redistribute"] + command += afi + " redistribute {protocol}".format(**config_data) + if config_data.get("metric"): + command += " metric {metric}".format(**config_data) + elif config_data.get("route_map"): + command += " route-map {route_map}".format(**config_data) + elif config_data.get("table"): + command += " table {table}".format(**config_data) + return command -def _tmplt_bgp_af_delete_redistribute(config_data): +def _tmplt_bgp_af_redistribute_delete(config_data): afi = config_data["address_family"]["afi"] + "-unicast" - command = "protocols bgp {as_number} address-family ".format(**config_data) - config_data = config_data["address_family"] - command += afi + " redistribute {protocol}".format(**config_data["redistribute"]) + command = "protocols bgp address-family ".format(**config_data) + config_data = config_data["address_family"]["redistribute"] + command += afi + " redistribute {protocol}".format(**config_data) + if config_data.get("metric"): + command += " metric" + elif config_data.get("route_map"): + command += " route-map" + elif config_data.get("table"): + command += " table" return command def _tmplt_bgp_af_neighbor_distribute_list(config_data): command = [] afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" - cmd = "protocols bgp {as_number} neighbor ".format(**config_data) + cmd = "protocols bgp neighbor ".format(**config_data) cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"]) config_data = config_data["neighbors"]["address_family"] for list_el in config_data["distribute_list"]: command.append( cmd + afi + " distribute-list " + list_el["action"] + " " + str(list_el["acl"]), ) return command def _tmplt_bgp_af_neighbor_route_map(config_data): command = [] afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" - cmd = "protocols bgp {as_number} neighbor ".format(**config_data) + cmd = "protocols bgp neighbor ".format(**config_data) cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"]) config_data = config_data["neighbors"]["address_family"] for list_el in config_data["route_map"]: command.append( cmd + afi + " route-map " + list_el["action"] + " " + str(list_el["route_map"]), ) return command def _tmplt_bgp_af_neighbor_prefix_list(config_data): command = [] afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" - cmd = "protocols bgp {as_number} neighbor ".format(**config_data) + cmd = "protocols bgp neighbor ".format(**config_data) cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"]) config_data = config_data["neighbors"]["address_family"] for list_el in config_data["prefix_list"]: command.append( cmd + afi + " prefix-list " + list_el["action"] + " " + str(list_el["prefix_list"]), ) return command def _tmplt_bgp_af_neighbor_filter_list(config_data): command = [] afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" - cmd = "protocols bgp {as_number} neighbor ".format(**config_data) + cmd = "protocols bgp neighbor ".format(**config_data) cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"]) config_data = config_data["neighbors"]["address_family"] for list_el in config_data["filter_list"]: command.append( cmd + afi + " filter-list " + list_el["action"] + " " + str(list_el["path_list"]), ) return command def _tmplt_bgp_af_neighbor_attribute(config_data): command = [] afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" - cmd = "protocols bgp {as_number} neighbor ".format(**config_data) + cmd = "protocols bgp neighbor ".format(**config_data) cmd += "{neighbor_address} address-family ".format(**config_data["neighbors"]) config_data = config_data["neighbors"]["address_family"] for k in config_data["attribute_unchanged"].keys(): if config_data["attribute_unchanged"][k]: k = re.sub("_", "-", k) c = cmd + afi + " attribute-unchanged " + k command.append(c) return command def _tmplt_bgp_af_neighbor_delete(config_data): afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" - command = "protocols bgp {as_number} ".format(**config_data) + command = "protocols bgp ".format(**config_data) command += ( "neighbor {neighbor_address} address-family ".format(**config_data["neighbors"]) + afi ) config_data = config_data["neighbors"]["address_family"] if config_data.get("allowas_in"): command += " allowas-in" elif config_data.get("as_override"): command += " as-override" elif config_data.get("attribute_unchanged"): command += " attribute-unchanged" elif config_data.get("capability"): command += " capability" elif config_data.get("default_originate"): command += " default-originate" elif config_data.get("maximum_prefix"): command += " maximum-prefix" elif config_data.get("nexthop_local"): command += " nexthop-local" elif config_data.get("nexthop_self"): command += " nexthop-self" elif config_data.get("peer_group"): command += " peer-group" elif config_data.get("remote_private_as"): command += " remote-private-as" elif config_data.get("route_reflector_client"): command += " route-reflector-client" elif config_data.get("route_server_client"): command += " route-server-client" elif config_data.get("soft_reconfiguration"): command += " soft-reconfiguration" elif config_data.get("unsuppress_map"): command += " unsuppress-map" elif config_data.get("weight"): command += " weight" elif config_data.get("filter_list"): command += " filter-list" elif config_data.get("prefix_list"): command += " prefix-list" elif config_data.get("distribute_list"): command += " distribute-list" elif config_data.get("route_map"): command += " route-map" return command def _tmplt_bgp_af_neighbor(config_data): afi = config_data["neighbors"]["address_family"]["afi"] + "-unicast" - command = "protocols bgp {as_number} ".format(**config_data) + command = "protocols bgp ".format(**config_data) command += ( "neighbor {neighbor_address} address-family ".format(**config_data["neighbors"]) + afi ) config_data = config_data["neighbors"]["address_family"] if config_data.get("allowas_in"): command += " allowas-in number {allowas_in}".format(**config_data) elif config_data.get("as_override"): command += " as-override" elif config_data.get("capability"): command += " capability " if config_data["capability"].get("dynamic"): command += "dynamic" elif config_data["capability"].get("orf"): command += " prefix-list {orf}".format(**config_data["capability"]) elif config_data.get("default_originate"): command += " default-originate route-map {default_originate}".format(**config_data) elif config_data.get("maximum_prefix"): command += " maximum-prefix {maximum_prefix}".format(**config_data) elif config_data.get("nexthop_local"): command += " nexthop-local" elif config_data.get("nexthop_self"): command += " nexthop-self" elif config_data.get("peer_group"): command += " peer-group {peer_group}".format(**config_data) elif config_data.get("remote_private_as"): command += " remote-private-as" elif config_data.get("route_reflector_client"): command += " route-reflector-client" elif config_data.get("route_server_client"): command += " route-server-client" elif config_data.get("soft_reconfiguration"): command += " soft-reconfiguration inbound" elif config_data.get("unsuppress_map"): command += " unsuppress-map {unsuppress_map}".format(**config_data) elif config_data.get("weight"): command += " weight {weight}".format(**config_data) return command -class Bgp_address_familyTemplate(NetworkTemplate): +def _tmplt_bgp_af_network(config_data): + afi = config_data["address_family"]["afi"] + "-unicast" + command = "protocols bgp address-family ".format(**config_data) + config_data = config_data["address_family"]["networks"] + command += afi + " network {prefix}".format(**config_data) + if config_data.get("backdoor"): + command += " backdoor" + elif config_data.get("route_map"): + command += " route-map {route_map}".format(**config_data) + return command + + +def _tmplt_bgp_af_network_delete(config_data): + afi = config_data["address_family"]["afi"] + "-unicast" + command = "protocols bgp address-family ".format(**config_data) + config_data = config_data["address_family"]["networks"] + command += afi + " network {prefix}".format(**config_data) + if config_data.get("backdoor"): + command += " backdoor" + elif config_data.get("route_map"): + command += " route_map" + return command + + +class Bgp_address_familyTemplate14(NetworkTemplate): def __init__(self, lines=None, module=None): prefix = {"set": "set", "remove": "delete"} - super(Bgp_address_familyTemplate, self).__init__( + super(Bgp_address_familyTemplate14, self).__init__( lines=lines, tmplt=self, prefix=prefix, module=module, ) # fmt: off PARSERS = [ { - "name": "address_family", + "name": "system_as", "getval": re.compile( r""" ^set \s+protocols \s+bgp + \s+system-as \s+(?P\d+) + *$""", + re.VERBOSE, + ), + "setval": "protocols bgp system-as {{ as_number }}", + "compval": "as_number", + "result": { + "as_number": "{{ as_num }}", + }, + }, + { + "name": "address_family", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp \s+address-family \s+(?P\S+)-unicast *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast", + "setval": "protocols bgp address-family {{ address_family.afi }}-unicast", "compval": "as_number", "result": { "as_number": "{{ as_num }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", }, }, }, }, { "name": "aggregate_address", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+address-family \s+(?P\S+)-unicast \s+aggregate-address \s+(?P
\S+) \s*(?Pas-set)* \s*(?Psummary-only)* $""", re.VERBOSE, ), "setval": _tmplt_bgp_af_aggregate_address, - "remval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast aggregate-address" + + "remval": "protocols bgp address-family {{ address_family.afi }}-unicast aggregate-address" + " {{ address_family.aggregate_address.prefix }}", "compval": "address_family.aggregate_address", "result": { "as_number": "{{ as_num }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "aggregate_address": [ { "prefix": "{{ address }}", "as_set": "{{ True if as_set is defined }}", "summary_only": "{{ True if summary_only is defined }}", }, ], }, }, }, }, + { + "name": "network", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+address-family + \s+(?P\S+)-unicast + \s+network + \s+(?P
\S+) + $""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_network, + "remval": "protocols bgp address-family {{ address_family.afi }}-unicast network {{ address_family.networks.prefix }}", + "compval": "address_family.networks.prefix", + "result": { + "as_number": "{{ as_num }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "networks": [ + { + "prefix": "{{ address }}", + }, + ], + }, + }, + }, + }, { "name": "network.backdoor", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+address-family \s+(?P\S+)-unicast \s+network \s+(?P
\S+) \s+backdoor *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast network {{ address_family.networks.prefix }} backdoor", - "remval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast network {{ address_family.networks.prefix }}", + "setval": _tmplt_bgp_af_network, + "remval": _tmplt_bgp_af_network_delete, "compval": "address_family.networks.backdoor", "result": { "as_number": "{{ as_num }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "networks": [ { "prefix": "{{ address }}", "backdoor": "{{ True }}", }, ], }, }, }, }, { "name": "network.path_limit", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+address-family \s+(?P\S+)-unicast \s+network \s+(?P
\S+) \s+path-limit \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast network" + - "{{ address_family.networks.prefix }} path-limit {{ address_family.networks.path_limit }}", - "remval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast network {{ address_family.networks.address }}", + "setval": _tmplt_bgp_af_network, + "remval": _tmplt_bgp_af_network_delete, "compval": "address_family.networks.path_limit", "result": { "as_number": "{{ as_num }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "networks": [ { "prefix": "{{ address }}", "path_limit": "{{ limit|int }}", }, ], }, }, }, }, { "name": "network.route_map", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+address-family \s+(?P\S+)-unicast \s+network \s+(?P
\S+) \s+route-map \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast network" + - " {{ address_family.networks.prefix }} route-map {{ address_family.networks.route_map }}", - "remval": "protocols bgp {{ as_number }} address-family {{ address_family.afi }}-unicast network {{ address_family.networks.prefix }}", + "setval": _tmplt_bgp_af_network, + "remval": _tmplt_bgp_af_network_delete, "compval": "address_family.networks.route_map", "result": { "as_number": "{{ as_num }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "networks": [ { "prefix": "{{ address }}", "route_map": "{{ map }}", }, ], }, }, }, }, + { + "name": "redistribute", + "getval": re.compile( + r""" + ^set + \s+protocols + \s+bgp + \s+address-family + \s+(?P\S+)-unicast + \s+redistribute + \s+(?P\S+) + $""", + re.VERBOSE, + ), + "setval": _tmplt_bgp_af_redistribute, + "remval": "protocols bgp address-family {{ address_family.afi }}-unicast redistribute {{ address_family.redistribute.protocol }}", + "compval": "address_family.redistribute.protocol", + "result": { + "as_number": "{{ as_num }}", + "address_family": { + "{{ afi }}": { + "afi": "{{ afi }}", + "redistribute": [ + { + "protocol": "{{ proto }}", + }, + ], + }, + }, + }, + }, { "name": "redistribute.metric", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+address-family \s+(?P\S+)-unicast \s+redistribute \s+(?P\S+) - \s+metric - \s+(?P\S+) + \s+metric\s+(?P\S+) *$""", re.VERBOSE, ), - "setval": _tmplt_bgp_af_redistribute_metric, - "remval": _tmplt_bgp_af_delete_redistribute, + "setval": _tmplt_bgp_af_redistribute, + "remval": _tmplt_bgp_af_redistribute_delete, "compval": "address_family.redistribute.metric", "result": { "as_number": "{{ as_num }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "redistribute": [ { "protocol": "{{ proto }}", - "metric": "{{ val|int }}", + "metric": "{{ val }}", }, ], }, }, }, }, { "name": "redistribute.route_map", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+address-family \s+(?P\S+)-unicast \s+redistribute \s+(?P\S+) \s+route-map \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": _tmplt_bgp_af_redistribute_route_map, - "remval": _tmplt_bgp_af_delete_redistribute, + "setval": _tmplt_bgp_af_redistribute, + "remval": _tmplt_bgp_af_redistribute_delete, "compval": "address_family.redistribute.route_map", "result": { "as_number": "{{ as_num }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "redistribute": [ { "protocol": "{{ proto }}", "route_map": "{{ map }}", }, ], }, }, }, }, { "name": "redistribute.table", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+address-family \s+(?P\S+)-unicast \s+redistribute \s+table \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": _tmplt_bgp_af_redistribute_table, - "remval": _tmplt_bgp_af_delete_redistribute, + "setval": _tmplt_bgp_af_redistribute, + "remval": _tmplt_bgp_af_redistribute_delete, "compval": "address_family.redistribute.table", "result": { "as_number": "{{ as_num }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "redistribute": [ { "table": "{{ tab }}", }, ], }, }, }, }, { "name": "neighbors", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbors.neighbor_address }} address-family", + "setval": "protocols bgp neighbor {{ neighbors.neighbor_address }} address-family", "compval": "neighbors", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", }, }, }, }, { "name": "neighbors.address_family", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbors.neighbor_address }} address-family {{ neighbors.address_family.afi }}-unicast", + "setval": "protocols bgp neighbor {{ neighbors.neighbor_address }} address-family {{ neighbors.address_family.afi }}-unicast", "compval": "neighbors", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", }, }, }, }, }, }, { "name": "neighbors.allowas_in", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+allowas-in \s+number \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.allowas_in", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "allowas_in": "{{ num }}", }, }, }, }, }, }, { "name": "neighbors.as_override", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+as-override *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.as_override", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "as_override": "{{ True }}", }, }, }, }, }, }, { "name": "neighbors.attribute_unchanged.as_path", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+attribute-unchanged \s+(?Pas-path) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor_attribute, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.attribute_unchanged.as_path", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "attribute_unchanged": { "as_path": "{{ True }}", }, }, }, }, }, }, }, { "name": "neighbors.attribute_unchanged.med", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+attribute-unchanged \s+(?Pmed) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor_attribute, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.attribute_unchanged.med", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "attribute_unchanged": { "med": "{{ True }}", }, }, }, }, }, }, }, { "name": "neighbors.attribute_unchanged.next_hop", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+attribute-unchanged \s+(?Pnext-hop) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor_attribute, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.attribute_unchanged.next_hop", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "attribute_unchanged": { "next_hop": "{{ True }}", }, }, }, }, }, }, }, { "name": "neighbors.capability_dynamic", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+capability \s+dynamic *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.capability.dynamic", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "capability": { "dynamic": "{{ true }}", }, }, }, }, }, }, }, { "name": "neighbors.capability_orf", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+capability \s+prefix-list \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.capability.orf", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "capability": { "orf": "{{ orf }}", }, }, }, }, }, }, }, { "name": "neighbors.default_originate", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+default-originate \s+route-map \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.default_originate", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "default_originate": "{{ map }}", }, }, }, }, }, }, { "name": "neighbors.distribute_list", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+distribute-list \s+(?Pexport|import) \s+(?P\d+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor_distribute_list, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.distribute_list", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "distribute_list": [ { "action": "{{ action }}", "acl": "{{ list }}", }, ], }, }, }, }, }, }, { "name": "neighbors.prefix_list", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+prefix-list \s+(?Pexport|import) \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor_prefix_list, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.prefix_list", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "prefix_list": [ { "action": "{{ action }}", "prefix_list": "{{ list }}", }, ], }, }, }, }, }, }, { "name": "neighbors.filter_list", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+filter-list \s+(?Pexport|import) \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor_filter_list, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.filter_list", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "filter_list": [ { "action": "{{ action }}", "path_list": "{{ list }}", }, ], }, }, }, }, }, }, { "name": "neighbors.maximum_prefix", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+maximum-prefix \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.maximum_prefix", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "maximum_prefix": "{{ num }}", }, }, }, }, }, }, { "name": "neighbors.nexthop_local", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+nexthop-local *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.nexthop_local", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "nexthop_local": "{{ True }}", }, }, }, }, }, }, { "name": "neighbors.nexthop_self", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+nexthop-self *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.nexthop_self", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "nexthop_self": "{{ True }}", }, }, }, }, }, }, { "name": "neighbors.peer_group", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+peer-group \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.peer_group", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "peer_group": "{{ name }}", }, }, }, }, }, }, { "name": "neighbors.remove_private_as", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+remove-private-as *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.remove_private_as", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "remove_private_as": "{{ True }}", }, }, }, }, }, }, { "name": "neighbors.route_map", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+route-map \s+(?Pexport|import) \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor_route_map, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.route_map", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "route_map": [ { "action": "{{ action }}", "route_map": "{{ map }}", }, ], }, }, }, }, }, }, { "name": "neighbors.route_reflector_client", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+route-reflector-client *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.route_reflector_client", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "route_reflector_client": "{{ True }}", }, }, }, }, }, }, { "name": "neighbors.route_server_client", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+route-server-client *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.route_server_client", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "route_server_client": "{{ True }}", }, }, }, }, }, }, { "name": "neighbors.soft_reconfiguration", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+soft-reconfiguration \s+inbound *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.soft_reconfiguration", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "soft_reconfiguration": "{{ True }}", }, }, }, }, }, }, { "name": "neighbors.unsuppress_map", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+unsuppress-map \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.unsuppress_map", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "unsuppress_map": "{{ map }}", }, }, }, }, }, }, { "name": "neighbors.weight", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+address-family \s+(?P\S+)-unicast \s+weight \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_af_neighbor, "remval": _tmplt_bgp_af_neighbor_delete, "compval": "neighbors.address_family.weight", "result": { "as_number": "{{ as_num }}", "neighbors": { "{{ address }}": { "neighbor_address": "{{ address }}", "address_family": { "{{ afi }}": { "afi": "{{ afi }}", "weight": "{{ num }}", }, }, }, }, }, }, ] # fmt: on diff --git a/plugins/module_utils/network/vyos/rm_templates/bgp_global.py b/plugins/module_utils/network/vyos/rm_templates/bgp_global.py index bd95e082..621f65ea 100644 --- a/plugins/module_utils/network/vyos/rm_templates/bgp_global.py +++ b/plugins/module_utils/network/vyos/rm_templates/bgp_global.py @@ -1,2017 +1,1860 @@ # -*- coding: utf-8 -*- # Copyright 2021 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function __metaclass__ = type """ The Bgp_global parser templates file. This contains a list of parser definitions and associated functions that facilitates both facts gathering and native command generation for the given network resource. """ import re from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) def _tmplt_bgp_params_confederation(config_data): command = [] for list_el in config_data["bgp_params"]["confederation"]: for k, v in iteritems(list_el): command.append( "protocols bgp {as_number} parameters confederation ".format(**config_data) + k + " " + str(v), ) return command def _tmplt_bgp_maximum_paths(config_data): command = [] for list_el in config_data["maximum_paths"]: command.append( "protocols bgp {as_number} maximum-paths ".format(**config_data) + list_el["path"] + " " + str(list_el["count"]), ) return command -def _tmplt_bgp_aggregate_address(config_data): - command = "protocols bgp {as_number} aggregate-address".format(**config_data) - if config_data["aggregate_address"].get("as_set"): - command += " {prefix} as-set".format(**config_data["aggregate_address"]) - if config_data["aggregate_address"].get("summary_only"): - command += " {prefix} summary-only".format(**config_data["aggregate_address"]) - return command - - def _tmplt_delete_bgp_maximum_paths(config_data): command = "protocols bgp {as_number} maximum-paths".format(**config_data) return command def _tmplt_bgp_params_default(config_data): command = "protocols bgp {as_number} parameters default".format(**config_data) if config_data["bgp_params"]["default"].get("no_ipv4_unicast"): command += " no-ipv4-unicast" if config_data["bgp_params"]["default"].get("local_pref"): command += " local-pref {local_pref}".format(**config_data["bgp_params"]["default"]) return command -def _tmplt_bgp_delete_redistribute(config_data): - command = ( - "protocols bgp {as_number} redistribute ".format(**config_data) - + config_data["redistribute"]["protocol"] - ) - return command - - def _tmplt_bgp_neighbor_timers(config_data): command = [] for k, v in iteritems(config_data["neighbor"]["timers"]): command.append( "protocols bgp {as_number} neighbor ".format(**config_data) + config_data["neighbor"]["address"] + " timers " + k + " " + str(v), ) return command def _tmplt_bgp_timers(config_data): command = [] for k, v in iteritems(config_data["timers"]): command.append( "protocols bgp {as_number} ".format(**config_data) + "timers " + k + " " + str(v), ) return command def _tmplt_bgp_neighbor_attribute_unchanged_as_path(config_data): command = "protocols bgp {as_number} ".format( **config_data, ) + "neighbor {address} attribute-unchanged as-path".format(**config_data["neighbor"]) return command def _tmplt_bgp_neighbor_attribute_unchanged_med(config_data): command = "protocols bgp {as_number} ".format( **config_data, ) + "neighbor {address} attribute-unchanged med".format(**config_data["neighbor"]) return command def _tmplt_bgp_neighbor_attribute_unchanged_next_hop(config_data): command = "protocols bgp {as_number} ".format( **config_data, ) + "neighbor {address} attribute-unchanged next-hop".format(**config_data["neighbor"]) return command def _tmplt_bgp_neighbor_distribute_list(config_data): command = [] for list_el in config_data["neighbor"]["distribute_list"]: command.append( "protocols bgp {as_number} ".format(**config_data) + "neighbor {address} distribute-list ".format(**config_data["neighbor"]) + list_el["action"] + " " + str(list_el["acl"]), ) return command def _tmplt_bgp_neighbor_route_map(config_data): command = [] for list_el in config_data["neighbor"]["route_map"]: command.append( "protocols bgp {as_number} ".format(**config_data) + "neighbor {address} route-map ".format(**config_data["neighbor"]) + list_el["action"] + " " + str(list_el["route_map"]), ) return command def _tmplt_bgp_neighbor_prefix_list(config_data): command = [] for list_el in config_data["neighbor"]["prefix_list"]: command.append( "protocols bgp {as_number} ".format(**config_data) + "neighbor {address} prefix-list ".format(**config_data["neighbor"]) + list_el["action"] + " " + str(list_el["prefix_list"]), ) return command def _tmplt_bgp_neighbor_filter_list(config_data): command = [] for list_el in config_data["neighbor"]["filter_list"]: command.append( "protocols bgp {as_number} ".format(**config_data) + "neighbor {address} filter-list ".format(**config_data["neighbor"]) + list_el["action"] + " " + str(list_el["path_list"]), ) return command def _tmplt_bgp_params_distance(config_data): command = ( "protocols bgp {as_number} parameters distance global ".format(**config_data) + config_data["bgp_params"]["distance"]["type"] + " " + str(config_data["bgp_params"]["distance"]["value"]) ) return command class Bgp_globalTemplate(NetworkTemplate): def __init__(self, lines=None, module=None): prefix = {"set": "set", "remove": "delete"} super(Bgp_globalTemplate, self).__init__( lines=lines, tmplt=self, prefix=prefix, module=module, ) # fmt: off PARSERS = [ { "name": "router", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }}", "compval": "as_number", "result": { "as_number": "{{ as_num }}", }, }, - { - "name": "aggregate_address", - "getval": re.compile( - r""" - ^set - \s+protocols - \s+bgp - \s+(?P\d+) - \s+aggregate-address - \s+(?P
\S+) - \s*(?Pas-set)* - \s*(?Psummary-only)* - $""", - re.VERBOSE, - ), - "setval": _tmplt_bgp_aggregate_address, - "remval": "protocols bgp {{ as_number }} aggregate-address {{ aggregate_address.prefix }}", - "compval": "aggregate_address", - "result": { - "as_number": "{{ as_num }}", - "aggregate_address": [ - { - "prefix": "{{ address }}", - "as_set": "{{ True if as_set is defined }}", - "summary_only": "{{ True if summary_only is defined }}", - }, - ], - }, - }, { "name": "maximum_paths", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+maximum-paths \s+(?Pebgp|ibgp) \s+(?P\d+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_maximum_paths, "remval": _tmplt_delete_bgp_maximum_paths, "compval": "maximum_paths", "result": { "as_number": "{{ as_num }}", "maximum_paths": [ { "path": "{{ path }}", "count": "{{ count }}", }, ], }, }, { "name": "neighbor.advertisement_interval", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+advertisement-interval \s+(?P\S+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} advertisement-interval {{ neighbor.advertisement_interval }}", "remval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} advertisement-interval", "compval": "neighbor.advertisement_interval", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "advertisement_interval": "{{ interval }}", }, }, }, }, { "name": "neighbor.allowas_in", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+allowas-in \s+number \s+(?P\'\d+\') *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} allowas-in number {{ neighbor.allowas_in }}", "compval": "neighbor.allowas_in", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "allowas_in": "{{ count }}", }, }, }, }, { "name": "neighbor.as_override", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+as-override *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} as-override", "compval": "neighbor.as_override", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "as_override": "{{ True }}", }, }, }, }, { "name": "neighbor.attribute_unchanged.as_path", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+attribute-unchanged \s+(?Pas-path) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_neighbor_attribute_unchanged_as_path, "compval": "neighbor.attribute_unchanged", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "attribute_unchanged": { "{{ 'as_path' }}": "{{ True }}", }, }, }, }, }, { "name": "neighbor.attribute_unchanged.med", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+attribute-unchanged \s+(?Pmed) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_neighbor_attribute_unchanged_med, "compval": "neighbor.attribute_unchanged", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "attribute_unchanged": { "{{ 'med' }}": "{{ True }}", }, }, }, }, }, { "name": "neighbor.attribute_unchanged.next_hop", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+attribute-unchanged \s+(?Pnext-hop) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_neighbor_attribute_unchanged_next_hop, "compval": "neighbor.attribute_unchanged", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "attribute_unchanged": { "{{ 'next_hop' }}": "{{ True }}", }, }, }, }, }, { "name": "neighbor.capability_dynamic", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+capability \s+(?Pdynamic) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} capability dynamic", "compval": "neighbor.capability.dynamic", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "capability": { "dynamic": "{{ True if dynamic is defined}}", }, }, }, }, }, { "name": "neighbor.capability_orf", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+capability \s+orf \s+prefix-list \s+(?P\S+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} capability orf prefix-list {{ neighbor.capability.orf }}", "compval": "neighbor.capability.orf", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "capability": { "orf": "{{ orf }}", }, }, }, }, }, { "name": "neighbor.default_originate", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+default-originate \s+route-map \s+(?P\S+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} default-originate route-map {{ neighbor.default_originate }}", "compval": "neighbor.advertisement_interval", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "default_originate": "{{ map }}", }, }, }, }, { "name": "neighbor.description", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+description \s+(?P\S+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} description {{ neighbor.description }}", "compval": "neighbor.description", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "description": "{{ desc }}", }, }, }, }, { "name": "neighbor.disable_capability_negotiation", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+disable-capability-negotiation *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} disable-capability-negotiation", "compval": "neighbor.disable_capability_negotiation", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "disable_capability_negotiation": "{{ True }}", }, }, }, }, { "name": "neighbor.disable_connected_check", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+disable-connected-check *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} disable-connected-check", "compval": "neighbor.disable_connected_check", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "disable_connected_check": "{{ True }}", }, }, }, }, { "name": "neighbor.disable_send_community", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+disable-send-community \s+(?P\S+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} disable-send-community {{ neighbor.disable_send_community }}", "compval": "neighbor.disable_send_community", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "disable_send_community": "{{ comm }}", }, }, }, }, { "name": "neighbor.distribute_list", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+distribute-list \s+(?Pexport|import) \s+(?P\d+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_neighbor_distribute_list, "compval": "neighbor.distribute_list", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "distribute_list": [ { "action": "{{ action }}", "acl": "{{ list }}", }, ], }, }, }, }, { "name": "neighbor.ebgp_multihop", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+ebgp-multihop \s+(?P\S+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} ebgp-multihop {{ neighbor.ebgp_multihop }}", "compval": "neighbor.ebgp_multihop", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "ebgp_multihop": "{{ hop|int }}", }, }, }, }, { "name": "neighbor.filter_list", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+filter-list \s+(?Pexport|import) \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_neighbor_filter_list, "compval": "neighbor.filter_list", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "filter_list": [ { "action": "{{ action }}", "path_list": "{{ list }}", }, ], }, }, }, }, { "name": "neighbor.local_as", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+local-as \s+(?P\S+) \s+no-prepend *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} local-as {{ neighbor.local_as }} no-prepend", "compval": "neighbor.local_as", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "local_as": "{{ as }}", }, }, }, }, { "name": "neighbor.maximum_prefix", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+maximum-prefix \s+(?P\S+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} maximum-prefix {{ neighbor.maximum_prefix }}", "compval": "neighbor.maximum_prefix", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "maximum_prefix": "{{ num }}", }, }, }, }, { "name": "neighbor.nexthop_self", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+nexthop-self *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} nexthop-self", "compval": "neighbor.nexthop_self", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "nexthop_self": "{{ True }}", }, }, }, }, { "name": "neighbor.override_capability", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+override-capability *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} override-capability", "compval": "neighbor.override_capability", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "override_capability": "{{ True }}", }, }, }, }, { "name": "neighbor.passive", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+passive *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} nexthop-self", + "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} passive", "compval": "neighbor.passive", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "passive": "{{ True }}", }, }, }, }, { "name": "neighbor.password", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+password \s+(?P\S+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} password {{ neighbor.password }}", "compval": "neighbor.password", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "password": "{{ pwd }}", }, }, }, }, { "name": "neighbor.peer_group_name", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+peer-group \s+(?P\S+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} peer-group {{ neighbor.peer_group_name }}", "compval": "neighbor.peer_group_name", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "peer_group_name": "{{ name }}", }, }, }, }, { "name": "neighbor.port", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+port \s+(?P\S+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} port {{ neighbor.port }}", "compval": "neighbor.port", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "port": "{{ num|int }}", }, }, }, }, { "name": "neighbor.prefix_list", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+prefix-list \s+(?Pexport|import) \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_neighbor_prefix_list, "compval": "neighbor.prefix_list", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "prefix_list": [ { "action": "{{ action }}", "prefix_list": "{{ list }}", }, ], }, }, }, }, { "name": "neighbor.remote_as", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+remote-as \s+(?P\S+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} remote-as {{ neighbor.remote_as }}", "compval": "neighbor.remote_as", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "remote_as": "{{ num|int }}", }, }, }, }, { "name": "neighbor.remove_private_as", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+remote-private-as *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} remote-private-as", "compval": "neighbor.remove_private_as", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "remove_private_as": "{{ True }}", }, }, }, }, { "name": "neighbor.route_map", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+route-map \s+(?Pexport|import) \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_neighbor_route_map, "compval": "neighbor.route_map", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "route_map": [ { "action": "{{ action }}", "route_map": "{{ map }}", }, ], }, }, }, }, { "name": "neighbor.route_reflector_client", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+route-reflector-client *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} router-reflector-client", "compval": "neighbor.route_reflector_client", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "route_reflector_client": "{{ True }}", }, }, }, }, { "name": "neighbor.route_server_client", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+route-server-client *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} route-server-client", "compval": "neighbor.route_server_client", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "route_server_client": "{{ True }}", }, }, }, }, { "name": "neighbor.shutdown", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+shutdown *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} shutdown", "compval": "neighbor.shutdown", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "shutdown": "{{ True }}", }, }, }, }, { "name": "neighbor.soft_reconfiguration", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+soft-reconfiguration \s+inbound *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} soft-reconfiguration", "compval": "neighbor.soft_reconfiguration", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "soft_reconfiguration": "{{ True }}", }, }, }, }, { "name": "neighbor.strict_capability_match", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+strict-capability-match *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} strict-capability-match", "compval": "neighbor.strict_capability_match", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "strict_capability_match": "{{ True }}", }, }, }, }, { "name": "neighbor.unsuppress_map", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+unsuppress-map \s+(?P\S+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} unsuppress-map {{ neighbor.unsuppress_map }}", "compval": "neighbor.unsuppress_map", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "unsuppress_map": "{{ map }}", }, }, }, }, { "name": "neighbor.update_source", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+update-source \s+(?P\S+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} update-source {{ neighbor.update_source }}", "compval": "neighbor.update_source", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "update_source": "{{ src }}", }, }, }, }, { "name": "neighbor.weight", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+weight \s+(?P\S+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} weight {{ neighbor.weight }}", "compval": "neighbor.weight", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "weight": "{{ num }}", }, }, }, }, { "name": "neighbor.ttl_security", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+ttl-security \s+(?P\S+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} ttl-security {{ neighbor.ttl_security }}", "compval": "neighbor.ttl_security", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "ttl_security": "{{ ttl|int }}", }, }, }, }, { "name": "neighbor.timers", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+timers \s+(?Pconnect|holdtime|keepalive) \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_neighbor_timers, "remval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} timers", "compval": "neighbor.timers", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "timers": { "{{ type }}": "{{ sec }}", }, }, }, }, }, - { - "name": "network.backdoor", - "getval": re.compile( - r""" - ^set - \s+protocols - \s+bgp - \s+(?P\d+) - \s+network - \s+(?P
\S+) - \s+backdoor - *$""", - re.VERBOSE, - ), - "setval": "protocols bgp {{ as_number }} network {{ network.address }} backdoor", - "remval": "protocols bgp {{ as_number }} network {{ network.address }}", - "compval": "network.backdoor", - "result": { - "as_number": "{{ as_num }}", - "network": [ - { - "address": "{{ address }}", - "backdoor": "{{ True }}", - }, - ], - }, - }, - { - "name": "network.route_map", - "getval": re.compile( - r""" - ^set - \s+protocols - \s+bgp - \s+(?P\d+) - \s+network - \s+(?P
\S+) - \s+route-map - \s+(?P\S+) - *$""", - re.VERBOSE, - ), - "setval": "protocols bgp {{ as_number }} network {{ network.address }} route-map {{ network.route_map }}", - "remval": "protocols bgp {{ as_number }} network {{ network.address }}", - "compval": "network.route_map", - "result": { - "as_number": "{{ as_num }}", - "network": [ - { - "address": "{{ address }}", - "route_map": "{{ map }}", - }, - ], - }, - }, - { - "name": "redistribute.metric", - "getval": re.compile( - r""" - ^set - \s+protocols - \s+bgp - \s+(?P\d+) - \s+redistribute - \s+(?P\S+) - \s+metric - \s+(?P\S+) - *$""", - re.VERBOSE, - ), - "setval": "protocols bgp {{ as_number }} redistribute {{ redistribute.protocol }} metric {{ redistribute.metric }}", - "remval": _tmplt_bgp_delete_redistribute, - "compval": "redistribute", - "result": { - "as_number": "{{ as_num }}", - "redistribute": [ - { - "protocol": "{{ proto }}", - "metric": "{{ val|int }}", - }, - ], - }, - }, - { - "name": "redistribute.route_map", - "getval": re.compile( - r""" - ^set - \s+protocols - \s+bgp - \s+(?P\d+) - \s+redistribute - \s+(?P\S+) - \s+route-map - \s+(?P\S+) - *$""", - re.VERBOSE, - ), - "setval": "protocols bgp {{ as_number }} redistribute {{ redistribute.protocol }} route-map {{ redistribute.route_map }}", - "remval": _tmplt_bgp_delete_redistribute, - "compval": "redistribute", - "result": { - "as_number": "{{ as_num }}", - "redistribute": [ - { - "protocol": "{{ proto }}", - "route_map": "{{ val }}", - }, - ], - }, - }, { "name": "timers", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+timers \s+(?P\S+) \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_timers, "remval": "protocols bgp {{ as_number }} timers", "compval": "timers", "result": { "as_number": "{{ as_num }}", "timers": { "{{ type }}": "{{ val }}", }, }, }, { "name": "bgp_params.always_compare_med", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+parameters \s+always-compare-med *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} parameters always-compare-med", "compval": "bgp_params.always_compare_med", "result": { "as_number": "{{ as_num }}", "bgp_params": { "always_compare_med": "{{ True }}", }, }, }, { "name": "bgp_params.bestpath.as_path", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+parameters \s+bestpath \s+as-path \s+(?Pconfed|ignore) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} parameters bestpath as-path {{ bgp_params.bestpath.as_path }}", "compval": "bgp_params.bestpath.as_path", "result": { "as_number": "{{ as_num }}", "bgp_params": { "bestpath": { "as_path": "{{ path }}", }, }, }, }, { "name": "bgp_params.bestpath.compare_routerid", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+parameters \s+bestpath \s+compare-routerid *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} parameters bestpath compare-routerid", "compval": "bgp_params.bestpath.compare_routerid", "result": { "as_number": "{{ as_num }}", "bgp_params": { "bestpath": { "compare_routerid": "{{ True }}", }, }, }, }, { "name": "bgp_params.bestpath.med", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+parameters \s+bestpath \s+med \s+(?Pconfed|missing-as-worst) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} parameters bestpath med {{ bestpath.med }}", "compval": "bgp_params.bestpath.med", "result": { "as_number": "{{ as_num }}", "bgp_params": { "bestpath": { "med": "{{ path }}", }, }, }, }, { "name": "bgp_params.cluster_id", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+parameters \s+cluster-id \s+(?P\S+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} parameters cluster-id {{ bgp_params.cluster_id }}", "compval": "bgp_params.cluster_id", "result": { "as_number": "{{ as_num }}", "bgp_params": { "cluster_id": "{{ id }}", }, }, }, { "name": "bgp_params.confederation", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+parameters \s+confederation \s+(?Pidentifier|peers) \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_params_confederation, "compval": "bgp_params.always_compare_med", "result": { "as_number": "{{ as_num }}", "bgp_params": { "confederation": [ { "peers": "{{ val if type == 'peers' }}", "identifier": "{{ val if type == 'identifier' }}", }, ], }, }, }, { "name": "bgp_params.dampening_half_life", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+parameters \s+dampening \s+half-life \s+(?P\S+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} parameters dampening half-life {{ bgp_params.dampening.half_life}}", "compval": "bgp_params.dampening.half_life", "result": { "as_number": "{{ as_num }}", "bgp_params": { "dampening": { "half_life": "{{ val }}", }, }, }, }, { "name": "bgp_params.dampening_max_suppress_time", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+parameters \s+dampening \s+max-suppress-time \s+(?P\S+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} parameters dampening max-suppress-time {{ bgp_params.dampening.max_suppress_time}}", "compval": "bgp_params.dampening.max_suppress_time", "result": { "as_number": "{{ as_num }}", "bgp_params": { "dampening": { "max_suppress_time": "{{ val }}", }, }, }, }, { "name": "bgp_params.dampening_re_use", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+parameters \s+dampening \s+re-use \s+(?P\S+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} parameters dampening re-use {{ bgp_params.dampening.re_use}}", "compval": "bgp_params.dampening.re_use", "result": { "as_number": "{{ as_num }}", "bgp_params": { "dampening": { "re_use": "{{ val }}", }, }, }, }, { "name": "bgp_params.dampening_start_suppress_time", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+parameters \s+dampening \s+start-suppress-time \s+(?P\S+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} parameters dampening start-suppress-time {{ bgp_params.dampening.start_suppress_time}}", "compval": "bgp_params.dampening.start_suppress_time", "result": { "as_number": "{{ as_num }}", "bgp_params": { "dampening": { "start_suppress_time": "{{ val }}", }, }, }, }, { "name": "bgp_params.default", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+parameters \s+default \s*(?Pno-ipv4-unicast)* \s*(?Plocal-pref\s\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_params_default, "remval": "protocols bgp {{ as_number }} parameters default", "compval": "bgp_params.default", "result": { "as_number": "{{ as_num }}", "bgp_params": { "default": { "no_ipv4_unicast": "{{ True if no_ipv4_unicast is defined }}", "local_pref": "{{ local_pref.split(" " )[1] if local_pref is defined }}", }, }, }, }, { "name": "bgp_params.deterministic_med", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+parameters \s+deterministic-med *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} parameters deterministic-med", "compval": "bgp_params.deterministic_med", "result": { "as_number": "{{ as_num }}", "bgp_params": { "deterministic_med": "{{ True }}", }, }, }, { "name": "bgp_params.disbale_network_import_check", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+parameters \s+disable-network-import-check *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} parameters disable-network-import-check", "compval": "bgp_params.disable_network_import_check", "result": { "as_number": "{{ as_num }}", "bgp_params": { "disable_network_import_check": "{{ True }}", }, }, }, { "name": "bgp_params.distance.prefix", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+parameters \s+distance\sprefix \s+(?P\S+) \s+distance \s+(?P\S+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} parameters distance prefix {{ bgp_params.distance.prefix }} distance {{ bgp_params.distance.value }}", "compval": "bgp_params.distance.prefix", "remval": "protocols bgp {{ as_number }} parameters distance prefix", "result": { "as_number": "{{ as_num }}", "bgp_params": { "distance": [ { "prefix": "{{ prefix }}", "value": "{{ val }}", }, ], }, }, }, { "name": "bgp_params.distance.global", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+parameters \s+distance\sglobal \s+(?P\S+) \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_params_distance, "remval": "protocols bgp {{ as_number }} parameters distance global", "compval": "bgp_params.distance", "result": { "as_number": "{{ as_num }}", "bgp_params": { "distance": [ { "type": "{{ type }}", "value": "{{ val }}", }, ], }, }, }, { "name": "bgp_params.enforce_first_as", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+parameters \s+enforce-first-as *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} parameters enforce-first-as", "compval": "bgp_params.enforce_first_as", "result": { "as_number": "{{ as_num }}", "bgp_params": { "enforce_first_as": "{{ True }}", }, }, }, { "name": "bgp_params.graceful_restart", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+parameters \s+graceful-restart\s+stalepath-time \s+(?P\S+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} parameters graceful-restart stalepath-time {{ bgp_params.graceful_restart }}", "compval": "bgp_params.graceful_restart", "result": { "as_number": "{{ as_num }}", "bgp_params": { "graceful_restart": "{{ val }}", }, }, }, { "name": "bgp_params.log_neighbor_changes", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+parameters \s+log-neighbor-changes *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} parameters log-neighbor-changes", "compval": "bgp_params.log_neighbor_changes", "result": { "as_number": "{{ as_num }}", "bgp_params": { "log_neighbor_changes": "{{ True }}", }, }, }, { "name": "bgp_params.no_client_to_client_reflection", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+parameters \s+no-client-to-client-reflection *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} parameters no-client-to-client-reflection", "compval": "bgp_params.log_neighbor_changes", "result": { "as_number": "{{ as_num }}", "bgp_params": { "no_client_to_client_reflection": "{{ True }}", }, }, }, { "name": "bgp_params.no_fast_external_failover", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+parameters \s+no-fast-external-failover *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} parameters no-fast-external-failover", "compval": "bgp_params.no_fast_external_failover", "result": { "as_number": "{{ as_num }}", "bgp_params": { "no_fast_external_failover": "{{ True }}", }, }, }, { "name": "bgp_params.routerid", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+parameters \s+router-id \s+(?P\S+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} parameters router-id {{ bgp_params.router_id }}", "compval": "bgp_params.router_id", "result": { "as_number": "{{ as_num }}", "bgp_params": { "router_id": "{{ id }}", }, }, }, { "name": "bgp_params.scan_time", "getval": re.compile( r""" ^set \s+protocols \s+bgp \s+(?P\d+) \s+parameters \s+scan-time \s+(?P\d+) *$""", re.VERBOSE, ), "setval": "protocols bgp {{ as_number }} parameters scan-time {{ bgp_params.scan_time }}", "compval": "bgp_params.scan_time", "result": { "as_number": "{{ as_num }}", "bgp_params": { "scan_time": "{{ val }}", }, }, }, ] # fmt: on diff --git a/plugins/module_utils/network/vyos/rm_templates/bgp_global.py b/plugins/module_utils/network/vyos/rm_templates/bgp_global_14.py similarity index 77% copy from plugins/module_utils/network/vyos/rm_templates/bgp_global.py copy to plugins/module_utils/network/vyos/rm_templates/bgp_global_14.py index bd95e082..b8beb923 100644 --- a/plugins/module_utils/network/vyos/rm_templates/bgp_global.py +++ b/plugins/module_utils/network/vyos/rm_templates/bgp_global_14.py @@ -1,2017 +1,1799 @@ # -*- coding: utf-8 -*- # Copyright 2021 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function __metaclass__ = type """ The Bgp_global parser templates file. This contains a list of parser definitions and associated functions that facilitates both facts gathering and native command generation for the given network resource. """ import re from ansible.module_utils.six import iteritems from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.network_template import ( NetworkTemplate, ) def _tmplt_bgp_params_confederation(config_data): command = [] for list_el in config_data["bgp_params"]["confederation"]: for k, v in iteritems(list_el): command.append( - "protocols bgp {as_number} parameters confederation ".format(**config_data) + "protocols bgp parameters confederation ".format(**config_data) + k + " " + str(v), ) return command def _tmplt_bgp_maximum_paths(config_data): command = [] for list_el in config_data["maximum_paths"]: command.append( - "protocols bgp {as_number} maximum-paths ".format(**config_data) + "protocols bgp maximum-paths ".format(**config_data) + list_el["path"] + " " + str(list_el["count"]), ) return command -def _tmplt_bgp_aggregate_address(config_data): - command = "protocols bgp {as_number} aggregate-address".format(**config_data) - if config_data["aggregate_address"].get("as_set"): - command += " {prefix} as-set".format(**config_data["aggregate_address"]) - if config_data["aggregate_address"].get("summary_only"): - command += " {prefix} summary-only".format(**config_data["aggregate_address"]) - return command - - def _tmplt_delete_bgp_maximum_paths(config_data): - command = "protocols bgp {as_number} maximum-paths".format(**config_data) + command = "protocols bgp maximum-paths".format(**config_data) return command def _tmplt_bgp_params_default(config_data): - command = "protocols bgp {as_number} parameters default".format(**config_data) + command = "protocols bgp parameters default".format(**config_data) if config_data["bgp_params"]["default"].get("no_ipv4_unicast"): command += " no-ipv4-unicast" if config_data["bgp_params"]["default"].get("local_pref"): command += " local-pref {local_pref}".format(**config_data["bgp_params"]["default"]) return command -def _tmplt_bgp_delete_redistribute(config_data): - command = ( - "protocols bgp {as_number} redistribute ".format(**config_data) - + config_data["redistribute"]["protocol"] - ) - return command - - def _tmplt_bgp_neighbor_timers(config_data): command = [] for k, v in iteritems(config_data["neighbor"]["timers"]): command.append( - "protocols bgp {as_number} neighbor ".format(**config_data) + "protocols bgp neighbor ".format(**config_data) + config_data["neighbor"]["address"] + " timers " + k + " " + str(v), ) return command def _tmplt_bgp_timers(config_data): command = [] for k, v in iteritems(config_data["timers"]): command.append( - "protocols bgp {as_number} ".format(**config_data) + "timers " + k + " " + str(v), + "protocols bgp ".format(**config_data) + "timers " + k + " " + str(v), ) return command def _tmplt_bgp_neighbor_attribute_unchanged_as_path(config_data): - command = "protocols bgp {as_number} ".format( + command = "protocols bgp ".format( **config_data, ) + "neighbor {address} attribute-unchanged as-path".format(**config_data["neighbor"]) return command def _tmplt_bgp_neighbor_attribute_unchanged_med(config_data): - command = "protocols bgp {as_number} ".format( + command = "protocols bgp ".format( **config_data, ) + "neighbor {address} attribute-unchanged med".format(**config_data["neighbor"]) return command def _tmplt_bgp_neighbor_attribute_unchanged_next_hop(config_data): - command = "protocols bgp {as_number} ".format( + command = "protocols bgp ".format( **config_data, ) + "neighbor {address} attribute-unchanged next-hop".format(**config_data["neighbor"]) return command def _tmplt_bgp_neighbor_distribute_list(config_data): command = [] for list_el in config_data["neighbor"]["distribute_list"]: command.append( - "protocols bgp {as_number} ".format(**config_data) + "protocols bgp ".format(**config_data) + "neighbor {address} distribute-list ".format(**config_data["neighbor"]) + list_el["action"] + " " + str(list_el["acl"]), ) return command def _tmplt_bgp_neighbor_route_map(config_data): command = [] for list_el in config_data["neighbor"]["route_map"]: command.append( - "protocols bgp {as_number} ".format(**config_data) + "protocols bgp ".format(**config_data) + "neighbor {address} route-map ".format(**config_data["neighbor"]) + list_el["action"] + " " + str(list_el["route_map"]), ) return command def _tmplt_bgp_neighbor_prefix_list(config_data): command = [] for list_el in config_data["neighbor"]["prefix_list"]: command.append( - "protocols bgp {as_number} ".format(**config_data) + "protocols bgp ".format(**config_data) + "neighbor {address} prefix-list ".format(**config_data["neighbor"]) + list_el["action"] + " " + str(list_el["prefix_list"]), ) return command def _tmplt_bgp_neighbor_filter_list(config_data): command = [] for list_el in config_data["neighbor"]["filter_list"]: command.append( - "protocols bgp {as_number} ".format(**config_data) + "protocols bgp ".format(**config_data) + "neighbor {address} filter-list ".format(**config_data["neighbor"]) + list_el["action"] + " " + str(list_el["path_list"]), ) return command def _tmplt_bgp_params_distance(config_data): command = ( - "protocols bgp {as_number} parameters distance global ".format(**config_data) + "protocols bgp parameters distance global ".format(**config_data) + config_data["bgp_params"]["distance"]["type"] + " " + str(config_data["bgp_params"]["distance"]["value"]) ) return command -class Bgp_globalTemplate(NetworkTemplate): +class Bgp_globalTemplate14(NetworkTemplate): def __init__(self, lines=None, module=None): prefix = {"set": "set", "remove": "delete"} - super(Bgp_globalTemplate, self).__init__( + super(Bgp_globalTemplate14, self).__init__( lines=lines, tmplt=self, prefix=prefix, module=module, ) # fmt: off PARSERS = [ { "name": "router", "getval": re.compile( r""" ^set \s+protocols \s+bgp + \s*system-as \s+(?P\d+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }}", + "setval": "protocols bgp system-as {{ as_number }}", + "remval": "protocols bgp", "compval": "as_number", "result": { "as_number": "{{ as_num }}", }, }, - { - "name": "aggregate_address", - "getval": re.compile( - r""" - ^set - \s+protocols - \s+bgp - \s+(?P\d+) - \s+aggregate-address - \s+(?P
\S+) - \s*(?Pas-set)* - \s*(?Psummary-only)* - $""", - re.VERBOSE, - ), - "setval": _tmplt_bgp_aggregate_address, - "remval": "protocols bgp {{ as_number }} aggregate-address {{ aggregate_address.prefix }}", - "compval": "aggregate_address", - "result": { - "as_number": "{{ as_num }}", - "aggregate_address": [ - { - "prefix": "{{ address }}", - "as_set": "{{ True if as_set is defined }}", - "summary_only": "{{ True if summary_only is defined }}", - }, - ], - }, - }, { "name": "maximum_paths", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+maximum-paths \s+(?Pebgp|ibgp) \s+(?P\d+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_maximum_paths, "remval": _tmplt_delete_bgp_maximum_paths, "compval": "maximum_paths", "result": { "as_number": "{{ as_num }}", "maximum_paths": [ { "path": "{{ path }}", "count": "{{ count }}", }, ], }, }, { "name": "neighbor.advertisement_interval", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+advertisement-interval \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} advertisement-interval {{ neighbor.advertisement_interval }}", - "remval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} advertisement-interval", + "setval": "protocols bgp neighbor {{ neighbor.address }} advertisement-interval {{ neighbor.advertisement_interval }}", + "remval": "protocols bgp neighbor {{ neighbor.address }} advertisement-interval", "compval": "neighbor.advertisement_interval", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "advertisement_interval": "{{ interval }}", }, }, }, }, { "name": "neighbor.allowas_in", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+allowas-in \s+number \s+(?P\'\d+\') *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} allowas-in number {{ neighbor.allowas_in }}", + "setval": "protocols bgp neighbor {{ neighbor.address }} allowas-in number {{ neighbor.allowas_in }}", "compval": "neighbor.allowas_in", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "allowas_in": "{{ count }}", }, }, }, }, { "name": "neighbor.as_override", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+as-override *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} as-override", + "setval": "protocols bgp neighbor {{ neighbor.address }} as-override", "compval": "neighbor.as_override", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "as_override": "{{ True }}", }, }, }, }, { "name": "neighbor.attribute_unchanged.as_path", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+attribute-unchanged \s+(?Pas-path) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_neighbor_attribute_unchanged_as_path, "compval": "neighbor.attribute_unchanged", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "attribute_unchanged": { "{{ 'as_path' }}": "{{ True }}", }, }, }, }, }, { "name": "neighbor.attribute_unchanged.med", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+attribute-unchanged \s+(?Pmed) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_neighbor_attribute_unchanged_med, "compval": "neighbor.attribute_unchanged", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "attribute_unchanged": { "{{ 'med' }}": "{{ True }}", }, }, }, }, }, { "name": "neighbor.attribute_unchanged.next_hop", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+attribute-unchanged \s+(?Pnext-hop) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_neighbor_attribute_unchanged_next_hop, "compval": "neighbor.attribute_unchanged", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "attribute_unchanged": { "{{ 'next_hop' }}": "{{ True }}", }, }, }, }, }, { "name": "neighbor.capability_dynamic", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+capability \s+(?Pdynamic) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} capability dynamic", + "setval": "protocols bgp neighbor {{ neighbor.address }} capability dynamic", "compval": "neighbor.capability.dynamic", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "capability": { "dynamic": "{{ True if dynamic is defined}}", }, }, }, }, }, { "name": "neighbor.capability_orf", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+capability \s+orf \s+prefix-list \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} capability orf prefix-list {{ neighbor.capability.orf }}", + "setval": "protocols bgp neighbor {{ neighbor.address }} capability orf prefix-list {{ neighbor.capability.orf }}", "compval": "neighbor.capability.orf", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "capability": { "orf": "{{ orf }}", }, }, }, }, }, { "name": "neighbor.default_originate", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+default-originate \s+route-map \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} default-originate route-map {{ neighbor.default_originate }}", + "setval": "protocols bgp neighbor {{ neighbor.address }} default-originate route-map {{ neighbor.default_originate }}", "compval": "neighbor.advertisement_interval", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "default_originate": "{{ map }}", }, }, }, }, { "name": "neighbor.description", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+description \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} description {{ neighbor.description }}", + "setval": "protocols bgp neighbor {{ neighbor.address }} description {{ neighbor.description }}", "compval": "neighbor.description", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "description": "{{ desc }}", }, }, }, }, { "name": "neighbor.disable_capability_negotiation", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+disable-capability-negotiation *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} disable-capability-negotiation", + "setval": "protocols bgp neighbor {{ neighbor.address }} disable-capability-negotiation", "compval": "neighbor.disable_capability_negotiation", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "disable_capability_negotiation": "{{ True }}", }, }, }, }, { "name": "neighbor.disable_connected_check", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+disable-connected-check *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} disable-connected-check", + "setval": "protocols bgp neighbor {{ neighbor.address }} disable-connected-check", "compval": "neighbor.disable_connected_check", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "disable_connected_check": "{{ True }}", }, }, }, }, { "name": "neighbor.disable_send_community", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+disable-send-community \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} disable-send-community {{ neighbor.disable_send_community }}", + "setval": "protocols bgp neighbor {{ neighbor.address }} disable-send-community {{ neighbor.disable_send_community }}", "compval": "neighbor.disable_send_community", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "disable_send_community": "{{ comm }}", }, }, }, }, { "name": "neighbor.distribute_list", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+distribute-list \s+(?Pexport|import) \s+(?P\d+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_neighbor_distribute_list, "compval": "neighbor.distribute_list", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "distribute_list": [ { "action": "{{ action }}", "acl": "{{ list }}", }, ], }, }, }, }, { "name": "neighbor.ebgp_multihop", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+ebgp-multihop \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} ebgp-multihop {{ neighbor.ebgp_multihop }}", + "setval": "protocols bgp neighbor {{ neighbor.address }} ebgp-multihop {{ neighbor.ebgp_multihop }}", "compval": "neighbor.ebgp_multihop", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "ebgp_multihop": "{{ hop|int }}", }, }, }, }, { "name": "neighbor.filter_list", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+filter-list \s+(?Pexport|import) \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_neighbor_filter_list, "compval": "neighbor.filter_list", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "filter_list": [ { "action": "{{ action }}", "path_list": "{{ list }}", }, ], }, }, }, }, { "name": "neighbor.local_as", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+local-as \s+(?P\S+) \s+no-prepend *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} local-as {{ neighbor.local_as }} no-prepend", + "setval": "protocols bgp neighbor {{ neighbor.address }} local-as {{ neighbor.local_as }} no-prepend", "compval": "neighbor.local_as", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "local_as": "{{ as }}", }, }, }, }, { "name": "neighbor.maximum_prefix", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+maximum-prefix \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} maximum-prefix {{ neighbor.maximum_prefix }}", + "setval": "protocols bgp neighbor {{ neighbor.address }} maximum-prefix {{ neighbor.maximum_prefix }}", "compval": "neighbor.maximum_prefix", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "maximum_prefix": "{{ num }}", }, }, }, }, { "name": "neighbor.nexthop_self", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+nexthop-self *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} nexthop-self", + "setval": "protocols bgp neighbor {{ neighbor.address }} nexthop-self", "compval": "neighbor.nexthop_self", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "nexthop_self": "{{ True }}", }, }, }, }, { "name": "neighbor.override_capability", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+override-capability *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} override-capability", + "setval": "protocols bgp neighbor {{ neighbor.address }} override-capability", "compval": "neighbor.override_capability", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "override_capability": "{{ True }}", }, }, }, }, { "name": "neighbor.passive", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+passive *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} nexthop-self", + "setval": "protocols bgp neighbor {{ neighbor.address }} passive", "compval": "neighbor.passive", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "passive": "{{ True }}", }, }, }, }, { "name": "neighbor.password", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+password \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} password {{ neighbor.password }}", + "setval": "protocols bgp neighbor {{ neighbor.address }} password {{ neighbor.password }}", "compval": "neighbor.password", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "password": "{{ pwd }}", }, }, }, }, { "name": "neighbor.peer_group_name", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+peer-group \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} peer-group {{ neighbor.peer_group_name }}", + "setval": "protocols bgp neighbor {{ neighbor.address }} peer-group {{ neighbor.peer_group_name }}", "compval": "neighbor.peer_group_name", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "peer_group_name": "{{ name }}", }, }, }, }, { "name": "neighbor.port", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+port \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} port {{ neighbor.port }}", + "setval": "protocols bgp neighbor {{ neighbor.address }} port {{ neighbor.port }}", "compval": "neighbor.port", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "port": "{{ num|int }}", }, }, }, }, { "name": "neighbor.prefix_list", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+prefix-list \s+(?Pexport|import) \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_neighbor_prefix_list, "compval": "neighbor.prefix_list", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "prefix_list": [ { "action": "{{ action }}", "prefix_list": "{{ list }}", }, ], }, }, }, }, { "name": "neighbor.remote_as", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+remote-as \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} remote-as {{ neighbor.remote_as }}", + "setval": "protocols bgp neighbor {{ neighbor.address }} remote-as {{ neighbor.remote_as }}", "compval": "neighbor.remote_as", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "remote_as": "{{ num|int }}", }, }, }, }, { "name": "neighbor.remove_private_as", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+remote-private-as *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} remote-private-as", + "setval": "protocols bgp neighbor {{ neighbor.address }} remote-private-as", "compval": "neighbor.remove_private_as", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "remove_private_as": "{{ True }}", }, }, }, }, { "name": "neighbor.route_map", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+route-map \s+(?Pexport|import) \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_neighbor_route_map, "compval": "neighbor.route_map", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "route_map": [ { "action": "{{ action }}", "route_map": "{{ map }}", }, ], }, }, }, }, { "name": "neighbor.route_reflector_client", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+route-reflector-client *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} router-reflector-client", + "setval": "protocols bgp neighbor {{ neighbor.address }} router-reflector-client", "compval": "neighbor.route_reflector_client", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "route_reflector_client": "{{ True }}", }, }, }, }, { "name": "neighbor.route_server_client", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+route-server-client *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} route-server-client", + "setval": "protocols bgp neighbor {{ neighbor.address }} route-server-client", "compval": "neighbor.route_server_client", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "route_server_client": "{{ True }}", }, }, }, }, { "name": "neighbor.shutdown", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+shutdown *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} shutdown", + "setval": "protocols bgp neighbor {{ neighbor.address }} shutdown", "compval": "neighbor.shutdown", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "shutdown": "{{ True }}", }, }, }, }, { "name": "neighbor.soft_reconfiguration", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+soft-reconfiguration \s+inbound *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} soft-reconfiguration", + "setval": "protocols bgp neighbor {{ neighbor.address }} soft-reconfiguration", "compval": "neighbor.soft_reconfiguration", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "soft_reconfiguration": "{{ True }}", }, }, }, }, { "name": "neighbor.strict_capability_match", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+strict-capability-match *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} strict-capability-match", + "setval": "protocols bgp neighbor {{ neighbor.address }} strict-capability-match", "compval": "neighbor.strict_capability_match", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "strict_capability_match": "{{ True }}", }, }, }, }, { "name": "neighbor.unsuppress_map", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+unsuppress-map \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} unsuppress-map {{ neighbor.unsuppress_map }}", + "setval": "protocols bgp neighbor {{ neighbor.address }} unsuppress-map {{ neighbor.unsuppress_map }}", "compval": "neighbor.unsuppress_map", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "unsuppress_map": "{{ map }}", }, }, }, }, { "name": "neighbor.update_source", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+update-source \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} update-source {{ neighbor.update_source }}", + "setval": "protocols bgp neighbor {{ neighbor.address }} update-source {{ neighbor.update_source }}", "compval": "neighbor.update_source", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "update_source": "{{ src }}", }, }, }, }, { "name": "neighbor.weight", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+weight \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} weight {{ neighbor.weight }}", + "setval": "protocols bgp neighbor {{ neighbor.address }} weight {{ neighbor.weight }}", "compval": "neighbor.weight", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "weight": "{{ num }}", }, }, }, }, { "name": "neighbor.ttl_security", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+ttl-security \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} ttl-security {{ neighbor.ttl_security }}", + "setval": "protocols bgp neighbor {{ neighbor.address }} ttl-security {{ neighbor.ttl_security }}", "compval": "neighbor.ttl_security", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "ttl_security": "{{ ttl|int }}", }, }, }, }, { "name": "neighbor.timers", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+neighbor \s+(?P
\S+) \s+timers \s+(?Pconnect|holdtime|keepalive) \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_neighbor_timers, - "remval": "protocols bgp {{ as_number }} neighbor {{ neighbor.address }} timers", + "remval": "protocols bgp neighbor {{ neighbor.address }} timers", "compval": "neighbor.timers", "result": { "as_number": "{{ as_num }}", "neighbor": { "{{ address }}": { "address": "{{ address }}", "timers": { "{{ type }}": "{{ sec }}", }, }, }, }, }, - { - "name": "network.backdoor", - "getval": re.compile( - r""" - ^set - \s+protocols - \s+bgp - \s+(?P\d+) - \s+network - \s+(?P
\S+) - \s+backdoor - *$""", - re.VERBOSE, - ), - "setval": "protocols bgp {{ as_number }} network {{ network.address }} backdoor", - "remval": "protocols bgp {{ as_number }} network {{ network.address }}", - "compval": "network.backdoor", - "result": { - "as_number": "{{ as_num }}", - "network": [ - { - "address": "{{ address }}", - "backdoor": "{{ True }}", - }, - ], - }, - }, - { - "name": "network.route_map", - "getval": re.compile( - r""" - ^set - \s+protocols - \s+bgp - \s+(?P\d+) - \s+network - \s+(?P
\S+) - \s+route-map - \s+(?P\S+) - *$""", - re.VERBOSE, - ), - "setval": "protocols bgp {{ as_number }} network {{ network.address }} route-map {{ network.route_map }}", - "remval": "protocols bgp {{ as_number }} network {{ network.address }}", - "compval": "network.route_map", - "result": { - "as_number": "{{ as_num }}", - "network": [ - { - "address": "{{ address }}", - "route_map": "{{ map }}", - }, - ], - }, - }, - { - "name": "redistribute.metric", - "getval": re.compile( - r""" - ^set - \s+protocols - \s+bgp - \s+(?P\d+) - \s+redistribute - \s+(?P\S+) - \s+metric - \s+(?P\S+) - *$""", - re.VERBOSE, - ), - "setval": "protocols bgp {{ as_number }} redistribute {{ redistribute.protocol }} metric {{ redistribute.metric }}", - "remval": _tmplt_bgp_delete_redistribute, - "compval": "redistribute", - "result": { - "as_number": "{{ as_num }}", - "redistribute": [ - { - "protocol": "{{ proto }}", - "metric": "{{ val|int }}", - }, - ], - }, - }, - { - "name": "redistribute.route_map", - "getval": re.compile( - r""" - ^set - \s+protocols - \s+bgp - \s+(?P\d+) - \s+redistribute - \s+(?P\S+) - \s+route-map - \s+(?P\S+) - *$""", - re.VERBOSE, - ), - "setval": "protocols bgp {{ as_number }} redistribute {{ redistribute.protocol }} route-map {{ redistribute.route_map }}", - "remval": _tmplt_bgp_delete_redistribute, - "compval": "redistribute", - "result": { - "as_number": "{{ as_num }}", - "redistribute": [ - { - "protocol": "{{ proto }}", - "route_map": "{{ val }}", - }, - ], - }, - }, { "name": "timers", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+timers \s+(?P\S+) \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_timers, - "remval": "protocols bgp {{ as_number }} timers", + "remval": "protocols bgp timers", "compval": "timers", "result": { "as_number": "{{ as_num }}", "timers": { "{{ type }}": "{{ val }}", }, }, }, { "name": "bgp_params.always_compare_med", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+parameters \s+always-compare-med *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} parameters always-compare-med", + "setval": "protocols bgp parameters always-compare-med", "compval": "bgp_params.always_compare_med", "result": { "as_number": "{{ as_num }}", "bgp_params": { "always_compare_med": "{{ True }}", }, }, }, { "name": "bgp_params.bestpath.as_path", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+parameters \s+bestpath \s+as-path \s+(?Pconfed|ignore) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} parameters bestpath as-path {{ bgp_params.bestpath.as_path }}", + "setval": "protocols bgp parameters bestpath as-path {{ bgp_params.bestpath.as_path }}", "compval": "bgp_params.bestpath.as_path", "result": { "as_number": "{{ as_num }}", "bgp_params": { "bestpath": { "as_path": "{{ path }}", }, }, }, }, { "name": "bgp_params.bestpath.compare_routerid", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+parameters \s+bestpath \s+compare-routerid *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} parameters bestpath compare-routerid", + "setval": "protocols bgp parameters bestpath compare-routerid", "compval": "bgp_params.bestpath.compare_routerid", "result": { "as_number": "{{ as_num }}", "bgp_params": { "bestpath": { "compare_routerid": "{{ True }}", }, }, }, }, { "name": "bgp_params.bestpath.med", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+parameters \s+bestpath \s+med \s+(?Pconfed|missing-as-worst) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} parameters bestpath med {{ bestpath.med }}", + "setval": "protocols bgp parameters bestpath med {{ bestpath.med }}", "compval": "bgp_params.bestpath.med", "result": { "as_number": "{{ as_num }}", "bgp_params": { "bestpath": { "med": "{{ path }}", }, }, }, }, { "name": "bgp_params.cluster_id", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+parameters \s+cluster-id \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} parameters cluster-id {{ bgp_params.cluster_id }}", + "setval": "protocols bgp parameters cluster-id {{ bgp_params.cluster_id }}", "compval": "bgp_params.cluster_id", "result": { "as_number": "{{ as_num }}", "bgp_params": { "cluster_id": "{{ id }}", }, }, }, { "name": "bgp_params.confederation", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+parameters \s+confederation \s+(?Pidentifier|peers) \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_params_confederation, "compval": "bgp_params.always_compare_med", "result": { "as_number": "{{ as_num }}", "bgp_params": { "confederation": [ { "peers": "{{ val if type == 'peers' }}", "identifier": "{{ val if type == 'identifier' }}", }, ], }, }, }, { "name": "bgp_params.dampening_half_life", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+parameters \s+dampening \s+half-life \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} parameters dampening half-life {{ bgp_params.dampening.half_life}}", + "setval": "protocols bgp parameters dampening half-life {{ bgp_params.dampening.half_life}}", "compval": "bgp_params.dampening.half_life", "result": { "as_number": "{{ as_num }}", "bgp_params": { "dampening": { "half_life": "{{ val }}", }, }, }, }, { "name": "bgp_params.dampening_max_suppress_time", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+parameters \s+dampening \s+max-suppress-time \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} parameters dampening max-suppress-time {{ bgp_params.dampening.max_suppress_time}}", + "setval": "protocols bgp parameters dampening max-suppress-time {{ bgp_params.dampening.max_suppress_time}}", "compval": "bgp_params.dampening.max_suppress_time", "result": { "as_number": "{{ as_num }}", "bgp_params": { "dampening": { "max_suppress_time": "{{ val }}", }, }, }, }, { "name": "bgp_params.dampening_re_use", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+parameters \s+dampening \s+re-use \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} parameters dampening re-use {{ bgp_params.dampening.re_use}}", + "setval": "protocols bgp parameters dampening re-use {{ bgp_params.dampening.re_use}}", "compval": "bgp_params.dampening.re_use", "result": { "as_number": "{{ as_num }}", "bgp_params": { "dampening": { "re_use": "{{ val }}", }, }, }, }, { "name": "bgp_params.dampening_start_suppress_time", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+parameters \s+dampening \s+start-suppress-time \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} parameters dampening start-suppress-time {{ bgp_params.dampening.start_suppress_time}}", + "setval": "protocols bgp parameters dampening start-suppress-time {{ bgp_params.dampening.start_suppress_time}}", "compval": "bgp_params.dampening.start_suppress_time", "result": { "as_number": "{{ as_num }}", "bgp_params": { "dampening": { "start_suppress_time": "{{ val }}", }, }, }, }, { "name": "bgp_params.default", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+parameters \s+default \s*(?Pno-ipv4-unicast)* \s*(?Plocal-pref\s\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_params_default, - "remval": "protocols bgp {{ as_number }} parameters default", + "remval": "protocols bgp parameters default", "compval": "bgp_params.default", "result": { "as_number": "{{ as_num }}", "bgp_params": { "default": { "no_ipv4_unicast": "{{ True if no_ipv4_unicast is defined }}", "local_pref": "{{ local_pref.split(" " )[1] if local_pref is defined }}", }, }, }, }, { "name": "bgp_params.deterministic_med", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+parameters \s+deterministic-med *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} parameters deterministic-med", + "setval": "protocols bgp parameters deterministic-med", "compval": "bgp_params.deterministic_med", "result": { "as_number": "{{ as_num }}", "bgp_params": { "deterministic_med": "{{ True }}", }, }, }, { "name": "bgp_params.disbale_network_import_check", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+parameters \s+disable-network-import-check *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} parameters disable-network-import-check", + "setval": "protocols bgp parameters disable-network-import-check", "compval": "bgp_params.disable_network_import_check", "result": { "as_number": "{{ as_num }}", "bgp_params": { "disable_network_import_check": "{{ True }}", }, }, }, { "name": "bgp_params.distance.prefix", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+parameters \s+distance\sprefix \s+(?P\S+) \s+distance \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} parameters distance prefix {{ bgp_params.distance.prefix }} distance {{ bgp_params.distance.value }}", + "setval": "protocols bgp parameters distance prefix {{ bgp_params.distance.prefix }} distance {{ bgp_params.distance.value }}", "compval": "bgp_params.distance.prefix", - "remval": "protocols bgp {{ as_number }} parameters distance prefix", + "remval": "protocols bgp parameters distance prefix", "result": { "as_number": "{{ as_num }}", "bgp_params": { "distance": [ { "prefix": "{{ prefix }}", "value": "{{ val }}", }, ], }, }, }, { "name": "bgp_params.distance.global", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+parameters \s+distance\sglobal \s+(?P\S+) \s+(?P\S+) *$""", re.VERBOSE, ), "setval": _tmplt_bgp_params_distance, - "remval": "protocols bgp {{ as_number }} parameters distance global", + "remval": "protocols bgp parameters distance global", "compval": "bgp_params.distance", "result": { "as_number": "{{ as_num }}", "bgp_params": { "distance": [ { "type": "{{ type }}", "value": "{{ val }}", }, ], }, }, }, { "name": "bgp_params.enforce_first_as", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+parameters \s+enforce-first-as *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} parameters enforce-first-as", + "setval": "protocols bgp parameters enforce-first-as", "compval": "bgp_params.enforce_first_as", "result": { "as_number": "{{ as_num }}", "bgp_params": { "enforce_first_as": "{{ True }}", }, }, }, { "name": "bgp_params.graceful_restart", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+parameters \s+graceful-restart\s+stalepath-time \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} parameters graceful-restart stalepath-time {{ bgp_params.graceful_restart }}", + "setval": "protocols bgp parameters graceful-restart stalepath-time {{ bgp_params.graceful_restart }}", "compval": "bgp_params.graceful_restart", "result": { "as_number": "{{ as_num }}", "bgp_params": { "graceful_restart": "{{ val }}", }, }, }, { "name": "bgp_params.log_neighbor_changes", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+parameters \s+log-neighbor-changes *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} parameters log-neighbor-changes", + "setval": "protocols bgp parameters log-neighbor-changes", "compval": "bgp_params.log_neighbor_changes", "result": { "as_number": "{{ as_num }}", "bgp_params": { "log_neighbor_changes": "{{ True }}", }, }, }, { "name": "bgp_params.no_client_to_client_reflection", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+parameters \s+no-client-to-client-reflection *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} parameters no-client-to-client-reflection", + "setval": "protocols bgp parameters no-client-to-client-reflection", "compval": "bgp_params.log_neighbor_changes", "result": { "as_number": "{{ as_num }}", "bgp_params": { "no_client_to_client_reflection": "{{ True }}", }, }, }, { "name": "bgp_params.no_fast_external_failover", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+parameters \s+no-fast-external-failover *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} parameters no-fast-external-failover", + "setval": "protocols bgp parameters no-fast-external-failover", "compval": "bgp_params.no_fast_external_failover", "result": { "as_number": "{{ as_num }}", "bgp_params": { "no_fast_external_failover": "{{ True }}", }, }, }, { "name": "bgp_params.routerid", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+parameters \s+router-id \s+(?P\S+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} parameters router-id {{ bgp_params.router_id }}", + "setval": "protocols bgp parameters router-id {{ bgp_params.router_id }}", "compval": "bgp_params.router_id", "result": { "as_number": "{{ as_num }}", "bgp_params": { "router_id": "{{ id }}", }, }, }, { "name": "bgp_params.scan_time", "getval": re.compile( r""" ^set \s+protocols \s+bgp - \s+(?P\d+) \s+parameters \s+scan-time \s+(?P\d+) *$""", re.VERBOSE, ), - "setval": "protocols bgp {{ as_number }} parameters scan-time {{ bgp_params.scan_time }}", + "setval": "protocols bgp parameters scan-time {{ bgp_params.scan_time }}", "compval": "bgp_params.scan_time", "result": { "as_number": "{{ as_num }}", "bgp_params": { "scan_time": "{{ val }}", }, }, }, - ] # fmt: on diff --git a/plugins/modules/vyos_bgp_address_family.py b/plugins/modules/vyos_bgp_address_family.py index b3756e2e..14c3605d 100644 --- a/plugins/modules/vyos_bgp_address_family.py +++ b/plugins/modules/vyos_bgp_address_family.py @@ -1,1228 +1,1229 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # Copyright 2024 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) """ The module file for vyos_bgp_address_family """ from __future__ import absolute_import, division, print_function __metaclass__ = type DOCUMENTATION = """ module: vyos_bgp_address_family version_added: 1.0.0 short_description: BGP Address Family resource module description: - This module manages BGP address family configuration of interfaces on devices running VYOS. +- Tested against VYOS 1.3, 1.4 author: Gomathi Selvi Srinivasan (@GomathiselviS) options: config: description: A dict of BGP global configuration for interfaces. type: dict suboptions: as_number: description: - AS number type: int address_family: description: BGP address-family parameters. type: list elements: dict suboptions: afi: description: BGP address family settings. type: str choices: ['ipv4', 'ipv6'] aggregate_address: description: - BGP aggregate network. type: list elements: dict suboptions: prefix: description: BGP aggregate network. type: str as_set: description: Generate AS-set path information for this aggregate address. type: bool summary_only: description: Announce the aggregate summary network only. type: bool networks: description: BGP network type: list elements: dict suboptions: prefix: description: BGP network address type: str path_limit: description: AS path hop count limit type: int backdoor: description: Network as a backdoor route. type: bool route_map: description: Route-map to modify route attributes type: str redistribute: description: Redistribute routes from other protocols into BGP type: list elements: dict suboptions: protocol: description: types of routes to be redistributed. type: str choices: ['connected', 'kernel', 'ospf', 'ospfv3', 'rip', 'ripng', 'static'] table: description: Redistribute non-main Kernel Routing Table. type: str route_map: description: Route map to filter redistributed routes type: str metric: description: Metric for redistributed routes. type: int neighbors: description: BGP neighbor type: list elements: dict suboptions: neighbor_address: description: BGP neighbor address (v4/v6). type: str address_family: description: address family. type: list elements: dict suboptions: afi: description: BGP neighbor parameters. type: str choices: ['ipv4', 'ipv6'] allowas_in: description: Number of occurrences of AS number. type: int as_override: description: AS for routes sent to this neighbor to be the local AS. type: bool attribute_unchanged: description: BGP attributes are sent unchanged. type: dict suboptions: as_path: description: as_path attribute type: bool med: description: med attribute type: bool next_hop: description: next_hop attribute type: bool capability: description: Advertise capabilities to this neighbor. type: dict suboptions: dynamic: description: Advertise dynamic capability to this neighbor. type: bool orf: description: Advertise ORF capability to this neighbor. type: str choices: ['send', 'receive'] default_originate: description: Send default route to this neighbor type: str distribute_list: description: Access-list to filter route updates to/from this neighbor. type: list elements: dict suboptions: action: description: Access-list to filter outgoing/incoming route updates to this neighbor type: str choices: ['export', 'import'] acl: description: Access-list number. type: int filter_list: description: As-path-list to filter route updates to/from this neighbor. type: list elements: dict suboptions: action: description: filter outgoing/incoming route updates type: str choices: ['export', 'import'] path_list: description: As-path-list to filter type: str maximum_prefix: description: Maximum number of prefixes to accept from this neighbor nexthop-self Nexthop for routes sent to this neighbor to be the local router. type: int nexthop_local: description: Nexthop attributes. type: bool nexthop_self: description: Nexthop for routes sent to this neighbor to be the local router. type: bool peer_group: description: IPv4 peer group for this peer type: str prefix_list: description: Prefix-list to filter route updates to/from this neighbor. type: list elements: dict suboptions: action: description: filter outgoing/incoming route updates type: str choices: ['export', 'import'] prefix_list: description: Prefix-list to filter type: str remove_private_as: description: Remove private AS numbers from AS path in outbound route updates type: bool route_map: description: Route-map to filter route updates to/from this neighbor. type: list elements: dict suboptions: action: description: filter outgoing/incoming route updates type: str choices: ['export', 'import'] route_map: description: route-map to filter type: str route_reflector_client: description: Neighbor as a route reflector client type: bool route_server_client: description: Neighbor is route server client type: bool soft_reconfiguration: description: Soft reconfiguration for neighbor type: bool unsupress_map: description: Route-map to selectively unsuppress suppressed routes type: str weight: description: Default weight for routes from this neighbor type: int running_config: type: str description: - This option is used only with state I(parsed). - The value of this option should be the output received from the VYOS device by executing the command B(show configuration command | match bgp). - The state I(parsed) reads the configuration from C(running_config) option and transforms it into Ansible structured data as per the resource module's argspec and the value is then returned in the I(parsed) key within the result. state: description: - The state the configuration should be left in. type: str choices: - merged - replaced - deleted - gathered - parsed - rendered - purged - overridden default: merged """ EXAMPLES = """ # Using merged # Before state # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # vyos@vyos:~$ - name: Merge provided configuration with device configuration vyos.vyos.vyos_bgp_address_family: config: as_number: "100" address_family: - afi: "ipv4" redistribute: - protocol: "static" metric: 50 neighbors: - neighbor_address: "20.33.1.1/24" address_family: - afi: "ipv4" allowas_in: 4 as_override: true attribute_unchanged: med: true - afi: "ipv6" default_originate: "map01" distribute_list: - action: "export" acl: 10 - neighbor_address: "100.11.34.12" address_family: - afi: "ipv4" maximum_prefix: 45 nexthop_self: true route_map: - action: "export" route_map: "map01" - action: "import" route_map: "map01" weight: 50 # After State: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 100 address-family ipv4-unicast redistribute static metric '50' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast allowas-in number '4' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast as-override # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast attribute-unchanged med # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast default-originate route-map 'map01' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast distribute-list export '10' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast maximum-prefix '45' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast nexthop-self # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast route-map export 'map01' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast route-map import 'map01' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast weight '50' # vyos@vyos:~$ # # Module Execution: # # "after": { # "address_family": [ # { # "afi": "ipv4", # "redistribute": [ # { # "metric": 50, # "protocol": "static" # } # ] # } # ], # "as_number": 100, # "neighbors": [ # { # "address_family": [ # { # "afi": "ipv4", # "maximum_prefix": 45, # "nexthop_self": true, # "route_map": [ # { # "action": "export", # "route_map": "map01" # }, # { # "action": "import", # "route_map": "map01" # } # ], # "weight": 50 # } # ], # "neighbor_address": "100.11.34.12" # }, # { # "address_family": [ # { # "afi": "ipv4", # "allowas_in": 4, # "as_override": true, # "attribute_unchanged": { # "med": true # } # }, # { # "afi": "ipv6", # "default_originate": "map01", # "distribute_list": [ # { # "acl": 10, # "action": "export" # } # ] # } # ], # "neighbor_address": "20.33.1.1/24" # } # ] # }, # "before": {}, # "changed": true, # "commands": [ # "set protocols bgp 100 address-family ipv4-unicast redistribute static metric 50", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast allowas-in number 4", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast as-override", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast attribute-unchanged med", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast default-originate route-map map01", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast distribute-list export 10", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast maximum-prefix 45", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast nexthop-self", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast route-map export map01", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast route-map import map01", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast weight 50" # ], # # Using replaced: # Before state: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 100 address-family ipv4-unicast redistribute static metric '50' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast allowas-in number '4' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast as-override # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast attribute-unchanged med # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast default-originate route-map 'map01' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast distribute-list export '10' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast maximum-prefix '45' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast nexthop-self # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast route-map export 'map01' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast route-map import 'map01' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast weight '50' # vyos@vyos:~$ - name: Replace provided configuration with device configuration vyos.vyos.vyos_bgp_address_family: config: as_number: "100" neighbors: - neighbor_address: "100.11.34.12" address_family: - afi: "ipv4" allowas_in: 4 as_override: true attribute_unchanged: med: true - afi: "ipv6" default_originate: "map01" distribute_list: - action: "export" acl: 10 - neighbor_address: "20.33.1.1/24" address_family: - afi: "ipv6" maximum_prefix: 45 nexthop_self: true state: replaced # After State: # # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 100 address-family ipv4-unicast redistribute static metric '50' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast maximum-prefix '45' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast nexthop-self # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast allowas-in number '4' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast as-override # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast attribute-unchanged med # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast default-originate route-map 'map01' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast distribute-list export '10' # vyos@vyos:~$ # # # # Module Execution: # "after": { # "address_family": [ # { # "afi": "ipv4", # "redistribute": [ # { # "metric": 50, # "protocol": "static" # } # ] # } # ], # "as_number": 100, # "neighbors": [ # { # "address_family": [ # { # "afi": "ipv4", # "allowas_in": 4, # "as_override": true, # "attribute_unchanged": { # "med": true # } # }, # { # "afi": "ipv6", # "default_originate": "map01", # "distribute_list": [ # { # "acl": 10, # "action": "export" # } # ] # } # ], # "neighbor_address": "100.11.34.12" # }, # { # "address_family": [ # { # "afi": "ipv4" # }, # { # "afi": "ipv6", # "maximum_prefix": 45, # "nexthop_self": true # } # ], # "neighbor_address": "20.33.1.1/24" # } # ] # }, # "before": { # "address_family": [ # { # "afi": "ipv4", # "redistribute": [ # { # "metric": 50, # "protocol": "static" # } # ] # } # ], # "as_number": 100, # "neighbors": [ # { # "address_family": [ # { # "afi": "ipv4", # "maximum_prefix": 45, # "nexthop_self": true, # "route_map": [ # { # "action": "export", # "route_map": "map01" # }, # { # "action": "import", # "route_map": "map01" # } # ], # "weight": 50 # } # ], # "neighbor_address": "100.11.34.12" # }, # { # "address_family": [ # { # "afi": "ipv4", # "allowas_in": 4, # "as_override": true, # "attribute_unchanged": { # "med": true # } # }, # { # "afi": "ipv6", # "default_originate": "map01", # "distribute_list": [ # { # "acl": 10, # "action": "export" # } # ] # } # ], # "neighbor_address": "20.33.1.1/24" # } # ] # }, # "changed": true, # "commands": [ # "delete protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast distribute-list", # "delete protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast default-originate", # "delete protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast attribute-unchanged", # "delete protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast as-override", # "delete protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast allowas-in", # "delete protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast weight", # "delete protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast route-map", # "delete protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast nexthop-self", # "delete protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast maximum-prefix", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast allowas-in number 4", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast as-override", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast attribute-unchanged med", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast default-originate route-map map01", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast distribute-list export 10", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast maximum-prefix 45", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast nexthop-self" # ], # Using overridden # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 100 address-family ipv4-unicast network 35.1.1.0/24 backdoor # set protocols bgp 100 address-family ipv4-unicast redistribute static metric '50' # set protocols bgp 100 address-family ipv6-unicast aggregate-address 6601:1:1:1::/64 summary-only # set protocols bgp 100 address-family ipv6-unicast network 5001:1:1:1::/64 route-map 'map01' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast maximum-prefix '45' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast nexthop-self # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast allowas-in number '4' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast as-override # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast attribute-unchanged med # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast default-originate route-map 'map01' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast distribute-list export '10' # vyos@vyos:~$ - name: Override vyos.vyos.vyos_bgp_address_family: config: as_number: "100" neighbors: - neighbor_address: "100.11.34.12" address_family: - afi: "ipv6" maximum_prefix: 45 nexthop_self: true route_map: - action: "import" route_map: "map01" address_family: - afi: "ipv4" aggregate_address: - prefix: "60.9.2.0/24" summary_only: true - afi: "ipv6" redistribute: - protocol: "static" metric: 50 state: overridden # After State # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 100 address-family ipv4-unicast aggregate-address 60.9.2.0/24 summary-only # set protocols bgp 100 address-family ipv6-unicast redistribute static metric '50' # set protocols bgp 100 neighbor 20.33.1.1/24 # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast maximum-prefix '45' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast nexthop-self # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast route-map import 'map01' # vyos@vyos:~$ # Module Execution: # "after": { # "address_family": [ # { # "afi": "ipv4", # "aggregate_address": [ # { # "prefix": "60.9.2.0/24", # "summary_only": true # } # ] # }, # { # "afi": "ipv6", # "redistribute": [ # { # "metric": 50, # "protocol": "static" # } # ] # } # ], # "as_number": 100, # "neighbors": [ # { # "address_family": [ # { # "afi": "ipv4" # }, # { # "afi": "ipv6", # "maximum_prefix": 45, # "nexthop_self": true, # "route_map": [ # { # "action": "import", # "route_map": "map01" # } # ] # } # ], # "neighbor_address": "100.11.34.12" # } # ] # }, # "before": { # "address_family": [ # { # "afi": "ipv4", # "networks": [ # { # "backdoor": true, # "prefix": "35.1.1.0/24" # } # ], # "redistribute": [ # { # "metric": 50, # "protocol": "static" # } # ] # }, # { # "afi": "ipv6", # "aggregate_address": [ # { # "prefix": "6601:1:1:1::/64", # "summary_only": true # } # ], # "networks": [ # { # "prefix": "5001:1:1:1::/64", # "route_map": "map01" # } # ] # } # ], # "as_number": 100, # "neighbors": [ # { # "address_family": [ # { # "afi": "ipv4", # "allowas_in": 4, # "as_override": true, # "attribute_unchanged": { # "med": true # } # }, # { # "afi": "ipv6", # "default_originate": "map01", # "distribute_list": [ # { # "acl": 10, # "action": "export" # } # ] # } # ], # "neighbor_address": "100.11.34.12" # }, # { # "address_family": [ # { # "afi": "ipv4" # }, # { # "afi": "ipv6", # "maximum_prefix": 45, # "nexthop_self": true # } # ], # "neighbor_address": "20.33.1.1/24" # } # ] # }, # "changed": true, # "commands": [ # "delete protocols bgp 100 neighbor 20.33.1.1/24 address-family", # "delete protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast distribute-list", # "delete protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast default-originate", # "delete protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast attribute-unchanged", # "delete protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast as-override", # "delete protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast allowas-in", # "delete protocols bgp 100 address-family ipv6 aggregate-address", # "delete protocols bgp 100 address-family ipv6 network", # "delete protocols bgp 100 address-family ipv4 network", # "delete protocols bgp 100 address-family ipv4 redistribute", # "set protocols bgp 100 address-family ipv4-unicast aggregate-address 60.9.2.0/24 summary-only", # "set protocols bgp 100 address-family ipv6-unicast redistribute static metric 50", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast maximum-prefix 45", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast nexthop-self", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast route-map import map01" # ], # # Using deleted: # Before State: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 100 address-family ipv4-unicast aggregate-address 60.9.2.0/24 summary-only # set protocols bgp 100 address-family ipv4-unicast redistribute static metric '50' # set protocols bgp 100 address-family ipv6-unicast redistribute static metric '50' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast allowas-in number '4' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast as-override # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast attribute-unchanged med # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast default-originate route-map 'map01' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast distribute-list export '10' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast maximum-prefix '45' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast nexthop-self # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast route-map export 'map01' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast route-map import 'map01' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast weight '50' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast maximum-prefix '45' # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast nexthop-self # set protocols bgp 100 neighbor 100.11.34.12 address-family ipv6-unicast route-map import 'map01' # vyos@vyos:~$ - name: Delete vyos.vyos.vyos_bgp_address_family: config: as_number: "100" neighbors: - neighbor_address: "20.33.1.1/24" address_family: - afi: "ipv6" - neighbor_address: "100.11.34.12" address_family: - afi: "ipv4" state: deleted # After State: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 100 address-family ipv6-unicast redistribute static metric '50' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast allowas-in number '4' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast as-override # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast attribute-unchanged med # set protocols bgp 100 neighbor 100.11.34.12 # vyos@vyos:~$ # # # Module Execution: # # "after": { # "address_family": [ # { # "afi": "ipv6", # "redistribute": [ # { # "metric": 50, # "protocol": "static" # } # ] # } # ], # "as_number": 100, # "neighbors": [ # { # "address_family": [ # { # "afi": "ipv4", # "allowas_in": 4, # "as_override": true, # "attribute_unchanged": { # "med": true # } # } # ], # "neighbor_address": "20.33.1.1/24" # } # ] # }, # "before": { # "address_family": [ # { # "afi": "ipv4", # "aggregate_address": [ # { # "prefix": "60.9.2.0/24", # "summary_only": true # } # ], # "redistribute": [ # { # "metric": 50, # "protocol": "static" # } # ] # }, # { # "afi": "ipv6", # "redistribute": [ # { # "metric": 50, # "protocol": "static" # } # ] # } # ], # "as_number": 100, # "neighbors": [ # { # "address_family": [ # { # "afi": "ipv4", # "maximum_prefix": 45, # "nexthop_self": true, # "route_map": [ # { # "action": "export", # "route_map": "map01" # }, # { # "action": "import", # "route_map": "map01" # } # ], # "weight": 50 # }, # { # "afi": "ipv6", # "maximum_prefix": 45, # "nexthop_self": true, # "route_map": [ # { # "action": "import", # "route_map": "map01" # } # ] # } # ], # "neighbor_address": "100.11.34.12" # }, # { # "address_family": [ # { # "afi": "ipv4", # "allowas_in": 4, # "as_override": true, # "attribute_unchanged": { # "med": true # } # }, # { # "afi": "ipv6", # "default_originate": "map01", # "distribute_list": [ # { # "acl": 10, # "action": "export" # } # ] # } # ], # "neighbor_address": "20.33.1.1/24" # } # ] # }, # "changed": true, # "commands": [ # "delete protocols bgp 100 address-family ipv4-unicast", # "delete protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast", # "delete protocols bgp 100 neighbor 100.11.34.12 address-family" # ], # # using parsed: # parsed.cfg # set protocols bgp 65536 address-family ipv4-unicast aggregate-address 192.0.2.0/24 as-set # set protocols bgp 65536 address-family ipv4-unicast network 192.1.13.0/24 route-map 'map01' # set protocols bgp 65536 address-family ipv4-unicast network 192.2.13.0/24 backdoor # set protocols bgp 65536 address-family ipv6-unicast redistribute ripng metric '20' # set protocols bgp 65536 neighbor 192.0.2.25 address-family ipv4-unicast route-map export 'map01' # set protocols bgp 65536 neighbor 192.0.2.25 address-family ipv4-unicast soft-reconfiguration inbound # set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged next-hop - name: parse configs vyos.vyos.vyos_bgp_address_family: running_config: "{{ lookup('file', './parsed.cfg') }}" state: parsed # Module execution result: # # "parsed": { # "address_family": [ # { # "afi": "ipv4", # "aggregate_address": [ # { # "as_set": true, # "prefix": "192.0.2.0/24" # } # ], # "networks": [ # { # "prefix": "192.1.13.0/24", # "route_map": "map01" # }, # { # "backdoor": true, # "prefix": "192.2.13.0/24" # } # ] # }, # { # "afi": "ipv6", # "redistribute": [ # { # "metric": 20, # "protocol": "ripng" # } # ] # } # ], # "as_number": 65536, # "neighbors": [ # { # "address_family": [ # { # "afi": "ipv4", # "route_map": [ # { # "action": "export", # "route_map": "map01" # } # ], # "soft_reconfiguration": true # } # ], # "neighbor_address": "192.0.2.25" # }, # { # "address_family": [ # { # "afi": "ipv6", # "attribute_unchanged": { # "next_hop": true # } # } # ], # "neighbor_address": "203.0.113.5" # } # ] # # Using gathered: # Native config: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 100 address-family ipv4-unicast network 35.1.1.0/24 backdoor # set protocols bgp 100 address-family ipv4-unicast redistribute static metric '50' # set protocols bgp 100 address-family ipv6-unicast aggregate-address 6601:1:1:1::/64 summary-only # set protocols bgp 100 address-family ipv6-unicast network 5001:1:1:1::/64 route-map 'map01' # set protocols bgp 100 address-family ipv6-unicast redistribute static metric '50' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast allowas-in number '4' # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast as-override # set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast attribute-unchanged med # set protocols bgp 100 neighbor 100.11.34.12 - name: gather configs vyos.vyos.vyos_bgp_address_family: state: gathered # Module execution result: # # "gathered": { # "address_family": [ # { # "afi": "ipv4", # "networks": [ # { # "backdoor": true, # "prefix": "35.1.1.0/24" # } # ], # "redistribute": [ # { # "metric": 50, # "protocol": "static" # } # ] # }, # { # "afi": "ipv6", # "aggregate_address": [ # { # "prefix": "6601:1:1:1::/64", # "summary_only": true # } # ], # "networks": [ # { # "prefix": "5001:1:1:1::/64", # "route_map": "map01" # } # ], # "redistribute": [ # { # "metric": 50, # "protocol": "static" # } # ] # } # ], # "as_number": 100, # "neighbors": [ # { # "address_family": [ # { # "afi": "ipv4", # "allowas_in": 4, # "as_override": true, # "attribute_unchanged": { # "med": true # } # } # ], # "neighbor_address": "20.33.1.1/24" # } # ] # Using rendered: - name: Render vyos.vyos.vyos_bgp_address_family: config: as_number: "100" address_family: - afi: "ipv4" redistribute: - protocol: "static" metric: 50 neighbors: - neighbor_address: "20.33.1.1/24" address_family: - afi: "ipv4" allowas_in: 4 as_override: true attribute_unchanged: med: true - afi: "ipv6" default_originate: "map01" distribute_list: - action: "export" acl: 10 - neighbor_address: "100.11.34.12" address_family: - afi: "ipv4" maximum_prefix: 45 nexthop_self: true route_map: - action: "export" route_map: "map01" - action: "import" route_map: "map01" weight: 50 state: rendered # Module Execution: # "rendered": [ # "set protocols bgp 100 address-family ipv4-unicast redistribute static metric 50", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast allowas-in number 4", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast as-override", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv4-unicast attribute-unchanged med", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast default-originate route-map map01", # "set protocols bgp 100 neighbor 20.33.1.1/24 address-family ipv6-unicast distribute-list export 10", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast maximum-prefix 45", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast nexthop-self", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast route-map export map01", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast route-map import map01", # "set protocols bgp 100 neighbor 100.11.34.12 address-family ipv4-unicast weight 50" # ] """ RETURN = """ before: description: The configuration prior to the module execution. returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) type: dict sample: > This output will always be in the same format as the module argspec. after: description: The resulting configuration after module execution. returned: when changed type: dict sample: > This output will always be in the same format as the module argspec. commands: description: The set of commands pushed to the remote device. returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) type: list sample: - sample command 1 - sample command 2 - sample command 3 rendered: description: The provided configuration in the task rendered in device-native format (offline). returned: when I(state) is C(rendered) type: list sample: - sample command 1 - sample command 2 - sample command 3 gathered: description: Facts about the network resource gathered from the remote device as structured data. returned: when I(state) is C(gathered) type: list sample: > This output will always be in the same format as the module argspec. parsed: description: The device native config provided in I(running_config) option parsed into structured data as per module argspec. returned: when I(state) is C(parsed) type: list sample: > This output will always be in the same format as the module argspec. """ from ansible.module_utils.basic import AnsibleModule from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.bgp_address_family.bgp_address_family import ( Bgp_address_familyArgs, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.bgp_address_family.bgp_address_family import ( Bgp_address_family, ) def main(): """ Main entry point for module execution :returns: the result form module invocation """ module = AnsibleModule( argument_spec=Bgp_address_familyArgs.argument_spec, mutually_exclusive=[["config", "running_config"]], required_if=[ ["state", "merged", ["config"]], ["state", "replaced", ["config"]], ["state", "overridden", ["config"]], ["state", "rendered", ["config"]], ["state", "parsed", ["running_config"]], ], supports_check_mode=True, ) result = Bgp_address_family(module).execute_module() module.exit_json(**result) if __name__ == "__main__": main() diff --git a/plugins/modules/vyos_bgp_global.py b/plugins/modules/vyos_bgp_global.py index 7d47e4ad..4d7db472 100644 --- a/plugins/modules/vyos_bgp_global.py +++ b/plugins/modules/vyos_bgp_global.py @@ -1,1491 +1,1536 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # Copyright 2024 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) """ The module file for vyos_bgp_global """ from __future__ import absolute_import, division, print_function __metaclass__ = type DOCUMENTATION = """ module: vyos_bgp_global version_added: 1.0.0 short_description: BGP global resource module description: - This module manages BGP global configuration of interfaces on devices running VYOS. +- Tested against VYOS 1.3, 1.4 author: - Gomathi Selvi Srinivasan (@GomathiselviS) options: config: description: A dict of BGP global configuration for interfaces. type: dict suboptions: as_number: description: - AS number. type: int - aggregate_address: - description: - - BGP aggregate network. - type: list - elements: dict - suboptions: - prefix: - description: - - BGP aggregate network. - type: str - as_set: - description: - - Generate AS-set path information for this aggregate address. - type: bool - summary_only: - description: - - Announce the aggregate summary network only. - type: bool - maximum_paths: - description: BGP multipaths - type: list - elements: dict - suboptions: - path: - description: BGP multipaths - type: str - count: - description: No. of paths. - type: int + # aggregate_address: + # description: + # - BGP aggregate network. + # type: list + # elements: dict + # suboptions: + # prefix: + # description: + # - BGP aggregate network. + # type: str + # as_set: + # description: + # - Generate AS-set path information for this aggregate address. + # type: bool + # summary_only: + # description: + # - Announce the aggregate summary network only. + # type: bool + #maximum_paths: --> moved to address-family before 1.3 + # description: BGP multipaths + # type: list + # elements: dict + # suboptions: + # path: + # description: BGP multipaths + # type: str + # count: + # description: No. of paths. + # type: int neighbor: description: BGP neighbor type: list elements: dict suboptions: address: description: - BGP neighbor address (v4/v6). type: str advertisement_interval: description: - Minimum interval for sending routing updates. type: int - allowas_in: - description: - - Number of occurrences of AS number. - type: int - as_override: - description: - - AS for routes sent to this neighbor to be the local AS. - type: bool - attribute_unchanged: - description: - - BGP attributes are sent unchanged. - type: dict - suboptions: - as_path: - description: as_path - type: bool - med: - description: med - type: bool - next_hop: - description: next_hop - type: bool + # bfd: # <-- added in 1.3 + # description: Enable Bidirectional Forwarding Detection (BFD) support + # type: dict + # suboptions: + # check-control-plane-failure: + # description: + # - Allow to write CBIT independence in BFD outgoing packets + # and read both C-BIT value of BFD and lookup BGP peer status + # type: bool + # allowas_in: --> Moved to address-family before 1.3 + # description: + # - Number of occurrences of AS number. + # type: int + # as_override: --> Moved to address-family before 1.3 + # description: + # - AS for routes sent to this neighbor to be the local AS. + # type: bool + # attribute_unchanged: --> Moved to address-family before 1.3 + # description: + # - BGP attributes are sent unchanged. + # type: dict + # suboptions: + # as_path: + # description: as_path + # type: bool + # med: + # description: med + # type: bool + # next_hop: + # description: next_hop + # type: bool capability: description: - Advertise capabilities to this neighbor. type: dict suboptions: dynamic: description: - Advertise dynamic capability to this neighbor. type: bool - orf: + extended_nexthop: description: - - Advertise ORF capability to this neighbor. - type: str - choices: - - send - - receive + - Advertise extended nexthop capability to this neighbor. + type: bool + # orf: --> Removed before 1.3 + # description: + # - Advertise ORF capability to this neighbor. + # type: str + # choices: + # - send + # - receive default_originate: description: - Send default route to this neighbor type: str description: description: - Description of the neighbor type: str disable_capability_negotiation: description: - Disbale capability negotiation with the neighbor type: bool disable_connected_check: description: - Disable check to see if EBGP peer's address is a connected route. type: bool disable_send_community: description: - Disable sending community attributes to this neighbor. type: str choices: ['extended', 'standard'] - distribute_list: - description: Access-list to filter route updates to/from this neighbor. - type: list - elements: dict - suboptions: - action: - description: Access-list to filter outgoing/incoming route updates to this neighbor - type: str - choices: ['export', 'import'] - acl: - description: Access-list number. - type: int + # distribute_list: --> Moved to address-family before 1.3 + # description: Access-list to filter route updates to/from this neighbor. + # type: list + # elements: dict + # suboptions: + # action: + # description: Access-list to filter outgoing/incoming route updates to this neighbor + # type: str + # choices: ['export', 'import'] + # acl: + # description: Access-list number. + # type: int ebgp_multihop: description: - Allow this EBGP neighbor to not be on a directly connected network. Specify the number hops. type: int - filter_list: - description: As-path-list to filter route updates to/from this neighbor. - type: list - elements: dict - suboptions: - action: - description: filter outgoing/incoming route updates - type: str - choices: ['export', 'import'] - path_list: - description: As-path-list to filter - type: str + # interface: # <-- added in 1.3 + # description: interface parameters + # type: dict + # suboptions: + # peer_group: + # description: Peer group for this neighbor + # type: str + # remote_as: + # description: + # - Remote AS number + # - Or 'external' for any number except this AS number + # - or 'internal' for this AS number + # type: str + # v6only: + # description: Enable BGP with v6 link-local only + # type: dict + # suboptions: + # peer_group: + # description: Peer group for this neighbor + # type: str + # remote_as: + # description: + # - Remote AS number + # - Or 'external' for any number except this AS number + # - or 'internal' for this AS number + # filter_list: --> Moved to address-family before 1.3 + # description: As-path-list to filter route updates to/from this neighbor. + # type: list + # elements: dict + # suboptions: + # action: + # description: filter outgoing/incoming route updates + # type: str + # choices: ['export', 'import'] + # path_list: + # description: As-path-list to filter + # type: str local_as: description: local as number not to be prepended to updates from EBGP peers type: int - maximum_prefix: - description: Maximum number of prefixes to accept from this neighbor - nexthop-self Nexthop for routes sent to this neighbor to be the local router. - type: int - nexthop_self: - description: Nexthop for routes sent to this neighbor to be the local router. - type: bool + # maximum_prefix: --> Moved to address-family before 1.3 + # description: Maximum number of prefixes to accept from this neighbor + # nexthop-self Nexthop for routes sent to this neighbor to be the local router. + # type: int + # nexthop_self: --> Moved to address-family before 1.3 + # description: Nexthop for routes sent to this neighbor to be the local router. + # type: bool override_capability: description: Ignore capability negotiation with specified neighbor. type: bool passive: description: Do not initiate a session with this neighbor type: bool password: description: BGP MD5 password type: str peer_group_name: description: IPv4 peer group for this peer type: str peer_group: description: True if all the configs under this neighbor key is for peer group template. type: bool port: description: Neighbor's BGP port type: int - prefix_list: - description: Prefix-list to filter route updates to/from this neighbor. - type: list - elements: dict - suboptions: - action: - description: filter outgoing/incoming route updates - type: str - choices: ['export', 'import'] - prefix_list: - description: Prefix-list to filter - type: str + # prefix_list: --> Moved to address-family before 1.3 + # description: Prefix-list to filter route updates to/from this neighbor. + # type: list + # elements: dict + # suboptions: + # action: + # description: filter outgoing/incoming route updates + # type: str + # choices: ['export', 'import'] + # prefix_list: + # description: Prefix-list to filter + # type: str remote_as: description: Neighbor BGP AS number type: int - remove_private_as: - description: Remove private AS numbers from AS path in outbound route updates - type: bool - route_map: - description: Route-map to filter route updates to/from this neighbor. - type: list - elements: dict - suboptions: - action: - description: filter outgoing/incoming route updates - type: str - choices: ['export', 'import'] - route_map: - description: route-map to filter - type: str - route_reflector_client: - description: Neighbor as a route reflector client - type: bool - route_server_client: - description: Neighbor is route server client - type: bool + # remove_private_as: --> Moved to address-family before 1.3 + # description: Remove private AS numbers from AS path in outbound route updates + # type: bool + # route_map: --> Moved to address-family before 1.3 + # description: Route-map to filter route updates to/from this neighbor. + # type: list + # elements: dict + # suboptions: + # action: + # description: filter outgoing/incoming route updates + # type: str + # choices: ['export', 'import'] + # route_map: + # description: route-map to filter + # type: str + # route_reflector_client: --> Moved to address-family before 1.3 + # description: Neighbor as a route reflector client + # type: bool + # route_server_client: --> Removed prior to 1.3 + # description: Neighbor is route server client + # type: bool shutdown: description: Administratively shut down neighbor type: bool - soft_reconfiguration: - description: Soft reconfiguration for neighbor + # soft_reconfiguration: --> Moved to address-family before 1.3 + # description: Soft reconfiguration for neighbor + # type: bool + solo: # <-- added in 1.3 + description: Do not send back prefixes learned from the neighbor type: bool strict_capability_match: description: Enable strict capability negotiation type: bool - unsuppress_map: - description: Route-map to selectively unsuppress suppressed routes - type: str - update_source: - description: Source IP of routing updates - type: str - weight: - description: Default weight for routes from this neighbor - type: int - ttl_security: - description: Ttl security mechanism for this BGP peer - type: int + # unsuppress_map: --> Moved to address-family before 1.3 + # description: Route-map to selectively unsuppress suppressed routes + # type: str + + # weight: --> Moved to address-family before 1.3 + # description: Default weight for routes from this neighbor + # type: int timers: description: Neighbor timers type: dict suboptions: connect: description: BGP connect timer for this neighbor. type: int holdtime: description: BGP hold timer for this neighbor type: int keepalive: description: BGP keepalive interval for this neighbor type: int - network: - description: BGP network - type: list - elements: dict - suboptions: - address: - description: BGP network address - type: str - backdoor: - description: Network as a backdoor route - type: bool - route_map: - description: Route-map to modify route attributes - type: str - redistribute: - description: Redistribute routes from other protocols into BGP - type: list - elements: dict - suboptions: - protocol: - description: types of routes to be redistributed. - type: str - choices: ['connected', 'kernel', 'ospf', 'rip', 'static'] - route_map: - description: Route map to filter redistributed routes - type: str - metric: - description: Metric for redistributed routes. + ttl_security: + description: Number of the maximum number of hops to the BGP peer type: int + update_source: + description: Source IP of routing updates + type: str + # network: + # description: BGP network + # type: list + # elements: dict + # suboptions: + # address: + # description: BGP network address + # type: str + # backdoor: + # description: Network as a backdoor route + # type: bool + # route_map: + # description: Route-map to modify route attributes + # type: str + # redistribute: + # description: Redistribute routes from other protocols into BGP + # type: list + # elements: dict + # suboptions: + # protocol: + # description: types of routes to be redistributed. + # type: str + # choices: ['connected', 'kernel', 'ospf', 'rip', 'static'] + # route_map: + # description: Route map to filter redistributed routes + # type: str + # metric: + # description: Metric for redistributed routes. + # type: int timers: description: BGP protocol timers type: dict suboptions: keepalive: description: Keepalive interval type: int holdtime: description: Hold time interval type: int bgp_params: description: BGP parameters type: dict suboptions: always_compare_med: description: Always compare MEDs from different neighbors type: bool bestpath: description: Default bestpath selection mechanism type: dict suboptions: as_path: description: AS-path attribute comparison parameters type: str choices: ['confed', 'ignore'] compare_routerid: description: Compare the router-id for identical EBGP paths type: bool med: description: MED attribute comparison parameters type: str choices: ['confed', 'missing-as-worst'] cluster_id: description: Route-reflector cluster-id type: str confederation: description: AS confederation parameters type: list elements: dict suboptions: identifier: description: Confederation AS identifier type: int peers: description: Peer ASs in the BGP confederation type: int dampening: description: Enable route-flap dampening type: dict suboptions: half_life: description: Half-life penalty in seconds type: int max_suppress_time: description: Maximum duration to suppress a stable route type: int re_use: description: Time to start reusing a route type: int start_suppress_time: description: When to start suppressing a route type: int default: description: BGP defaults type: dict suboptions: local_pref: description: Default local preference type: int no_ipv4_unicast: - description: Deactivate IPv4 unicast for a peer by default + description: | + Deactivate IPv4 unicast for a peer by default + Deprecated: Unavailable after 1.4 type: bool deterministic_med: description: Compare MEDs between different peers in the same AS type: bool disable_network_import_check: description: Disable IGP route check for network statements type: bool distance: description: Administrative distances for BGP routes type: list elements: dict suboptions: type: description: Type of route type: str choices: ['external', 'internal', 'local'] value: description: distance type: int prefix: description: Administrative distance for a specific BGP prefix type: int enforce_first_as: description: Require first AS in the path to match peer's AS type: bool graceful_restart: description: Maximum time to hold onto restarting peer's stale paths type: int log_neighbor_changes: description: Log neighbor up/down changes and reset reason type: bool no_client_to_client_reflection: description: Disable client to client route reflection type: bool no_fast_external_failover: description: Disable immediate session reset if peer's connected link goes down type: bool router_id: description: BGP router-id type: str scan_time: description: BGP route scanner interval type: int state: description: - The state the configuration should be left in. - State I(purged) removes all the BGP configurations from the target device. Use caution with this state.('delete protocols bgp ') - State I(deleted) only removes BGP attributes that this modules manages and does not negate the BGP process completely. Thereby, preserving address-family related configurations under BGP context. - Running states I(deleted) and I(replaced) will result in an error if there are address-family configuration lines present under neighbor context that is is to be removed. Please use the M(vyos.vyos.vyos_bgp_address_family) module for prior cleanup. - Refer to examples for more details. type: str choices: [deleted, merged, purged, replaced, gathered, rendered, parsed] default: merged running_config: description: - This option is used only with state I(parsed). - The value of this option should be the output received from the EOS device by executing the command B(show running-config | section bgp). - The state I(parsed) reads the configuration from C(running_config) option and transforms it into Ansible structured data as per the resource module's argspec and the value is then returned in the I(parsed) key within the result. type: str """ EXAMPLES = """ # Using merged # Before state # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # vyos@vyos:~$ - name: Merge provided configuration with device configuration vyos.vyos.vyos_bgp_global: config: as_number: "65536" aggregate_address: - prefix: "203.0.113.0/24" as_set: true - prefix: "192.0.2.0/24" summary_only: true network: - address: "192.1.13.0/24" backdoor: true redistribute: - protocol: "kernel" metric: 45 - protocol: "connected" route_map: "map01" maximum_paths: - path: "ebgp" count: 20 - path: "ibgp" count: 55 timers: keepalive: 35 bgp_params: bestpath: as_path: "confed" compare_routerid: true default: no_ipv4_unicast: true router_id: "192.1.2.9" confederation: - peers: 20 - peers: 55 - identifier: 66 neighbor: - address: "192.0.2.25" disable_connected_check: true timers: holdtime: 30 keepalive: 10 - address: "203.0.113.5" attribute_unchanged: as_path: true med: true ebgp_multihop: 2 remote_as: 101 update_source: "192.0.2.25" - address: "5001::64" maximum_prefix: 34 distribute_list: - acl: 20 action: "export" - acl: 40 action: "import" state: merged # After State # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 65536 aggregate-address 192.0.2.0/24 'summary-only' # set protocols bgp 65536 aggregate-address 203.0.113.0/24 'as-set' # set protocols bgp 65536 maximum-paths ebgp '20' # set protocols bgp 65536 maximum-paths ibgp '55' # set protocols bgp 65536 neighbor 192.0.2.25 'disable-connected-check' # set protocols bgp 65536 neighbor 192.0.2.25 timers holdtime '30' # set protocols bgp 65536 neighbor 192.0.2.25 timers keepalive '10' # set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'as-path' # set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'med' # set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'next-hop' # set protocols bgp 65536 neighbor 203.0.113.5 ebgp-multihop '2' # set protocols bgp 65536 neighbor 203.0.113.5 remote-as '101' # set protocols bgp 65536 neighbor 203.0.113.5 update-source '192.0.2.25' # set protocols bgp 65536 neighbor 5001::64 distribute-list export '20' # set protocols bgp 65536 neighbor 5001::64 distribute-list import '40' # set protocols bgp 65536 neighbor 5001::64 maximum-prefix '34' # set protocols bgp 65536 network 192.1.13.0/24 'backdoor' # set protocols bgp 65536 parameters bestpath as-path 'confed' # set protocols bgp 65536 parameters bestpath 'compare-routerid' # set protocols bgp 65536 parameters confederation identifier '66' # set protocols bgp 65536 parameters confederation peers '20' # set protocols bgp 65536 parameters confederation peers '55' # set protocols bgp 65536 parameters default 'no-ipv4-unicast' # set protocols bgp 65536 parameters router-id '192.1.2.9' # set protocols bgp 65536 redistribute connected route-map 'map01' # set protocols bgp 65536 redistribute kernel metric '45' # set protocols bgp 65536 timers keepalive '35' # vyos@vyos:~$ # # # Module Execution: # # "after": { # "aggregate_address": [ # { # "prefix": "192.0.2.0/24", # "summary_only": true # }, # { # "prefix": "203.0.113.0/24", # "as_set": true # } # ], # "as_number": 65536, # "bgp_params": { # "bestpath": { # "as_path": "confed", # "compare_routerid": true # }, # "confederation": [ # { # "identifier": 66 # }, # { # "peers": 20 # }, # { # "peers": 55 # } # ], # "default": { # "no_ipv4_unicast": true # }, # "router_id": "192.1.2.9" # }, # "maximum_paths": [ # { # "count": 20, # "path": "ebgp" # }, # { # "count": 55, # "path": "ibgp" # } # ], # "neighbor": [ # { # "address": "192.0.2.25", # "disable_connected_check": true, # "timers": { # "holdtime": 30, # "keepalive": 10 # } # }, # { # "address": "203.0.113.5", # "attribute_unchanged": { # "as_path": true, # "med": true, # "next_hop": true # }, # "ebgp_multihop": 2, # "remote_as": 101, # "update_source": "192.0.2.25" # }, # { # "address": "5001::64", # "distribute_list": [ # { # "acl": 20, # "action": "export" # }, # { # "acl": 40, # "action": "import" # } # ], # "maximum_prefix": 34 # } # ], # "network": [ # { # "address": "192.1.13.0/24", # "backdoor": true # } # ], # "redistribute": [ # { # "protocol": "connected", # "route_map": "map01" # }, # { # "metric": 45, # "protocol": "kernel" # } # ], # "timers": { # "keepalive": 35 # } # }, # "before": {}, # "changed": true, # "commands": [ # "set protocols bgp 65536 neighbor 192.0.2.25 disable-connected-check", # "set protocols bgp 65536 neighbor 192.0.2.25 timers holdtime 30", # "set protocols bgp 65536 neighbor 192.0.2.25 timers keepalive 10", # "set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged as-path", # "set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged med", # "set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged next-hop", # "set protocols bgp 65536 neighbor 203.0.113.5 ebgp-multihop 2", # "set protocols bgp 65536 neighbor 203.0.113.5 remote-as 101", # "set protocols bgp 65536 neighbor 203.0.113.5 update-source 192.0.2.25", # "set protocols bgp 65536 neighbor 5001::64 maximum-prefix 34", # "set protocols bgp 65536 neighbor 5001::64 distribute-list export 20", # "set protocols bgp 65536 neighbor 5001::64 distribute-list import 40", # "set protocols bgp 65536 redistribute kernel metric 45", # "set protocols bgp 65536 redistribute connected route-map map01", # "set protocols bgp 65536 network 192.1.13.0/24 backdoor", # "set protocols bgp 65536 aggregate-address 203.0.113.0/24 as-set", # "set protocols bgp 65536 aggregate-address 192.0.2.0/24 summary-only", # "set protocols bgp 65536 parameters bestpath as-path confed", # "set protocols bgp 65536 parameters bestpath compare-routerid", # "set protocols bgp 65536 parameters default no-ipv4-unicast", # "set protocols bgp 65536 parameters router-id 192.1.2.9", # "set protocols bgp 65536 parameters confederation peers 20", # "set protocols bgp 65536 parameters confederation peers 55", # "set protocols bgp 65536 parameters confederation identifier 66", # "set protocols bgp 65536 maximum-paths ebgp 20", # "set protocols bgp 65536 maximum-paths ibgp 55", # "set protocols bgp 65536 timers keepalive 35" # ], # Using replaced: # -------------- # Before state: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 65536 aggregate-address 192.0.2.0/24 'summary-only' # set protocols bgp 65536 aggregate-address 203.0.113.0/24 'as-set' # set protocols bgp 65536 maximum-paths ebgp '20' # set protocols bgp 65536 maximum-paths ibgp '55' # set protocols bgp 65536 neighbor 192.0.2.25 'disable-connected-check' # set protocols bgp 65536 neighbor 192.0.2.25 timers holdtime '30' # set protocols bgp 65536 neighbor 192.0.2.25 timers keepalive '10' # set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'as-path' # set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'med' # set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'next-hop' # set protocols bgp 65536 neighbor 203.0.113.5 ebgp-multihop '2' # set protocols bgp 65536 neighbor 203.0.113.5 remote-as '101' # set protocols bgp 65536 neighbor 203.0.113.5 update-source '192.0.2.25' # set protocols bgp 65536 neighbor 5001::64 distribute-list export '20' # set protocols bgp 65536 neighbor 5001::64 distribute-list import '40' # set protocols bgp 65536 neighbor 5001::64 maximum-prefix '34' # set protocols bgp 65536 network 192.1.13.0/24 'backdoor' # set protocols bgp 65536 parameters bestpath as-path 'confed' # set protocols bgp 65536 parameters bestpath 'compare-routerid' # set protocols bgp 65536 parameters confederation identifier '66' # set protocols bgp 65536 parameters confederation peers '20' # set protocols bgp 65536 parameters confederation peers '55' # set protocols bgp 65536 parameters default 'no-ipv4-unicast' # set protocols bgp 65536 parameters router-id '192.1.2.9' # set protocols bgp 65536 redistribute connected route-map 'map01' # set protocols bgp 65536 redistribute kernel metric '45' # set protocols bgp 65536 timers keepalive '35' # vyos@vyos:~$ - name: Replace vyos.vyos.vyos_bgp_global: config: as_number: "65536" network: - address: "203.0.113.0/24" route_map: map01 redistribute: - protocol: "static" route_map: "map01" neighbor: - address: "192.0.2.40" advertisement_interval: 72 capability: orf: "receive" bgp_params: bestpath: as_path: "confed" state: replaced # After state: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 65536 neighbor 192.0.2.40 advertisement-interval '72' # set protocols bgp 65536 neighbor 192.0.2.40 capability orf prefix-list 'receive' # set protocols bgp 65536 network 203.0.113.0/24 route-map 'map01' # set protocols bgp 65536 parameters bestpath as-path 'confed' # set protocols bgp 65536 redistribute static route-map 'map01' # vyos@vyos:~$ # # # Module Execution: # # "after": { # "as_number": 65536, # "bgp_params": { # "bestpath": { # "as_path": "confed" # } # }, # "neighbor": [ # { # "address": "192.0.2.40", # "advertisement_interval": 72, # "capability": { # "orf": "receive" # } # } # ], # "network": [ # { # "address": "203.0.113.0/24", # "route_map": "map01" # } # ], # "redistribute": [ # { # "protocol": "static", # "route_map": "map01" # } # ] # }, # "before": { # "aggregate_address": [ # { # "prefix": "192.0.2.0/24", # "summary_only": true # }, # { # "prefix": "203.0.113.0/24", # "as_set": true # } # ], # "as_number": 65536, # "bgp_params": { # "bestpath": { # "as_path": "confed", # "compare_routerid": true # }, # "confederation": [ # { # "identifier": 66 # }, # { # "peers": 20 # }, # { # "peers": 55 # } # ], # "default": { # "no_ipv4_unicast": true # }, # "router_id": "192.1.2.9" # }, # "maximum_paths": [ # { # "count": 20, # "path": "ebgp" # }, # { # "count": 55, # "path": "ibgp" # } # ], # "neighbor": [ # { # "address": "192.0.2.25", # "disable_connected_check": true, # "timers": { # "holdtime": 30, # "keepalive": 10 # } # }, # { # "address": "203.0.113.5", # "attribute_unchanged": { # "as_path": true, # "med": true, # "next_hop": true # }, # "ebgp_multihop": 2, # "remote_as": 101, # "update_source": "192.0.2.25" # }, # { # "address": "5001::64", # "distribute_list": [ # { # "acl": 20, # "action": "export" # }, # { # "acl": 40, # "action": "import" # } # ], # "maximum_prefix": 34 # } # ], # "network": [ # { # "address": "192.1.13.0/24", # "backdoor": true # } # ], # "redistribute": [ # { # "protocol": "connected", # "route_map": "map01" # }, # { # "metric": 45, # "protocol": "kernel" # } # ], # "timers": { # "keepalive": 35 # } # }, # "changed": true, # "commands": [ # "delete protocols bgp 65536 timers", # "delete protocols bgp 65536 maximum-paths ", # "delete protocols bgp 65536 maximum-paths ", # "delete protocols bgp 65536 parameters router-id 192.1.2.9", # "delete protocols bgp 65536 parameters default", # "delete protocols bgp 65536 parameters confederation", # "delete protocols bgp 65536 parameters bestpath compare-routerid", # "delete protocols bgp 65536 aggregate-address", # "delete protocols bgp 65536 network 192.1.13.0/24", # "delete protocols bgp 65536 redistribute kernel", # "delete protocols bgp 65536 redistribute kernel", # "delete protocols bgp 65536 redistribute connected", # "delete protocols bgp 65536 redistribute connected", # "delete protocols bgp 65536 neighbor 5001::64", # "delete protocols bgp 65536 neighbor 203.0.113.5", # "delete protocols bgp 65536 neighbor 192.0.2.25", # "set protocols bgp 65536 neighbor 192.0.2.40 advertisement-interval 72", # "set protocols bgp 65536 neighbor 192.0.2.40 capability orf prefix-list receive", # "set protocols bgp 65536 redistribute static route-map map01", # "set protocols bgp 65536 network 203.0.113.0/24 route-map map01" # ], # Using deleted: # ------------- # Before state: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 65536 neighbor 192.0.2.40 advertisement-interval '72' # set protocols bgp 65536 neighbor 192.0.2.40 capability orf prefix-list 'receive' # set protocols bgp 65536 network 203.0.113.0/24 route-map 'map01' # set protocols bgp 65536 parameters bestpath as-path 'confed' # set protocols bgp 65536 redistribute static route-map 'map01' # vyos@vyos:~$ - name: Delete configuration vyos.vyos.vyos_bgp_global: config: as_number: "65536" state: deleted # After state: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp '65536' # vyos@vyos:~$ # # # Module Execution: # # "after": { # "as_number": 65536 # }, # "before": { # "as_number": 65536, # "bgp_params": { # "bestpath": { # "as_path": "confed" # } # }, # "neighbor": [ # { # "address": "192.0.2.40", # "advertisement_interval": 72, # "capability": { # "orf": "receive" # } # } # ], # "network": [ # { # "address": "203.0.113.0/24", # "route_map": "map01" # } # ], # "redistribute": [ # { # "protocol": "static", # "route_map": "map01" # } # ] # }, # "changed": true, # "commands": [ # "delete protocols bgp 65536 neighbor 192.0.2.40", # "delete protocols bgp 65536 redistribute", # "delete protocols bgp 65536 network", # "delete protocols bgp 65536 parameters" # ], # Using purged: # Before state: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 65536 aggregate-address 192.0.2.0/24 'summary-only' # set protocols bgp 65536 aggregate-address 203.0.113.0/24 'as-set' # set protocols bgp 65536 maximum-paths ebgp '20' # set protocols bgp 65536 maximum-paths ibgp '55' # set protocols bgp 65536 neighbor 192.0.2.25 'disable-connected-check' # set protocols bgp 65536 neighbor 192.0.2.25 timers holdtime '30' # set protocols bgp 65536 neighbor 192.0.2.25 timers keepalive '10' # set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'as-path' # set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'med' # set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'next-hop' # set protocols bgp 65536 neighbor 203.0.113.5 ebgp-multihop '2' # set protocols bgp 65536 neighbor 203.0.113.5 remote-as '101' # set protocols bgp 65536 neighbor 203.0.113.5 update-source '192.0.2.25' # set protocols bgp 65536 neighbor 5001::64 distribute-list export '20' # set protocols bgp 65536 neighbor 5001::64 distribute-list import '40' # set protocols bgp 65536 neighbor 5001::64 maximum-prefix '34' # set protocols bgp 65536 network 192.1.13.0/24 'backdoor' # set protocols bgp 65536 parameters bestpath as-path 'confed' # set protocols bgp 65536 parameters bestpath 'compare-routerid' # set protocols bgp 65536 parameters confederation identifier '66' # set protocols bgp 65536 parameters confederation peers '20' # set protocols bgp 65536 parameters confederation peers '55' # set protocols bgp 65536 parameters default 'no-ipv4-unicast' # set protocols bgp 65536 parameters router-id '192.1.2.9' # set protocols bgp 65536 redistribute connected route-map 'map01' # set protocols bgp 65536 redistribute kernel metric '45' # set protocols bgp 65536 timers keepalive '35' # vyos@vyos:~$ - name: Purge configuration vyos.vyos.vyos_bgp_global: config: as_number: "65536" state: purged # After state: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # vyos@vyos:~$ # # Module Execution: # # "after": {}, # "before": { # "aggregate_address": [ # { # "prefix": "192.0.2.0/24", # "summary_only": true # }, # { # "prefix": "203.0.113.0/24", # "as_set": true # } # ], # "as_number": 65536, # "bgp_params": { # "bestpath": { # "as_path": "confed", # "compare_routerid": true # }, # "confederation": [ # { # "identifier": 66 # }, # { # "peers": 20 # }, # { # "peers": 55 # } # ], # "default": { # "no_ipv4_unicast": true # }, # "router_id": "192.1.2.9" # }, # "maximum_paths": [ # { # "count": 20, # "path": "ebgp" # }, # { # "count": 55, # "path": "ibgp" # } # ], # "neighbor": [ # { # "address": "192.0.2.25", # "disable_connected_check": true, # "timers": { # "holdtime": 30, # "keepalive": 10 # } # }, # { # "address": "203.0.113.5", # "attribute_unchanged": { # "as_path": true, # "med": true, # "next_hop": true # }, # "ebgp_multihop": 2, # "remote_as": 101, # "update_source": "192.0.2.25" # }, # { # "address": "5001::64", # "distribute_list": [ # { # "acl": 20, # "action": "export" # }, # { # "acl": 40, # "action": "import" # } # ], # "maximum_prefix": 34 # } # ], # "network": [ # { # "address": "192.1.13.0/24", # "backdoor": true # } # ], # "redistribute": [ # { # "protocol": "connected", # "route_map": "map01" # }, # { # "metric": 45, # "protocol": "kernel" # } # ], # "timers": { # "keepalive": 35 # } # }, # "changed": true, # "commands": [ # "delete protocols bgp 65536" # ], # Deleted in presence of address family under neighbors: # Before state: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 65536 neighbor 192.0.2.43 advertisement-interval '72' # set protocols bgp 65536 neighbor 192.0.2.43 capability 'dynamic' # set protocols bgp 65536 neighbor 192.0.2.43 'disable-connected-check' # set protocols bgp 65536 neighbor 192.0.2.43 timers holdtime '30' # set protocols bgp 65536 neighbor 192.0.2.43 timers keepalive '10' # set protocols bgp 65536 neighbor 203.0.113.0 address-family 'ipv6-unicast' # set protocols bgp 65536 neighbor 203.0.113.0 capability orf prefix-list 'receive' # set protocols bgp 65536 network 203.0.113.0/24 route-map 'map01' # set protocols bgp 65536 parameters 'always-compare-med' # set protocols bgp 65536 parameters bestpath as-path 'confed' # set protocols bgp 65536 parameters bestpath 'compare-routerid' # set protocols bgp 65536 parameters dampening half-life '33' # set protocols bgp 65536 parameters dampening max-suppress-time '20' # set protocols bgp 65536 parameters dampening re-use '60' # set protocols bgp 65536 parameters dampening start-suppress-time '5' # set protocols bgp 65536 parameters default 'no-ipv4-unicast' # set protocols bgp 65536 parameters distance global external '66' # set protocols bgp 65536 parameters distance global internal '20' # set protocols bgp 65536 parameters distance global local '10' # set protocols bgp 65536 redistribute static route-map 'map01' # vyos@vyos:~$ ^C # vyos@vyos:~$ - name: Delete configuration vyos.vyos.vyos_bgp_global: config: as_number: "65536" state: deleted # Module Execution: # # "changed": false, # "invocation": { # "module_args": { # "config": { # "aggregate_address": null, # "as_number": 65536, # "bgp_params": null, # "maximum_paths": null, # "neighbor": null, # "network": null, # "redistribute": null, # "timers": null # }, # "running_config": null, # "state": "deleted" # } # }, # "msg": "Use the _bgp_address_family module to delete the address_family under neighbor 203.0.113.0, before replacing/deleting the neighbor." # } # using gathered: # -------------- # Before state: # vyos@vyos:~$ show configuration commands | match "set protocols bgp" # set protocols bgp 65536 neighbor 192.0.2.43 advertisement-interval '72' # set protocols bgp 65536 neighbor 192.0.2.43 capability 'dynamic' # set protocols bgp 65536 neighbor 192.0.2.43 'disable-connected-check' # set protocols bgp 65536 neighbor 192.0.2.43 timers holdtime '30' # set protocols bgp 65536 neighbor 192.0.2.43 timers keepalive '10' # set protocols bgp 65536 neighbor 203.0.113.0 address-family 'ipv6-unicast' # set protocols bgp 65536 neighbor 203.0.113.0 capability orf prefix-list 'receive' # set protocols bgp 65536 network 203.0.113.0/24 route-map 'map01' # set protocols bgp 65536 parameters 'always-compare-med' # set protocols bgp 65536 parameters bestpath as-path 'confed' # set protocols bgp 65536 parameters bestpath 'compare-routerid' # set protocols bgp 65536 parameters dampening half-life '33' # set protocols bgp 65536 parameters dampening max-suppress-time '20' # set protocols bgp 65536 parameters dampening re-use '60' # set protocols bgp 65536 parameters dampening start-suppress-time '5' # set protocols bgp 65536 parameters default 'no-ipv4-unicast' # set protocols bgp 65536 parameters distance global external '66' # set protocols bgp 65536 parameters distance global internal '20' # set protocols bgp 65536 parameters distance global local '10' # set protocols bgp 65536 redistribute static route-map 'map01' # vyos@vyos:~$ ^C - name: gather configs vyos.vyos.vyos_bgp_global: state: gathered # Module Execution: # "gathered": { # "as_number": 65536, # "bgp_params": { # "always_compare_med": true, # "bestpath": { # "as_path": "confed", # "compare_routerid": true # }, # "default": { # "no_ipv4_unicast": true # }, # "distance": [ # { # "type": "external", # "value": 66 # }, # { # "type": "internal", # "value": 20 # }, # { # "type": "local", # "value": 10 # } # ] # }, # "neighbor": [ # { # "address": "192.0.2.43", # "advertisement_interval": 72, # "capability": { # "dynamic": true # }, # "disable_connected_check": true, # "timers": { # "holdtime": 30, # "keepalive": 10 # } # }, # { # "address": "203.0.113.0", # "capability": { # "orf": "receive" # } # } # ], # "network": [ # { # "address": "203.0.113.0/24", # "route_map": "map01" # } # ], # "redistribute": [ # { # "protocol": "static", # "route_map": "map01" # } # ] # }, # # Using parsed: # ------------ # parsed.cfg # set protocols bgp 65536 neighbor 192.0.2.43 advertisement-interval '72' # set protocols bgp 65536 neighbor 192.0.2.43 capability 'dynamic' # set protocols bgp 65536 neighbor 192.0.2.43 'disable-connected-check' # set protocols bgp 65536 neighbor 192.0.2.43 timers holdtime '30' # set protocols bgp 65536 neighbor 192.0.2.43 timers keepalive '10' # set protocols bgp 65536 neighbor 203.0.113.0 address-family 'ipv6-unicast' # set protocols bgp 65536 neighbor 203.0.113.0 capability orf prefix-list 'receive' # set protocols bgp 65536 network 203.0.113.0/24 route-map 'map01' # set protocols bgp 65536 parameters 'always-compare-med' # set protocols bgp 65536 parameters bestpath as-path 'confed' # set protocols bgp 65536 parameters bestpath 'compare-routerid' # set protocols bgp 65536 parameters dampening half-life '33' # set protocols bgp 65536 parameters dampening max-suppress-time '20' # set protocols bgp 65536 parameters dampening re-use '60' # set protocols bgp 65536 parameters dampening start-suppress-time '5' # set protocols bgp 65536 parameters default 'no-ipv4-unicast' # set protocols bgp 65536 parameters distance global external '66' # set protocols bgp 65536 parameters distance global internal '20' # set protocols bgp 65536 parameters distance global local '10' # set protocols bgp 65536 redistribute static route-map 'map01' - name: parse configs vyos.vyos.vyos_bgp_global: running_config: "{{ lookup('file', './parsed.cfg') }}" state: parsed tags: - parsed # Module execution: # "parsed": { # "as_number": 65536, # "bgp_params": { # "always_compare_med": true, # "bestpath": { # "as_path": "confed", # "compare_routerid": true # }, # "default": { # "no_ipv4_unicast": true # }, # "distance": [ # { # "type": "external", # "value": 66 # }, # { # "type": "internal", # "value": 20 # }, # { # "type": "local", # "value": 10 # } # ] # }, # "neighbor": [ # { # "address": "192.0.2.43", # "advertisement_interval": 72, # "capability": { # "dynamic": true # }, # "disable_connected_check": true, # "timers": { # "holdtime": 30, # "keepalive": 10 # } # }, # { # "address": "203.0.113.0", # "capability": { # "orf": "receive" # } # } # ], # "network": [ # { # "address": "203.0.113.0/24", # "route_map": "map01" # } # ], # "redistribute": [ # { # "protocol": "static", # "route_map": "map01" # } # ] # } # # Using rendered: # -------------- - name: Render vyos.vyos.vyos_bgp_global: config: as_number: "65536" network: - address: "203.0.113.0/24" route_map: map01 redistribute: - protocol: "static" route_map: "map01" bgp_params: always_compare_med: true dampening: start_suppress_time: 5 max_suppress_time: 20 half_life: 33 re_use: 60 distance: - type: "internal" value: 20 - type: "local" value: 10 - type: "external" value: 66 bestpath: as_path: "confed" compare_routerid: true default: no_ipv4_unicast: true neighbor: - address: "192.0.2.43" disable_connected_check: true advertisement_interval: 72 capability: dynamic: true timers: holdtime: 30 keepalive: 10 - address: "203.0.113.0" capability: orf: "receive" state: rendered # Module Execution: # "rendered": [ # "set protocols bgp 65536 neighbor 192.0.2.43 disable-connected-check", # "set protocols bgp 65536 neighbor 192.0.2.43 advertisement-interval 72", # "set protocols bgp 65536 neighbor 192.0.2.43 capability dynamic", # "set protocols bgp 65536 neighbor 192.0.2.43 timers holdtime 30", # "set protocols bgp 65536 neighbor 192.0.2.43 timers keepalive 10", # "set protocols bgp 65536 neighbor 203.0.113.0 capability orf prefix-list receive", # "set protocols bgp 65536 redistribute static route-map map01", # "set protocols bgp 65536 network 203.0.113.0/24 route-map map01", # "set protocols bgp 65536 parameters always-compare-med", # "set protocols bgp 65536 parameters dampening half-life 33", # "set protocols bgp 65536 parameters dampening max-suppress-time 20", # "set protocols bgp 65536 parameters dampening re-use 60", # "set protocols bgp 65536 parameters dampening start-suppress-time 5", # "set protocols bgp 65536 parameters distance global internal 20", # "set protocols bgp 65536 parameters distance global local 10", # "set protocols bgp 65536 parameters distance global external 66", # "set protocols bgp 65536 parameters bestpath as-path confed", # "set protocols bgp 65536 parameters bestpath compare-routerid", # "set protocols bgp 65536 parameters default no-ipv4-unicast" # ] """ RETURN = """ before: description: The configuration prior to the module execution. returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) type: dict sample: > This output will always be in the same format as the module argspec. after: description: The resulting configuration after module execution. returned: when changed type: dict sample: > This output will always be in the same format as the module argspec. commands: description: The set of commands pushed to the remote device. returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) type: list sample: - set protocols bgp 65536 redistribute static route-map map01 - set protocols bgp 65536 network 203.0.113.0/24 route-map map01 - set protocols bgp 65536 parameters always-compare-med rendered: description: The provided configuration in the task rendered in device-native format (offline). returned: when I(state) is C(rendered) type: list sample: - set protocols bgp 65536 redistribute static route-map map01 - set protocols bgp 65536 network 203.0.113.0/24 route-map map01 - set protocols bgp 65536 parameters always-compare-med gathered: description: Facts about the network resource gathered from the remote device as structured data. returned: when I(state) is C(gathered) type: list sample: > This output will always be in the same format as the module argspec. parsed: description: The device native config provided in I(running_config) option parsed into structured data as per module argspec. returned: when I(state) is C(parsed) type: list sample: > This output will always be in the same format as the module argspec. """ from ansible.module_utils.basic import AnsibleModule from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.bgp_global.bgp_global import ( Bgp_globalArgs, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.bgp_global.bgp_global import ( Bgp_global, ) def main(): """ Main entry point for module execution :returns: the result form module invocation """ module = AnsibleModule( argument_spec=Bgp_globalArgs.argument_spec, mutually_exclusive=[["config", "running_config"]], required_if=[ ["state", "merged", ["config"]], ["state", "replaced", ["config"]], ["state", "overridden", ["config"]], ["state", "rendered", ["config"]], ["state", "parsed", ["running_config"]], ], supports_check_mode=True, ) result = Bgp_global(module).execute_module() module.exit_json(**result) if __name__ == "__main__": main() diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/cli/_get_version.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/cli/_get_version.yaml new file mode 100644 index 00000000..2588b194 --- /dev/null +++ b/tests/integration/targets/vyos_bgp_address_family/tests/cli/_get_version.yaml @@ -0,0 +1,28 @@ +- name: make sure to get facts + vyos.vyos.vyos_facts: + vars: + ansible_connection: ansible.netcommon.network_cli + register: vyos_facts + when: vyos_version is not defined + +- name: debug vyos_facts + debug: + var: vyos_facts + +- name: pull version from facts + set_fact: + vyos_version: "{{ vyos_facts.ansible_facts.ansible_net_version.split('-')[0].split(' ')[-1] }}" + when: vyos_version is not defined + +- name: fix '.0' versions + set_fact: + vyos_version: "{{ vyos_version }}.0" + when: vyos_version.count('.') == 1 + +- name: include correct vars + include_vars: pre-v1_4.yaml + when: vyos_version is version('1.4.0', '<', version_type='semver') + +- name: include correct vars + include_vars: v1_4.yaml + when: vyos_version is version('1.4.0', '>=', version_type='semver') diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/cli/_parsed_config.cfg b/tests/integration/targets/vyos_bgp_address_family/tests/cli/_parsed_config.cfg index 2aecc805..afb0987a 100644 --- a/tests/integration/targets/vyos_bgp_address_family/tests/cli/_parsed_config.cfg +++ b/tests/integration/targets/vyos_bgp_address_family/tests/cli/_parsed_config.cfg @@ -1,9 +1,9 @@ set policy access-list 20 description 'acl20' set policy access-list 40 description 'acl40' set policy route-map map01 description 'map01' -set protocols bgp 65536 address-family ipv6-unicast aggregate-address 5000:1:1::/64 summary-only -set protocols bgp 65536 address-family ipv6-unicast network 21e0:1:1::/64 route-map 'map01' -set protocols bgp 65536 address-family ipv6-unicast redistribute ripng metric '20' -set protocols bgp 65536 neighbor 192.0.2.25 address-family ipv6-unicast route-map export 'map01' -set protocols bgp 65536 neighbor 192.0.2.25 address-family ipv6-unicast soft-reconfiguration inbound -set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged next-hop +set protocols bgp address-family ipv6-unicast aggregate-address 5000:1:1::/64 summary-only +set protocols bgp address-family ipv6-unicast network 21e0:1:1::/64 route-map 'map01' +set protocols bgp address-family ipv6-unicast redistribute ripng metric '20' +set protocols bgp neighbor 192.0.2.25 address-family ipv6-unicast route-map export 'map01' +set protocols bgp neighbor 192.0.2.25 address-family ipv6-unicast soft-reconfiguration inbound +set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged next-hop diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/cli/_parsed_config.cfg b/tests/integration/targets/vyos_bgp_address_family/tests/cli/_parsed_config_1_3.cfg similarity index 100% copy from tests/integration/targets/vyos_bgp_address_family/tests/cli/_parsed_config.cfg copy to tests/integration/targets/vyos_bgp_address_family/tests/cli/_parsed_config_1_3.cfg diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/cli/_populate.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/cli/_populate.yaml index ecbcc70d..4158a65d 100644 --- a/tests/integration/targets/vyos_bgp_address_family/tests/cli/_populate.yaml +++ b/tests/integration/targets/vyos_bgp_address_family/tests/cli/_populate.yaml @@ -1,19 +1,44 @@ --- - ansible.builtin.include_tasks: _remove_config.yaml -- name: Setup +- name: ensure facts + include_tasks: _get_version.yaml + +- name: Setup (Pre 1.4) vyos.vyos.vyos_config: lines: - set policy access-list 20 description 'acl20' - set policy access-list 40 description 'acl40' - set policy access-list6 10 description 'acl10' - set policy route-map map01 description 'map01' - set protocols bgp 65536 address-family ipv6-unicast aggregate-address 5000:1:1::/64 summary-only - set protocols bgp 65536 address-family ipv6-unicast network 21e0:1:1::/64 route-map 'map01' - set protocols bgp 65536 address-family ipv6-unicast redistribute ripng metric '20' - set protocols bgp 65536 neighbor 192.0.2.25 address-family ipv6-unicast route-map export 'map01' - set protocols bgp 65536 neighbor 192.0.2.25 address-family ipv6-unicast soft-reconfiguration inbound - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged next-hop ignore_errors: true vars: ansible_connection: ansible.netcommon.network_cli + when: vyos_version is version('1.4.0', '<', version_type='semver') + +- name: Setup (1.4+) + vyos.vyos.vyos_config: + lines: + - set policy access-list 20 description 'acl20' + - set policy access-list 40 description 'acl40' + - set policy access-list6 10 description 'acl10' + - set policy route-map map01 description 'map01' + - set protocols bgp system-as 65536 + - set protocols bgp address-family ipv6-unicast aggregate-address 5000:1:1::/64 summary-only + - set protocols bgp address-family ipv6-unicast network 21e0:1:1::/64 route-map 'map01' + - set protocols bgp address-family ipv6-unicast redistribute ripng metric '20' + - set protocols bgp neighbor 192.0.2.25 remote-as 65535 + - set protocols bgp neighbor 192.0.2.25 address-family ipv6-unicast route-map export 'map01' + - set protocols bgp neighbor 192.0.2.25 address-family ipv6-unicast soft-reconfiguration inbound + - set protocols bgp neighbor 203.0.113.5 remote-as 65534 + - set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged next-hop + ignore_errors: true + vars: + ansible_connection: ansible.netcommon.network_cli + when: vyos_version is version('1.4.0', '>=', version_type='semver') diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/cli/_preconfig.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/cli/_preconfig.yaml index 5024a70f..65adbb40 100644 --- a/tests/integration/targets/vyos_bgp_address_family/tests/cli/_preconfig.yaml +++ b/tests/integration/targets/vyos_bgp_address_family/tests/cli/_preconfig.yaml @@ -1,11 +1,19 @@ --- - name: setup vyos.vyos.vyos_config: lines: - set policy access-list 20 description 'acl20' - set policy access-list 40 description 'acl40' - set policy access-list6 10 description 'acl10' - set policy route-map map01 description 'map01' ignore_errors: true vars: ansible_connection: ansible.netcommon.network_cli + +- name: setup for 1.4+ + vyos.vyos.vyos_config: + lines: + - set protocols bgp system-as 65536 + - set protocols bgp neighbor 203.0.113.5 remote-as 65534 + - set protocols bgp neighbor 192.0.2.25 remote-as 65534 + when: vyos_version is version('1.4.0', '>=', version_type='semver') diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/cli/_remove_config.yaml index 39d8bd02..36600e24 100644 --- a/tests/integration/targets/vyos_bgp_address_family/tests/cli/_remove_config.yaml +++ b/tests/integration/targets/vyos_bgp_address_family/tests/cli/_remove_config.yaml @@ -1,12 +1,12 @@ --- - name: Remove pre-existing bgp processes vyos.vyos.vyos_config: lines: - - delete protocols bgp 65536 + - delete protocols bgp - delete policy access-list 20 - delete policy access-list 40 - delete policy access-list6 10 - delete policy route-map map01 ignore_errors: true vars: ansible_connection: ansible.netcommon.network_cli diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/cli/deleted.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/cli/deleted.yaml index 15bfe845..2a760069 100644 --- a/tests/integration/targets/vyos_bgp_address_family/tests/cli/deleted.yaml +++ b/tests/integration/targets/vyos_bgp_address_family/tests/cli/deleted.yaml @@ -1,42 +1,42 @@ --- - debug: msg: START vyos_bgp_address_family deleted integration tests on connection={{ ansible_connection }} - include_tasks: _populate.yaml - block: - name: Delete the provided configuration register: result vyos.vyos.vyos_bgp_address_family: &id001 config: as_number: "65536" address_family: - afi: ipv6 neighbors: - neighbor_address: 203.0.113.5 - neighbor_address: 192.0.2.25 address_family: - afi: ipv6 state: deleted - vyos.vyos.vyos_facts: gather_network_resources: bgp_address_family - assert: that: - - result.commands|length == 3 + - result.commands|length == deleted.commands|length - result.changed == true - result.commands|symmetric_difference(deleted.commands) == [] - result.after == ansible_facts['network_resources']['bgp_address_family'] - name: Delete the existing configuration with the provided running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_bgp_address_family: *id001 - name: Assert that the previous task was idempotent assert: that: - result['changed'] == false always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/cli/merged.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/cli/merged.yaml index 4e66a78a..acfae74d 100644 --- a/tests/integration/targets/vyos_bgp_address_family/tests/cli/merged.yaml +++ b/tests/integration/targets/vyos_bgp_address_family/tests/cli/merged.yaml @@ -1,65 +1,65 @@ --- - debug: msg: START vyos_bgp_address_family merged integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml - include_tasks: _preconfig.yaml - block: - name: Merge the provided configuration with the existing running configuration register: result vyos.vyos.vyos_bgp_address_family: &id001 config: as_number: "65536" address_family: - afi: ipv6 redistribute: - protocol: static metric: 50 neighbors: - neighbor_address: 203.0.113.5 address_family: - afi: ipv6 allowas_in: 4 attribute_unchanged: med: true default_originate: map01 distribute_list: - action: export acl: 10 - neighbor_address: 192.0.2.25 address_family: - afi: ipv6 maximum_prefix: 45 nexthop_self: true route_map: - action: export route_map: map01 - action: import route_map: map01 state: merged - vyos.vyos.vyos_facts: gather_network_resources: bgp_address_family - assert: that: - - result.commands|length == 9 + - result.commands|length == merged.commands|length - result.changed == true - result.commands|symmetric_difference(merged.commands) == [] - result.after == ansible_facts['network_resources']['bgp_address_family'] - - result.before == {} + - result.before == merged.before - result.after == merged.after - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_bgp_address_family: *id001 - name: Assert that the previous task was idempotent assert: that: - result['changed'] == false always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/cli/overridden.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/cli/overridden.yaml index 90b40dea..ec0b6164 100644 --- a/tests/integration/targets/vyos_bgp_address_family/tests/cli/overridden.yaml +++ b/tests/integration/targets/vyos_bgp_address_family/tests/cli/overridden.yaml @@ -1,51 +1,51 @@ --- - debug: msg: START vyos_bgp_address_family overridden integration tests on connection={{ ansible_connection }} - include_tasks: _populate.yaml - block: - name: Replace the existing configuration with the provided running configuration register: result vyos.vyos.vyos_bgp_address_family: &id001 config: as_number: "65536" address_family: - afi: ipv6 redistribute: - protocol: static metric: 50 neighbors: - neighbor_address: 203.0.113.5 address_family: - afi: ipv6 allowas_in: 4 attribute_unchanged: med: true default_originate: map01 distribute_list: - action: export acl: 10 state: overridden - vyos.vyos.vyos_facts: gather_network_resources: bgp_address_family - assert: that: - - result.commands|length == 10 + - result.commands|length == overridden.commands|length - result.changed == true - result.commands|symmetric_difference(overridden.commands) == [] - result.after == ansible_facts['network_resources']['bgp_address_family'] - name: Replace the existing configuration with the provided running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_bgp_address_family: *id001 - name: Assert that the previous task was idempotent assert: that: - result['changed'] == false always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/cli/parsed.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/cli/parsed.yaml index da9c1417..65e9b1b1 100644 --- a/tests/integration/targets/vyos_bgp_address_family/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_bgp_address_family/tests/cli/parsed.yaml @@ -1,14 +1,35 @@ --- - debug: msg: START vyos_bgp_address_family parsed integration tests on connection={{ ansible_connection }} -- name: Provide the running configuration for parsing (config to be parsed) - register: result - vyos.vyos.vyos_bgp_address_family: - running_config: "{{ lookup('file', '_parsed_config.cfg') }}" - state: parsed +- name: ensure facts + include_tasks: _get_version.yaml + +- name: version 1.3 + block: + - name: Provide the running configuration for parsing (config to be parsed) + register: result + vyos.vyos.vyos_bgp_address_family: + running_config: "{{ lookup('file', '_parsed_config_1_3.cfg') }}" + state: parsed + - name: set result + set_fact: + parsed_result: "{{ result }}" + when: vyos_version is version('1.4.0', '<', version_type='semver') + +- name: version 1.4+ + block: + - name: Provide the running configuration for parsing (config to be parsed) + register: result + vyos.vyos.vyos_bgp_address_family: + running_config: "{{ lookup('file', '_parsed_config.cfg') }}" + state: parsed + - name: set result + set_fact: + parsed_result: "{{ result }}" + when: vyos_version is version('1.4.0', '>=', version_type='semver') - assert: that: - - result.changed == false - - result.parsed == populate.config + - parsed_result.changed == false + - parsed_result.parsed == populate.config diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/cli/rendered.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/cli/rendered.yaml index 0ef116e8..151f896a 100644 --- a/tests/integration/targets/vyos_bgp_address_family/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_bgp_address_family/tests/cli/rendered.yaml @@ -1,42 +1,42 @@ --- - debug: msg: START vyos_bgp_address_family rendered integration tests on connection={{ ansible_connection }} - block: - name: Render the given config in the form of native config. register: result vyos.vyos.vyos_bgp_address_family: config: as_number: "65536" address_family: - afi: ipv6 redistribute: - protocol: static metric: 50 neighbors: - neighbor_address: 203.0.113.5 address_family: - afi: ipv6 allowas_in: 4 attribute_unchanged: med: true default_originate: map01 distribute_list: - action: export acl: 10 - neighbor_address: 192.0.2.25 address_family: - afi: ipv6 maximum_prefix: 45 nexthop_self: true route_map: - action: export route_map: map01 - action: import route_map: map01 state: rendered - assert: that: - result.changed == false - - result.rendered|symmetric_difference(merged.commands) == [] + - result.rendered|symmetric_difference(rendered.commands) == [] diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/cli/replaced.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/cli/replaced.yaml index 9b6f3303..15e45be3 100644 --- a/tests/integration/targets/vyos_bgp_address_family/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_bgp_address_family/tests/cli/replaced.yaml @@ -1,51 +1,51 @@ --- - debug: msg: START vyos_bgp_address_family replaced integration tests on connection={{ ansible_connection }} - include_tasks: _populate.yaml - block: - name: Replace the existing configuration with the provided running configuration register: result vyos.vyos.vyos_bgp_address_family: &id001 config: as_number: "65536" address_family: - afi: ipv6 redistribute: - protocol: static metric: 50 neighbors: - neighbor_address: 203.0.113.5 address_family: - afi: ipv6 allowas_in: 4 attribute_unchanged: med: true default_originate: map01 distribute_list: - action: export acl: 10 state: replaced - vyos.vyos.vyos_facts: gather_network_resources: bgp_address_family - assert: that: - - result.commands|length == 9 + - result.commands|length == replaced.commands|length - result.changed == true - result.commands|symmetric_difference(replaced.commands) == [] - result.after == ansible_facts['network_resources']['bgp_address_family'] - name: Replace the existing configuration with the provided running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_bgp_address_family: *id001 - name: Assert that the previous task was idempotent assert: that: - result['changed'] == false always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_address_family/tests/cli/rtt.yaml b/tests/integration/targets/vyos_bgp_address_family/tests/cli/rtt.yaml index baab61b0..49aeba78 100644 --- a/tests/integration/targets/vyos_bgp_address_family/tests/cli/rtt.yaml +++ b/tests/integration/targets/vyos_bgp_address_family/tests/cli/rtt.yaml @@ -1,83 +1,85 @@ --- - debug: msg: START vyos_bgp_address_family rtt integration tests on connection={{ ansible_connection }} +- include_tasks: _get_version.yaml + - include_tasks: _remove_config.yaml - include_tasks: _preconfig.yaml - block: - name: Merge the provided configuration with the existing running configuration register: baseconfig vyos.vyos.vyos_bgp_address_family: config: as_number: "65536" address_family: - afi: ipv6 redistribute: - protocol: static metric: 50 neighbors: - neighbor_address: 203.0.113.5 address_family: - afi: ipv6 allowas_in: 4 attribute_unchanged: med: true default_originate: map01 distribute_list: - action: export acl: 10 - neighbor_address: 192.0.2.25 address_family: - afi: ipv6 maximum_prefix: 45 nexthop_self: true route_map: - action: export route_map: map01 - action: import route_map: map01 state: merged - vyos.vyos.vyos_facts: gather_network_resources: bgp_address_family - assert: that: - - baseconfig.commands|length == 9 + - baseconfig.commands|length == merged.commands|length - baseconfig.changed == true - baseconfig.commands|symmetric_difference(merged.commands) == [] - baseconfig.after == ansible_facts['network_resources']['bgp_address_family'] - name: Apply the provided configuration (config to be reverted) register: result vyos.vyos.vyos_bgp_address_family: config: as_number: "65536" address_family: - afi: ipv6 aggregate_address: - summary_only: true prefix: 21e0:1:1::/64 networks: - prefix: 21e0:1:1::/64 route_map: map01 neighbors: - address_family: - afi: ipv6 remove_private_as: true neighbor_address: 203.0.113.5 - name: Revert back to base config using facts round trip register: revert vyos.vyos.vyos_bgp_address_family: config: "{{ ansible_facts['network_resources']['bgp_address_family'] }}" state: overridden - name: Assert that config was reverted assert: that: baseconfig.after == revert.after always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_address_family/vars/main.yaml b/tests/integration/targets/vyos_bgp_address_family/vars/main.yaml index 448918af..ed97d539 100644 --- a/tests/integration/targets/vyos_bgp_address_family/vars/main.yaml +++ b/tests/integration/targets/vyos_bgp_address_family/vars/main.yaml @@ -1,99 +1 @@ --- -merged: - commands: - - set protocols bgp 65536 address-family ipv6-unicast redistribute static metric 50 - - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast allowas-in number 4 - - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged med - - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast default-originate route-map map01 - - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast distribute-list export 10 - - set protocols bgp 65536 neighbor 192.0.2.25 address-family ipv6-unicast maximum-prefix 45 - - set protocols bgp 65536 neighbor 192.0.2.25 address-family ipv6-unicast nexthop-self - - set protocols bgp 65536 neighbor 192.0.2.25 address-family ipv6-unicast route-map export map01 - - set protocols bgp 65536 neighbor 192.0.2.25 address-family ipv6-unicast route-map import map01 - after: - address_family: - - afi: ipv6 - redistribute: - - metric: 50 - protocol: static - as_number: 65536 - neighbors: - - address_family: - - afi: ipv6 - maximum_prefix: 45 - nexthop_self: true - route_map: - - action: export - route_map: map01 - - action: import - route_map: map01 - neighbor_address: 192.0.2.25 - - address_family: - - afi: ipv6 - allowas_in: 4 - attribute_unchanged: - med: true - default_originate: map01 - distribute_list: - - acl: 10 - action: export - neighbor_address: 203.0.113.5 - -replaced: - commands: - - delete protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged - - delete protocols bgp 65536 address-family ipv6 aggregate-address - - delete protocols bgp 65536 address-family ipv6 network - - delete protocols bgp 65536 address-family ipv6-unicast redistribute ripng - - set protocols bgp 65536 address-family ipv6-unicast redistribute static metric 50 - - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast allowas-in number 4 - - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged med - - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast default-originate route-map map01 - - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast distribute-list export 10 - -overridden: - commands: - - delete protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged - - delete protocols bgp 65536 neighbor 192.0.2.25 address-family - - delete protocols bgp 65536 address-family ipv6-unicast redistribute ripng - - delete protocols bgp 65536 address-family ipv6 aggregate-address - - delete protocols bgp 65536 address-family ipv6 network - - set protocols bgp 65536 address-family ipv6-unicast redistribute static metric 50 - - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast allowas-in number 4 - - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged med - - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast default-originate route-map map01 - - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast distribute-list export 10 - -deleted: - commands: - - delete protocols bgp 65536 address-family ipv6-unicast - - delete protocols bgp 65536 neighbor 203.0.113.5 address-family - - delete protocols bgp 65536 neighbor 192.0.2.25 address-family ipv6-unicast - -populate: - config: - address_family: - - afi: ipv6 - aggregate_address: - - summary_only: true - prefix: 5000:1:1::/64 - networks: - - prefix: 21e0:1:1::/64 - route_map: map01 - redistribute: - - metric: 20 - protocol: ripng - as_number: 65536 - neighbors: - - address_family: - - afi: ipv6 - route_map: - - action: export - route_map: map01 - soft_reconfiguration: true - neighbor_address: 192.0.2.25 - - address_family: - - afi: ipv6 - attribute_unchanged: - next_hop: true - neighbor_address: 203.0.113.5 diff --git a/tests/integration/targets/vyos_bgp_address_family/vars/main.yaml b/tests/integration/targets/vyos_bgp_address_family/vars/pre-v1_4.yaml similarity index 98% copy from tests/integration/targets/vyos_bgp_address_family/vars/main.yaml copy to tests/integration/targets/vyos_bgp_address_family/vars/pre-v1_4.yaml index 448918af..c50db90a 100644 --- a/tests/integration/targets/vyos_bgp_address_family/vars/main.yaml +++ b/tests/integration/targets/vyos_bgp_address_family/vars/pre-v1_4.yaml @@ -1,99 +1,103 @@ --- +rendered: + commands: "{{ merged.commands }}" + merged: commands: - set protocols bgp 65536 address-family ipv6-unicast redistribute static metric 50 - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast allowas-in number 4 - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged med - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast default-originate route-map map01 - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast distribute-list export 10 - set protocols bgp 65536 neighbor 192.0.2.25 address-family ipv6-unicast maximum-prefix 45 - set protocols bgp 65536 neighbor 192.0.2.25 address-family ipv6-unicast nexthop-self - set protocols bgp 65536 neighbor 192.0.2.25 address-family ipv6-unicast route-map export map01 - set protocols bgp 65536 neighbor 192.0.2.25 address-family ipv6-unicast route-map import map01 + before: {} after: address_family: - afi: ipv6 redistribute: - metric: 50 protocol: static as_number: 65536 neighbors: - address_family: - afi: ipv6 maximum_prefix: 45 nexthop_self: true route_map: - action: export route_map: map01 - action: import route_map: map01 neighbor_address: 192.0.2.25 - address_family: - afi: ipv6 allowas_in: 4 attribute_unchanged: med: true default_originate: map01 distribute_list: - acl: 10 action: export neighbor_address: 203.0.113.5 replaced: commands: - delete protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged - delete protocols bgp 65536 address-family ipv6 aggregate-address - delete protocols bgp 65536 address-family ipv6 network - delete protocols bgp 65536 address-family ipv6-unicast redistribute ripng - set protocols bgp 65536 address-family ipv6-unicast redistribute static metric 50 - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast allowas-in number 4 - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged med - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast default-originate route-map map01 - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast distribute-list export 10 overridden: commands: - delete protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged - delete protocols bgp 65536 neighbor 192.0.2.25 address-family - delete protocols bgp 65536 address-family ipv6-unicast redistribute ripng - delete protocols bgp 65536 address-family ipv6 aggregate-address - delete protocols bgp 65536 address-family ipv6 network - set protocols bgp 65536 address-family ipv6-unicast redistribute static metric 50 - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast allowas-in number 4 - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged med - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast default-originate route-map map01 - set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast distribute-list export 10 deleted: commands: - delete protocols bgp 65536 address-family ipv6-unicast - delete protocols bgp 65536 neighbor 203.0.113.5 address-family - delete protocols bgp 65536 neighbor 192.0.2.25 address-family ipv6-unicast populate: config: address_family: - afi: ipv6 aggregate_address: - summary_only: true prefix: 5000:1:1::/64 networks: - prefix: 21e0:1:1::/64 route_map: map01 redistribute: - metric: 20 protocol: ripng as_number: 65536 neighbors: - address_family: - afi: ipv6 route_map: - action: export route_map: map01 soft_reconfiguration: true neighbor_address: 192.0.2.25 - address_family: - afi: ipv6 attribute_unchanged: next_hop: true neighbor_address: 203.0.113.5 diff --git a/tests/integration/targets/vyos_bgp_address_family/vars/v1_4.yaml b/tests/integration/targets/vyos_bgp_address_family/vars/v1_4.yaml new file mode 100644 index 00000000..a56e9ebf --- /dev/null +++ b/tests/integration/targets/vyos_bgp_address_family/vars/v1_4.yaml @@ -0,0 +1,113 @@ +--- +rendered: + commands: + - set protocols bgp system-as 65536 + - set protocols bgp address-family ipv6-unicast redistribute static metric 50 + - set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast allowas-in number 4 + - set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged med + - set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast default-originate route-map map01 + - set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast distribute-list export 10 + - set protocols bgp neighbor 192.0.2.25 address-family ipv6-unicast maximum-prefix 45 + - set protocols bgp neighbor 192.0.2.25 address-family ipv6-unicast nexthop-self + - set protocols bgp neighbor 192.0.2.25 address-family ipv6-unicast route-map export map01 + - set protocols bgp neighbor 192.0.2.25 address-family ipv6-unicast route-map import map01 + +merged: + commands: + - set protocols bgp address-family ipv6-unicast redistribute static metric 50 + - set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast allowas-in number 4 + - set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged med + - set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast default-originate route-map map01 + - set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast distribute-list export 10 + - set protocols bgp neighbor 192.0.2.25 address-family ipv6-unicast maximum-prefix 45 + - set protocols bgp neighbor 192.0.2.25 address-family ipv6-unicast nexthop-self + - set protocols bgp neighbor 192.0.2.25 address-family ipv6-unicast route-map export map01 + - set protocols bgp neighbor 192.0.2.25 address-family ipv6-unicast route-map import map01 + before: + as_number: 65536 + after: + address_family: + - afi: ipv6 + redistribute: + - metric: 50 + protocol: static + as_number: 65536 + neighbors: + - address_family: + - afi: ipv6 + maximum_prefix: 45 + nexthop_self: true + route_map: + - action: export + route_map: map01 + - action: import + route_map: map01 + neighbor_address: 192.0.2.25 + - address_family: + - afi: ipv6 + allowas_in: 4 + attribute_unchanged: + med: true + default_originate: map01 + distribute_list: + - acl: 10 + action: export + neighbor_address: 203.0.113.5 + +replaced: + commands: + - delete protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged + - delete protocols bgp address-family ipv6 aggregate-address + - delete protocols bgp address-family ipv6 network + - delete protocols bgp address-family ipv6-unicast redistribute ripng + - set protocols bgp address-family ipv6-unicast redistribute static metric 50 + - set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast allowas-in number 4 + - set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged med + - set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast default-originate route-map map01 + - set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast distribute-list export 10 + +overridden: + commands: + - delete protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged + - delete protocols bgp neighbor 192.0.2.25 address-family + - delete protocols bgp address-family ipv6-unicast redistribute ripng + - delete protocols bgp address-family ipv6 aggregate-address + - delete protocols bgp address-family ipv6 network + - set protocols bgp address-family ipv6-unicast redistribute static metric 50 + - set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast allowas-in number 4 + - set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged med + - set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast default-originate route-map map01 + - set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast distribute-list export 10 + +deleted: + commands: + - delete protocols bgp address-family ipv6-unicast + - delete protocols bgp neighbor 203.0.113.5 address-family + - delete protocols bgp neighbor 192.0.2.25 address-family ipv6-unicast + +populate: + config: + address_family: + - afi: ipv6 + aggregate_address: + - summary_only: true + prefix: 5000:1:1::/64 + networks: + - prefix: 21e0:1:1::/64 + route_map: map01 + redistribute: + - metric: 20 + protocol: ripng + neighbors: + - address_family: + - afi: ipv6 + route_map: + - action: export + route_map: map01 + soft_reconfiguration: true + neighbor_address: 192.0.2.25 + - address_family: + - afi: ipv6 + attribute_unchanged: + next_hop: true + neighbor_address: 203.0.113.5 diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/_get_version.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/_get_version.yaml new file mode 100644 index 00000000..2588b194 --- /dev/null +++ b/tests/integration/targets/vyos_bgp_global/tests/cli/_get_version.yaml @@ -0,0 +1,28 @@ +- name: make sure to get facts + vyos.vyos.vyos_facts: + vars: + ansible_connection: ansible.netcommon.network_cli + register: vyos_facts + when: vyos_version is not defined + +- name: debug vyos_facts + debug: + var: vyos_facts + +- name: pull version from facts + set_fact: + vyos_version: "{{ vyos_facts.ansible_facts.ansible_net_version.split('-')[0].split(' ')[-1] }}" + when: vyos_version is not defined + +- name: fix '.0' versions + set_fact: + vyos_version: "{{ vyos_version }}.0" + when: vyos_version.count('.') == 1 + +- name: include correct vars + include_vars: pre-v1_4.yaml + when: vyos_version is version('1.4.0', '<', version_type='semver') + +- name: include correct vars + include_vars: v1_4.yaml + when: vyos_version is version('1.4.0', '>=', version_type='semver') diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/_parsed_config.cfg b/tests/integration/targets/vyos_bgp_global/tests/cli/_parsed_config.cfg index 2338b03c..e8f78814 100644 --- a/tests/integration/targets/vyos_bgp_global/tests/cli/_parsed_config.cfg +++ b/tests/integration/targets/vyos_bgp_global/tests/cli/_parsed_config.cfg @@ -1,30 +1,19 @@ set policy access-list 20 description 'acl20' set policy access-list 40 description 'acl40' set policy route-map map01 description 'map01' -set protocols bgp 65536 aggregate-address 192.0.2.0/24 'summary-only' -set protocols bgp 65536 aggregate-address 203.0.113.0/24 'as-set' -set protocols bgp 65536 maximum-paths ebgp '20' -set protocols bgp 65536 maximum-paths ibgp '55' -set protocols bgp 65536 neighbor 192.0.2.25 'disable-connected-check' -set protocols bgp 65536 neighbor 192.0.2.25 timers holdtime '30' -set protocols bgp 65536 neighbor 192.0.2.25 timers keepalive '10' -set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'as-path' -set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'med' -set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'next-hop' -set protocols bgp 65536 neighbor 203.0.113.5 ebgp-multihop '2' -set protocols bgp 65536 neighbor 203.0.113.5 remote-as '101' -set protocols bgp 65536 neighbor 203.0.113.5 update-source '192.0.2.25' -set protocols bgp 65536 neighbor 5001::64 distribute-list export '20' -set protocols bgp 65536 neighbor 5001::64 distribute-list import '40' -set protocols bgp 65536 neighbor 5001::64 maximum-prefix '34' -set protocols bgp 65536 network 192.1.13.0/24 'backdoor' -set protocols bgp 65536 parameters bestpath as-path 'confed' -set protocols bgp 65536 parameters bestpath 'compare-routerid' -set protocols bgp 65536 parameters confederation identifier '66' -set protocols bgp 65536 parameters confederation peers '20' -set protocols bgp 65536 parameters confederation peers '55' -set protocols bgp 65536 parameters default 'no-ipv4-unicast' -set protocols bgp 65536 parameters router-id '192.1.2.9' -set protocols bgp 65536 redistribute connected route-map 'map01' -set protocols bgp 65536 redistribute kernel metric '45' -set protocols bgp 65536 timers keepalive '35' +set protocols bgp system-as '65536' +set protocols bgp neighbor 192.0.2.25 'disable-connected-check' +set protocols bgp neighbor 192.0.2.25 timers holdtime '30' +set protocols bgp neighbor 192.0.2.25 timers keepalive '10' +set protocols bgp neighbor 192.0.2.25 remote-as '102' +set protocols bgp neighbor 203.0.113.5 ebgp-multihop '2' +set protocols bgp neighbor 203.0.113.5 remote-as '101' +set protocols bgp neighbor 203.0.113.5 update-source '192.0.2.25' +set protocols bgp neighbor 5001::64 remote-as '103' +set protocols bgp parameters bestpath as-path 'confed' +set protocols bgp parameters bestpath 'compare-routerid' +set protocols bgp parameters confederation identifier '66' +set protocols bgp parameters confederation peers '20' +set protocols bgp parameters confederation peers '55' +set protocols bgp parameters router-id '192.1.2.9' +set protocols bgp timers keepalive '35' diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/_parsed_config.cfg b/tests/integration/targets/vyos_bgp_global/tests/cli/_parsed_config_1_3.cfg similarity index 51% copy from tests/integration/targets/vyos_bgp_global/tests/cli/_parsed_config.cfg copy to tests/integration/targets/vyos_bgp_global/tests/cli/_parsed_config_1_3.cfg index 2338b03c..fbf23261 100644 --- a/tests/integration/targets/vyos_bgp_global/tests/cli/_parsed_config.cfg +++ b/tests/integration/targets/vyos_bgp_global/tests/cli/_parsed_config_1_3.cfg @@ -1,30 +1,19 @@ set policy access-list 20 description 'acl20' set policy access-list 40 description 'acl40' set policy route-map map01 description 'map01' -set protocols bgp 65536 aggregate-address 192.0.2.0/24 'summary-only' -set protocols bgp 65536 aggregate-address 203.0.113.0/24 'as-set' -set protocols bgp 65536 maximum-paths ebgp '20' -set protocols bgp 65536 maximum-paths ibgp '55' set protocols bgp 65536 neighbor 192.0.2.25 'disable-connected-check' set protocols bgp 65536 neighbor 192.0.2.25 timers holdtime '30' set protocols bgp 65536 neighbor 192.0.2.25 timers keepalive '10' -set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'as-path' -set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'med' -set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'next-hop' +set protocols bgp 65536 neighbor 192.0.2.25 remote-as '102' set protocols bgp 65536 neighbor 203.0.113.5 ebgp-multihop '2' set protocols bgp 65536 neighbor 203.0.113.5 remote-as '101' set protocols bgp 65536 neighbor 203.0.113.5 update-source '192.0.2.25' -set protocols bgp 65536 neighbor 5001::64 distribute-list export '20' -set protocols bgp 65536 neighbor 5001::64 distribute-list import '40' -set protocols bgp 65536 neighbor 5001::64 maximum-prefix '34' -set protocols bgp 65536 network 192.1.13.0/24 'backdoor' +set protocols bgp 65536 neighbor 5001::64 remote-as '103' set protocols bgp 65536 parameters bestpath as-path 'confed' set protocols bgp 65536 parameters bestpath 'compare-routerid' set protocols bgp 65536 parameters confederation identifier '66' set protocols bgp 65536 parameters confederation peers '20' set protocols bgp 65536 parameters confederation peers '55' -set protocols bgp 65536 parameters default 'no-ipv4-unicast' +set protocols bgp 65536 parameters default local-pref 100 set protocols bgp 65536 parameters router-id '192.1.2.9' -set protocols bgp 65536 redistribute connected route-map 'map01' -set protocols bgp 65536 redistribute kernel metric '45' set protocols bgp 65536 timers keepalive '35' diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/_populate.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/_populate.yaml index 0f281c94..17fa22b1 100644 --- a/tests/integration/targets/vyos_bgp_global/tests/cli/_populate.yaml +++ b/tests/integration/targets/vyos_bgp_global/tests/cli/_populate.yaml @@ -1,39 +1,60 @@ --- - ansible.builtin.include_tasks: _remove_config.yaml -- name: Setup +- name: ensure facts + include_tasks: _get_version.yaml + +- name: Setup 1.3- vyos.vyos.vyos_config: lines: - set policy access-list 20 description 'acl20' - set policy access-list 40 description 'acl40' - set policy route-map map01 description 'map01' - - set protocols bgp 65536 aggregate-address 192.0.2.0/24 'summary-only' - - set protocols bgp 65536 aggregate-address 203.0.113.0/24 'as-set' - - set protocols bgp 65536 maximum-paths ebgp '20' - - set protocols bgp 65536 maximum-paths ibgp '55' - set protocols bgp 65536 neighbor 192.0.2.25 'disable-connected-check' - set protocols bgp 65536 neighbor 192.0.2.25 timers holdtime '30' - set protocols bgp 65536 neighbor 192.0.2.25 timers keepalive '10' - - set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'as-path' - - set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'med' - - set protocols bgp 65536 neighbor 203.0.113.5 attribute-unchanged 'next-hop' + - set protocols bgp 65536 neighbor 192.0.2.25 remote-as '102' - set protocols bgp 65536 neighbor 203.0.113.5 ebgp-multihop '2' - set protocols bgp 65536 neighbor 203.0.113.5 remote-as '101' - set protocols bgp 65536 neighbor 203.0.113.5 update-source '192.0.2.25' - - set protocols bgp 65536 neighbor 5001::64 distribute-list export '20' - - set protocols bgp 65536 neighbor 5001::64 distribute-list import '40' - - set protocols bgp 65536 neighbor 5001::64 maximum-prefix '34' - - set protocols bgp 65536 network 192.1.13.0/24 'backdoor' + - set protocols bgp 65536 neighbor 5001::64 remote-as '103' - set protocols bgp 65536 parameters bestpath as-path 'confed' - set protocols bgp 65536 parameters bestpath 'compare-routerid' - set protocols bgp 65536 parameters confederation identifier '66' - set protocols bgp 65536 parameters confederation peers '20' - set protocols bgp 65536 parameters confederation peers '55' - - set protocols bgp 65536 parameters default 'no-ipv4-unicast' + - set protocols bgp 65536 parameters default local-pref 100 - set protocols bgp 65536 parameters router-id '192.1.2.9' - - set protocols bgp 65536 redistribute connected route-map 'map01' - - set protocols bgp 65536 redistribute kernel metric '45' - set protocols bgp 65536 timers keepalive '35' ignore_errors: true vars: ansible_connection: ansible.netcommon.network_cli + when: vyos_version is version('1.4.0', '<', version_type='semver') + +- name: Setup 1.4+ + vyos.vyos.vyos_config: + lines: + - set policy access-list 20 description 'acl20' + - set policy access-list 40 description 'acl40' + - set policy route-map map01 description 'map01' + - set protocols bgp system-as 65536 + - set protocols bgp neighbor 192.0.2.25 'disable-connected-check' + - set protocols bgp neighbor 192.0.2.25 timers holdtime '30' + - set protocols bgp neighbor 192.0.2.25 timers keepalive '10' + - set protocols bgp neighbor 192.0.2.25 remote-as '102' + - set protocols bgp neighbor 203.0.113.5 ebgp-multihop '2' + - set protocols bgp neighbor 203.0.113.5 remote-as '101' + - set protocols bgp neighbor 203.0.113.5 update-source '192.0.2.25' + - set protocols bgp neighbor 5001::64 remote-as '103' + - set protocols bgp parameters bestpath as-path 'confed' + - set protocols bgp parameters bestpath 'compare-routerid' + - set protocols bgp parameters confederation identifier '66' + - set protocols bgp parameters confederation peers '20' + - set protocols bgp parameters confederation peers '55' + - set protocols bgp parameters default local-pref 100 + - set protocols bgp parameters router-id '192.1.2.9' + - set protocols bgp timers keepalive '35' + ignore_errors: true + vars: + ansible_connection: ansible.netcommon.network_cli + when: vyos_version is version('1.4.0', '>=', version_type='semver') diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/_populate_af.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/_populate_af.yaml index 59f3d925..0a06aeb3 100644 --- a/tests/integration/targets/vyos_bgp_global/tests/cli/_populate_af.yaml +++ b/tests/integration/targets/vyos_bgp_global/tests/cli/_populate_af.yaml @@ -1,12 +1,29 @@ --- -- name: setup +- name: ensure facts + include_tasks: _get_version.yaml + +- name: setup 1.3- AF vyos.vyos.vyos_config: lines: - set protocols bgp 65536 neighbor 5001::64 address-family 'ipv6-unicast' - set protocols bgp 65536 neighbor 5001::64 ebgp-multihop '2' - - set protocols bgp 65536 neighbor 5001::64 maximum-prefix '34' - - set protocols bgp 65536 neighbor 5001::64 remote-as '65535' + - set protocols bgp 65536 neighbor 5001::64 remote-as '103' - set protocols bgp 65536 neighbor 5001::64 update-source '2001:db8::1' + ignore_errors: true vars: ansible_connection: ansible.netcommon.network_cli + when: vyos_version is version('1.4.0', '<', version_type='semver') + +- name: setup 1.4+ AF + vyos.vyos.vyos_config: + lines: + - set protocols bgp system-as 65536 + - set protocols bgp neighbor 5001::64 address-family 'ipv6-unicast' + - set protocols bgp neighbor 5001::64 ebgp-multihop '2' + - set protocols bgp neighbor 5001::64 remote-as '103' + - set protocols bgp neighbor 5001::64 update-source '2001:db8::1' + ignore_errors: true + vars: + ansible_connection: ansible.netcommon.network_cli + when: vyos_version is version('1.4.0', '>=', version_type='semver') diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/_remove_config.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/_remove_config.yaml index 07d4aa47..9ccdb093 100644 --- a/tests/integration/targets/vyos_bgp_global/tests/cli/_remove_config.yaml +++ b/tests/integration/targets/vyos_bgp_global/tests/cli/_remove_config.yaml @@ -1,11 +1,11 @@ --- - name: Remove pre-existing bgp processes vyos.vyos.vyos_config: lines: - - delete protocols bgp 65536 + - delete protocols bgp - delete policy access-list 20 - delete policy access-list 40 - delete policy route-map map01 ignore_errors: true vars: ansible_connection: ansible.netcommon.network_cli diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/deleted.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/deleted.yaml index 5920c8f0..e652e127 100644 --- a/tests/integration/targets/vyos_bgp_global/tests/cli/deleted.yaml +++ b/tests/integration/targets/vyos_bgp_global/tests/cli/deleted.yaml @@ -1,35 +1,35 @@ --- - debug: msg: START vyos_bgp_global deleted integration tests on connection={{ ansible_connection }} - include_tasks: _populate.yaml - block: - name: Delete the provided configuration register: result vyos.vyos.vyos_bgp_global: &id001 config: as_number: "65536" state: deleted - vyos.vyos.vyos_facts: gather_network_resources: bgp_global - assert: that: - - result.commands|length == 9 + - result.commands|length == deleted.commands | length - result.changed == true - result.commands|symmetric_difference(deleted.commands) == [] - result.after == ansible_facts['network_resources']['bgp_global'] - name: Delete the existing configuration with the provided running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_bgp_global: *id001 - name: Assert that the previous task was idempotent assert: that: - result['changed'] == false always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/deleted_af.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/deleted_af.yaml index 88e6be09..d67d312b 100644 --- a/tests/integration/targets/vyos_bgp_global/tests/cli/deleted_af.yaml +++ b/tests/integration/targets/vyos_bgp_global/tests/cli/deleted_af.yaml @@ -1,23 +1,22 @@ --- - debug: msg: START vyos_bgp_global replaced integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml - include_tasks: _populate_af.yaml - block: - name: Delete the existing configuration, in presence of an af under neighbor. register: result ignore_errors: true vyos.vyos.vyos_bgp_global: config: as_number: "65536" state: deleted - assert: that: - result.msg == 'Use the _bgp_address_family module to delete the address_family under neighbor 5001::64, before replacing/deleting the neighbor.' - always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/merged.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/merged.yaml index 388bbccd..e11cd1ef 100644 --- a/tests/integration/targets/vyos_bgp_global/tests/cli/merged.yaml +++ b/tests/integration/targets/vyos_bgp_global/tests/cli/merged.yaml @@ -1,66 +1,48 @@ --- - debug: msg: START vyos_bgp_global merged integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml - include_tasks: _preconfig.yaml - block: - name: Merge the provided configuration with the existing running configuration register: result vyos.vyos.vyos_bgp_global: &id001 config: as_number: "65536" - aggregate_address: - - prefix: 203.0.113.0/24 - as_set: true - - prefix: 192.0.2.0/24 - summary_only: true - network: - - address: 192.1.13.0/24 - backdoor: true - redistribute: - - protocol: kernel - metric: 45 - - protocol: connected - route_map: map01 - maximum_paths: - - path: ebgp - count: 20 - - path: ibgp - count: 55 timers: keepalive: 35 bgp_params: bestpath: as_path: confed compare_routerid: true default: - no_ipv4_unicast: true + local_pref: 100 router_id: 192.1.2.9 state: merged - vyos.vyos.vyos_facts: gather_network_resources: bgp_global - assert: that: - - result.commands|length == 12 + - result.commands|length == merged.commands | length - result.changed == true - result.commands|symmetric_difference(merged.commands) == [] - result.after == ansible_facts['network_resources']['bgp_global'] - result.before == {} - result.after == merged.after - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_bgp_global: *id001 - name: Assert that the previous task was idempotent assert: that: - result['changed'] == false always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/parsed.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/parsed.yaml index eca85ce0..293c204c 100644 --- a/tests/integration/targets/vyos_bgp_global/tests/cli/parsed.yaml +++ b/tests/integration/targets/vyos_bgp_global/tests/cli/parsed.yaml @@ -1,14 +1,34 @@ --- - debug: msg: START vyos_bgp_global parsed integration tests on connection={{ ansible_connection }} -- name: Provide the running configuration for parsing (config to be parsed) - register: result - vyos.vyos.vyos_bgp_global: - running_config: "{{ lookup('file', '_parsed_config.cfg') }}" - state: parsed +- name: ensure facts + include_tasks: _get_version.yaml +- name: version 1.3 + block: + - name: Provide the running configuration for parsing (config to be parsed) + register: result + vyos.vyos.vyos_bgp_global: + running_config: "{{ lookup('file', '_parsed_config_1_3.cfg') }}" + state: parsed + - name: set result + set_fact: + parsed_result: "{{ result }}" + when: vyos_version is version('1.4.0', '<', version_type='semver') + +- name: version 1.4+ + block: + - name: Provide the running configuration for parsing (config to be parsed) + register: result + vyos.vyos.vyos_bgp_global: + running_config: "{{ lookup('file', '_parsed_config.cfg') }}" + state: parsed + - name: set result + set_fact: + parsed_result: "{{ result }}" + when: vyos_version is version('1.4.0', '>=', version_type='semver') - assert: that: - - result.changed == false - - result.parsed == populate.global + - parsed_result.changed == false + - parsed_result.parsed == populate.global diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/purged.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/purged.yaml index 71748f5c..dfc2e435 100644 --- a/tests/integration/targets/vyos_bgp_global/tests/cli/purged.yaml +++ b/tests/integration/targets/vyos_bgp_global/tests/cli/purged.yaml @@ -1,26 +1,35 @@ --- - debug: msg: START vyos_bgp_global purged integration tests on connection={{ ansible_connection }} - include_tasks: _populate.yaml - block: - name: Purge the provided configuration register: result vyos.vyos.vyos_bgp_global: config: as_number: "65536" state: purged - vyos.vyos.vyos_facts: gather_network_resources: bgp_global - assert: that: - result.commands|length == 1 - result.changed == true - "'delete protocols bgp 65536' in result.commands" - ansible_facts.network_resources.bgp_global == [] + when: vyos_version is version('1.4.0', '<', version_type='semver') + + - assert: + that: + - result.commands|length == 1 + - result.changed == true + - "'delete protocols bgp' in result.commands" + - ansible_facts.network_resources.bgp_global == [] + when: vyos_version is version('1.4.0', '>=', version_type='semver') always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/rendered.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/rendered.yaml index f37ef882..39fc12a8 100644 --- a/tests/integration/targets/vyos_bgp_global/tests/cli/rendered.yaml +++ b/tests/integration/targets/vyos_bgp_global/tests/cli/rendered.yaml @@ -1,43 +1,25 @@ --- - debug: msg: START vyos_bgp_global merged integration tests on connection={{ ansible_connection }} - block: - name: Render given bgp_global configuration register: result vyos.vyos.vyos_bgp_global: config: as_number: "65536" - aggregate_address: - - prefix: 203.0.113.0/24 - as_set: true - - prefix: 192.0.2.0/24 - summary_only: true - network: - - address: 192.1.13.0/24 - backdoor: true - redistribute: - - protocol: kernel - metric: 45 - - protocol: connected - route_map: map01 - maximum_paths: - - path: ebgp - count: 20 - - path: ibgp - count: 55 timers: keepalive: 35 bgp_params: bestpath: as_path: confed compare_routerid: true default: - no_ipv4_unicast: true + local_pref: 100 router_id: 192.1.2.9 state: rendered - assert: that: - result.changed == false - result.rendered|symmetric_difference(merged.commands) == [] diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/replaced.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/replaced.yaml index ae2c5c75..22323c3d 100644 --- a/tests/integration/targets/vyos_bgp_global/tests/cli/replaced.yaml +++ b/tests/integration/targets/vyos_bgp_global/tests/cli/replaced.yaml @@ -1,65 +1,59 @@ --- - debug: msg: START vyos_bgp_global replaced integration tests on connection={{ ansible_connection }} - include_tasks: _populate.yaml - block: - name: Replace the existing configuration with the provided running configuration register: result vyos.vyos.vyos_bgp_global: &id001 config: as_number: "65536" - network: - - address: 203.0.113.0/24 - route_map: map01 - redistribute: - - protocol: static - route_map: map01 bgp_params: always_compare_med: true dampening: start_suppress_time: 5 max_suppress_time: 20 half_life: 33 re_use: 60 bestpath: as_path: confed compare_routerid: true - default: - no_ipv4_unicast: true neighbor: - address: 192.0.2.43 disable_connected_check: true advertisement_interval: 72 capability: dynamic: true timers: holdtime: 30 keepalive: 10 + remote_as: 102 - address: 203.0.113.0 capability: - orf: receive + dynamic: true + remote_as: 102 state: replaced - vyos.vyos.vyos_facts: gather_network_resources: bgp_global - assert: that: - - result.commands|length == 24 + - result.commands|length == replaced.commands|length - result.changed == true - result.commands|symmetric_difference(replaced.commands) == [] - result.after == ansible_facts['network_resources']['bgp_global'] - name: Replace the existing configuration with the provided running configuration (IDEMPOTENT) register: result vyos.vyos.vyos_bgp_global: *id001 - name: Assert that the previous task was idempotent assert: that: - result['changed'] == false always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_global/tests/cli/replaced_af.yaml b/tests/integration/targets/vyos_bgp_global/tests/cli/replaced_af.yaml index c9b23193..3054ea1f 100644 --- a/tests/integration/targets/vyos_bgp_global/tests/cli/replaced_af.yaml +++ b/tests/integration/targets/vyos_bgp_global/tests/cli/replaced_af.yaml @@ -1,53 +1,47 @@ --- - debug: msg: START vyos_bgp_global replaced integration tests on connection={{ ansible_connection }} - include_tasks: _remove_config.yaml - include_tasks: _populate_af.yaml - block: - name: Replace the existing af configuration with the provided running configuration register: result ignore_errors: true vyos.vyos.vyos_bgp_global: config: as_number: "65536" - network: - - address: 203.0.113.0/24 - route_map: map01 - redistribute: - - protocol: static - route_map: map01 bgp_params: always_compare_med: true dampening: start_suppress_time: 5 max_suppress_time: 20 half_life: 33 re_use: 60 bestpath: as_path: confed compare_routerid: true - default: - no_ipv4_unicast: true neighbor: - address: 192.0.2.43 disable_connected_check: true advertisement_interval: 72 capability: dynamic: true timers: holdtime: 30 keepalive: 10 + remote_as: 102 - address: 203.0.113.0 capability: - orf: receive + dynamic: true + remote_as: 102 state: replaced - assert: that: - result.msg == 'Use the _bgp_address_family module to delete the address_family under neighbor 5001::64, before replacing/deleting the neighbor.' always: - include_tasks: _remove_config.yaml diff --git a/tests/integration/targets/vyos_bgp_global/vars/main.yaml b/tests/integration/targets/vyos_bgp_global/vars/main.yaml index e195c2d7..ed97d539 100644 --- a/tests/integration/targets/vyos_bgp_global/vars/main.yaml +++ b/tests/integration/targets/vyos_bgp_global/vars/main.yaml @@ -1,150 +1 @@ --- -merged: - commands: - - set protocols bgp 65536 redistribute kernel metric 45 - - set protocols bgp 65536 redistribute connected route-map map01 - - set protocols bgp 65536 network 192.1.13.0/24 backdoor - - set protocols bgp 65536 aggregate-address 203.0.113.0/24 as-set - - set protocols bgp 65536 aggregate-address 192.0.2.0/24 summary-only - - set protocols bgp 65536 parameters bestpath as-path confed - - set protocols bgp 65536 parameters bestpath compare-routerid - - set protocols bgp 65536 parameters default no-ipv4-unicast - - set protocols bgp 65536 parameters router-id 192.1.2.9 - - set protocols bgp 65536 maximum-paths ebgp 20 - - set protocols bgp 65536 maximum-paths ibgp 55 - - set protocols bgp 65536 timers keepalive 35 - after: - aggregate_address: - - prefix: 192.0.2.0/24 - summary_only: true - - prefix: 203.0.113.0/24 - as_set: true - as_number: 65536 - bgp_params: - bestpath: - as_path: confed - compare_routerid: true - default: - no_ipv4_unicast: true - router_id: 192.1.2.9 - maximum_paths: - - count: 20 - path: ebgp - - count: 55 - path: ibgp - network: - - address: 192.1.13.0/24 - backdoor: true - redistribute: - - protocol: connected - route_map: map01 - - metric: 45 - protocol: kernel - timers: - keepalive: 35 - -replaced: - commands: - - delete protocols bgp 65536 timers - - delete protocols bgp 65536 maximum-paths - - delete protocols bgp 65536 parameters router-id 192.1.2.9 - - delete protocols bgp 65536 parameters confederation - - delete protocols bgp 65536 aggregate-address - - delete protocols bgp 65536 network 192.1.13.0/24 - - delete protocols bgp 65536 redistribute kernel - - delete protocols bgp 65536 redistribute connected - - delete protocols bgp 65536 neighbor 5001::64 - - delete protocols bgp 65536 neighbor 203.0.113.5 - - delete protocols bgp 65536 neighbor 192.0.2.25 - - set protocols bgp 65536 neighbor 192.0.2.43 disable-connected-check - - set protocols bgp 65536 neighbor 192.0.2.43 advertisement-interval 72 - - set protocols bgp 65536 neighbor 192.0.2.43 capability dynamic - - set protocols bgp 65536 neighbor 192.0.2.43 timers holdtime 30 - - set protocols bgp 65536 neighbor 192.0.2.43 timers keepalive 10 - - set protocols bgp 65536 neighbor 203.0.113.0 capability orf prefix-list receive - - set protocols bgp 65536 redistribute static route-map map01 - - set protocols bgp 65536 network 203.0.113.0/24 route-map map01 - - set protocols bgp 65536 parameters always-compare-med - - set protocols bgp 65536 parameters dampening half-life 33 - - set protocols bgp 65536 parameters dampening max-suppress-time 20 - - set protocols bgp 65536 parameters dampening re-use 60 - - set protocols bgp 65536 parameters dampening start-suppress-time 5 - -deleted: - commands: - - delete protocols bgp 65536 timers - - delete protocols bgp 65536 maximum-paths - - delete protocols bgp 65536 parameters - - delete protocols bgp 65536 aggregate-address - - delete protocols bgp 65536 network - - delete protocols bgp 65536 redistribute - - delete protocols bgp 65536 neighbor 5001::64 - - delete protocols bgp 65536 neighbor 203.0.113.5 - - delete protocols bgp 65536 neighbor 192.0.2.25 - -rendered: - commands: - - set interfaces ethernet eth1 firewall in name 'INBOUND' - - set interfaces ethernet eth1 firewall out name 'OUTBOUND' - - set interfaces ethernet eth1 firewall local name 'LOCAL' - - set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL' - - set interfaces ethernet eth2 firewall in name 'INBOUND' - - set interfaces ethernet eth2 firewall out name 'OUTBOUND' - - set interfaces ethernet eth2 firewall local name 'LOCAL' - - set interfaces ethernet eth2 firewall local ipv6-name 'V6-LOCAL' - -populate: - global: - aggregate_address: - - prefix: 192.0.2.0/24 - summary_only: true - - prefix: 203.0.113.0/24 - as_set: true - as_number: 65536 - bgp_params: - bestpath: - as_path: confed - compare_routerid: true - confederation: - - identifier: 66 - - peers: 20 - - peers: 55 - default: - no_ipv4_unicast: true - router_id: 192.1.2.9 - maximum_paths: - - count: 20 - path: ebgp - - count: 55 - path: ibgp - neighbor: - - address: 192.0.2.25 - disable_connected_check: true - timers: - holdtime: 30 - keepalive: 10 - - address: 203.0.113.5 - attribute_unchanged: - as_path: true - med: true - next_hop: true - ebgp_multihop: 2 - remote_as: 101 - update_source: 192.0.2.25 - - address: 5001::64 - distribute_list: - - acl: 20 - action: export - - acl: 40 - action: import - maximum_prefix: 34 - network: - - address: 192.1.13.0/24 - backdoor: true - redistribute: - - protocol: connected - route_map: map01 - - metric: 45 - protocol: kernel - timers: - keepalive: 35 diff --git a/tests/integration/targets/vyos_bgp_global/vars/main.yaml b/tests/integration/targets/vyos_bgp_global/vars/pre-v1_4.yaml similarity index 55% copy from tests/integration/targets/vyos_bgp_global/vars/main.yaml copy to tests/integration/targets/vyos_bgp_global/vars/pre-v1_4.yaml index e195c2d7..efac1b98 100644 --- a/tests/integration/targets/vyos_bgp_global/vars/main.yaml +++ b/tests/integration/targets/vyos_bgp_global/vars/pre-v1_4.yaml @@ -1,150 +1,91 @@ --- merged: commands: - - set protocols bgp 65536 redistribute kernel metric 45 - - set protocols bgp 65536 redistribute connected route-map map01 - - set protocols bgp 65536 network 192.1.13.0/24 backdoor - - set protocols bgp 65536 aggregate-address 203.0.113.0/24 as-set - - set protocols bgp 65536 aggregate-address 192.0.2.0/24 summary-only - set protocols bgp 65536 parameters bestpath as-path confed - set protocols bgp 65536 parameters bestpath compare-routerid - - set protocols bgp 65536 parameters default no-ipv4-unicast + - set protocols bgp 65536 parameters default local-pref 100 - set protocols bgp 65536 parameters router-id 192.1.2.9 - - set protocols bgp 65536 maximum-paths ebgp 20 - - set protocols bgp 65536 maximum-paths ibgp 55 - set protocols bgp 65536 timers keepalive 35 after: - aggregate_address: - - prefix: 192.0.2.0/24 - summary_only: true - - prefix: 203.0.113.0/24 - as_set: true as_number: 65536 bgp_params: bestpath: as_path: confed compare_routerid: true default: - no_ipv4_unicast: true + local_pref: 100 router_id: 192.1.2.9 - maximum_paths: - - count: 20 - path: ebgp - - count: 55 - path: ibgp - network: - - address: 192.1.13.0/24 - backdoor: true - redistribute: - - protocol: connected - route_map: map01 - - metric: 45 - protocol: kernel timers: keepalive: 35 replaced: commands: - delete protocols bgp 65536 timers - - delete protocols bgp 65536 maximum-paths - delete protocols bgp 65536 parameters router-id 192.1.2.9 + - delete protocols bgp 65536 parameters default - delete protocols bgp 65536 parameters confederation - - delete protocols bgp 65536 aggregate-address - - delete protocols bgp 65536 network 192.1.13.0/24 - - delete protocols bgp 65536 redistribute kernel - - delete protocols bgp 65536 redistribute connected - delete protocols bgp 65536 neighbor 5001::64 - delete protocols bgp 65536 neighbor 203.0.113.5 - delete protocols bgp 65536 neighbor 192.0.2.25 - set protocols bgp 65536 neighbor 192.0.2.43 disable-connected-check - set protocols bgp 65536 neighbor 192.0.2.43 advertisement-interval 72 - set protocols bgp 65536 neighbor 192.0.2.43 capability dynamic - set protocols bgp 65536 neighbor 192.0.2.43 timers holdtime 30 - set protocols bgp 65536 neighbor 192.0.2.43 timers keepalive 10 - - set protocols bgp 65536 neighbor 203.0.113.0 capability orf prefix-list receive - - set protocols bgp 65536 redistribute static route-map map01 - - set protocols bgp 65536 network 203.0.113.0/24 route-map map01 + - set protocols bgp 65536 neighbor 192.0.2.43 remote-as 102 + - set protocols bgp 65536 neighbor 203.0.113.0 capability dynamic + - set protocols bgp 65536 neighbor 203.0.113.0 remote-as 102 - set protocols bgp 65536 parameters always-compare-med - set protocols bgp 65536 parameters dampening half-life 33 - set protocols bgp 65536 parameters dampening max-suppress-time 20 - set protocols bgp 65536 parameters dampening re-use 60 - set protocols bgp 65536 parameters dampening start-suppress-time 5 deleted: commands: - delete protocols bgp 65536 timers - - delete protocols bgp 65536 maximum-paths - delete protocols bgp 65536 parameters - - delete protocols bgp 65536 aggregate-address - - delete protocols bgp 65536 network - - delete protocols bgp 65536 redistribute - delete protocols bgp 65536 neighbor 5001::64 - delete protocols bgp 65536 neighbor 203.0.113.5 - delete protocols bgp 65536 neighbor 192.0.2.25 rendered: commands: - set interfaces ethernet eth1 firewall in name 'INBOUND' - set interfaces ethernet eth1 firewall out name 'OUTBOUND' - set interfaces ethernet eth1 firewall local name 'LOCAL' - set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL' - set interfaces ethernet eth2 firewall in name 'INBOUND' - set interfaces ethernet eth2 firewall out name 'OUTBOUND' - set interfaces ethernet eth2 firewall local name 'LOCAL' - set interfaces ethernet eth2 firewall local ipv6-name 'V6-LOCAL' populate: global: - aggregate_address: - - prefix: 192.0.2.0/24 - summary_only: true - - prefix: 203.0.113.0/24 - as_set: true as_number: 65536 bgp_params: bestpath: as_path: confed compare_routerid: true confederation: - identifier: 66 - peers: 20 - peers: 55 default: - no_ipv4_unicast: true + local_pref: 100 router_id: 192.1.2.9 - maximum_paths: - - count: 20 - path: ebgp - - count: 55 - path: ibgp neighbor: - address: 192.0.2.25 disable_connected_check: true timers: holdtime: 30 keepalive: 10 + remote_as: 102 - address: 203.0.113.5 - attribute_unchanged: - as_path: true - med: true - next_hop: true ebgp_multihop: 2 remote_as: 101 update_source: 192.0.2.25 - address: 5001::64 - distribute_list: - - acl: 20 - action: export - - acl: 40 - action: import - maximum_prefix: 34 - network: - - address: 192.1.13.0/24 - backdoor: true - redistribute: - - protocol: connected - route_map: map01 - - metric: 45 - protocol: kernel + remote_as: 103 timers: keepalive: 35 diff --git a/tests/integration/targets/vyos_bgp_global/vars/v1_4.yaml b/tests/integration/targets/vyos_bgp_global/vars/v1_4.yaml new file mode 100644 index 00000000..1dd462b1 --- /dev/null +++ b/tests/integration/targets/vyos_bgp_global/vars/v1_4.yaml @@ -0,0 +1,90 @@ +--- +merged: + commands: + - set protocols bgp system-as 65536 + - set protocols bgp parameters bestpath as-path confed + - set protocols bgp parameters bestpath compare-routerid + - set protocols bgp parameters default local-pref 100 + - set protocols bgp parameters router-id 192.1.2.9 + - set protocols bgp timers keepalive 35 + after: + as_number: 65536 + bgp_params: + bestpath: + as_path: confed + compare_routerid: true + default: + local_pref: 100 + router_id: 192.1.2.9 + timers: + keepalive: 35 + +replaced: + commands: + - delete protocols bgp timers + - delete protocols bgp parameters router-id 192.1.2.9 + - delete protocols bgp parameters default + - delete protocols bgp parameters confederation + - delete protocols bgp neighbor 5001::64 + - delete protocols bgp neighbor 203.0.113.5 + - delete protocols bgp neighbor 192.0.2.25 + - set protocols bgp neighbor 192.0.2.43 disable-connected-check + - set protocols bgp neighbor 192.0.2.43 advertisement-interval 72 + - set protocols bgp neighbor 192.0.2.43 capability dynamic + - set protocols bgp neighbor 192.0.2.43 timers holdtime 30 + - set protocols bgp neighbor 192.0.2.43 timers keepalive 10 + - set protocols bgp neighbor 192.0.2.43 remote-as 102 + - set protocols bgp neighbor 203.0.113.0 capability dynamic + - set protocols bgp neighbor 203.0.113.0 remote-as 102 + - set protocols bgp parameters always-compare-med + - set protocols bgp parameters dampening half-life 33 + - set protocols bgp parameters dampening max-suppress-time 20 + - set protocols bgp parameters dampening re-use 60 + - set protocols bgp parameters dampening start-suppress-time 5 + +deleted: + commands: + - delete protocols bgp timers + - delete protocols bgp parameters + - delete protocols bgp neighbor 5001::64 + - delete protocols bgp neighbor 203.0.113.5 + - delete protocols bgp neighbor 192.0.2.25 + +rendered: + commands: + - set interfaces ethernet eth1 firewall in name 'INBOUND' + - set interfaces ethernet eth1 firewall out name 'OUTBOUND' + - set interfaces ethernet eth1 firewall local name 'LOCAL' + - set interfaces ethernet eth1 firewall local ipv6-name 'V6-LOCAL' + - set interfaces ethernet eth2 firewall in name 'INBOUND' + - set interfaces ethernet eth2 firewall out name 'OUTBOUND' + - set interfaces ethernet eth2 firewall local name 'LOCAL' + - set interfaces ethernet eth2 firewall local ipv6-name 'V6-LOCAL' + +populate: + global: + as_number: 65536 + bgp_params: + bestpath: + as_path: confed + compare_routerid: true + confederation: + - identifier: 66 + - peers: 20 + - peers: 55 + router_id: 192.1.2.9 + neighbor: + - address: 192.0.2.25 + disable_connected_check: true + timers: + holdtime: 30 + keepalive: 10 + remote_as: 102 + - address: 203.0.113.5 + ebgp_multihop: 2 + remote_as: 101 + update_source: 192.0.2.25 + - address: 5001::64 + remote_as: 103 + timers: + keepalive: 35 diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_bgp_address_family_config_14.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_address_family_config_14.cfg new file mode 100644 index 00000000..20b8ee28 --- /dev/null +++ b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_address_family_config_14.cfg @@ -0,0 +1,8 @@ +set protocols bgp system-as 65536 +set protocols bgp address-family ipv4-unicast aggregate-address 192.0.2.0/24 as-set +set protocols bgp address-family ipv4-unicast network 192.1.13.0/24 route-map 'map01' +set protocols bgp address-family ipv4-unicast network 192.2.13.0/24 backdoor +set protocols bgp address-family ipv6-unicast redistribute ripng metric '20' +set protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast route-map export 'map01' +set protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast soft-reconfiguration inbound +set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged next-hop diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_bgp_af_ops_config.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_af_ops_config.cfg new file mode 100644 index 00000000..bc2704aa --- /dev/null +++ b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_af_ops_config.cfg @@ -0,0 +1,5 @@ +set protocols bgp 65536 address-family ipv4-unicast network 192.1.13.0/24 +set protocols bgp 65536 address-family ipv4-unicast network 192.2.13.0/24 backdoor +set protocols bgp 65536 address-family ipv6-unicast redistribute ripng metric '20' +set protocols bgp 65536 address-family ipv4-unicast redistribute rip metric '15' +set protocols bgp 65536 address-family ipv4-unicast redistribute ospf \ No newline at end of file diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_bgp_af_ops_config_14.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_af_ops_config_14.cfg new file mode 100644 index 00000000..b09da39d --- /dev/null +++ b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_af_ops_config_14.cfg @@ -0,0 +1,6 @@ +set protocols bgp system-as '65536' +set protocols bgp address-family ipv4-unicast network 192.1.13.0/24 +set protocols bgp address-family ipv4-unicast network 192.2.13.0/24 backdoor +set protocols bgp address-family ipv6-unicast redistribute ripng metric '20' +set protocols bgp address-family ipv4-unicast redistribute rip metric '15' +set protocols bgp address-family ipv4-unicast redistribute ospf \ No newline at end of file diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_af_config.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_af_config.cfg index 7d990d6b..7f6b1698 100644 --- a/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_af_config.cfg +++ b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_af_config.cfg @@ -1,5 +1,4 @@ set protocols bgp 65536 neighbor 5001::64 address-family 'ipv6-unicast' set protocols bgp 65536 neighbor 5001::64 ebgp-multihop '2' -set protocols bgp 65536 neighbor 5001::64 maximum-prefix '34' set protocols bgp 65536 neighbor 5001::64 remote-as '65535' set protocols bgp 65536 neighbor 5001::64 update-source '2001:db8::1' diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_af_config_14.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_af_config_14.cfg new file mode 100644 index 00000000..385ed1ec --- /dev/null +++ b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_af_config_14.cfg @@ -0,0 +1,5 @@ +set protocols bgp system-as 65536 +set protocols bgp neighbor 5001::64 address-family 'ipv6-unicast' +set protocols bgp neighbor 5001::64 ebgp-multihop '2' +set protocols bgp neighbor 5001::64 remote-as '65535' +set protocols bgp neighbor 5001::64 update-source '2001:db8::1' diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_config.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_config.cfg index 00c615fd..0142ccef 100644 --- a/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_config.cfg +++ b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_config.cfg @@ -1,23 +1,13 @@ set protocols bgp 65536 neighbor 10.0.0.4 'disable-connected-check' set protocols bgp 65536 neighbor 10.0.0.4 timers holdtime '30' set protocols bgp 65536 neighbor 10.0.0.4 timers keepalive '10' -set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged 'as-path' -set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged 'med' set protocols bgp 65536 neighbor 192.168.0.2 ebgp-multihop '2' set protocols bgp 65536 neighbor 192.168.0.2 remote-as '65535' -set protocols bgp 65536 neighbor 192.168.0.2 soft-reconfiguration 'inbound' set protocols bgp 65536 neighbor 192.168.0.2 update-source '192.168.0.1' set protocols bgp 65536 neighbor 2001:db8::2 ebgp-multihop '2' -set protocols bgp 65536 neighbor 2001:db8::2 maximum-prefix '34' set protocols bgp 65536 neighbor 2001:db8::2 remote-as '65535' set protocols bgp 65536 neighbor 2001:db8::2 update-source '2001:db8::1' -set protocols bgp 65536 network 172.16.42.32/27 'backdoor' -set protocols bgp 65536 network 172.16.42.251/32 route-map 'map01' set protocols bgp 65536 parameters bestpath as-path 'confed' set protocols bgp 65536 parameters bestpath 'compare-routerid' set protocols bgp 65536 parameters default 'no-ipv4-unicast' set protocols bgp 65536 parameters router-id '10.1.1.1' -set protocols bgp 65536 neighbor 10.0.0.4 capability orf prefix-list 'receive' -set protocols bgp 65536 redistribute kernel route-map 'map01' -set protocols bgp 65536 redistribute static metric '20' -set protocols bgp 65536 redistribute static route-map 'map01' diff --git a/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_config_14.cfg b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_config_14.cfg new file mode 100644 index 00000000..f6674ecd --- /dev/null +++ b/tests/unit/modules/network/vyos/fixtures/vyos_bgp_global_config_14.cfg @@ -0,0 +1,14 @@ +set protocols bgp system-as 65536 +set protocols bgp neighbor 10.0.0.4 'disable-connected-check' +set protocols bgp neighbor 10.0.0.4 timers holdtime '30' +set protocols bgp neighbor 10.0.0.4 timers keepalive '10' +set protocols bgp neighbor 192.168.0.2 ebgp-multihop '2' +set protocols bgp neighbor 192.168.0.2 remote-as '65535' +set protocols bgp neighbor 192.168.0.2 update-source '192.168.0.1' +set protocols bgp neighbor 2001:db8::2 ebgp-multihop '2' +set protocols bgp neighbor 2001:db8::2 remote-as '65535' +set protocols bgp neighbor 2001:db8::2 update-source '2001:db8::1' +set protocols bgp parameters bestpath as-path 'confed' +set protocols bgp parameters bestpath 'compare-routerid' +set protocols bgp parameters default 'no-ipv4-unicast' +set protocols bgp parameters router-id '10.1.1.1' diff --git a/tests/unit/modules/network/vyos/test_vyos_bgp_address_family.py b/tests/unit/modules/network/vyos/test_vyos_bgp_address_family.py index 87b3ad9d..7ea9b2cd 100644 --- a/tests/unit/modules/network/vyos/test_vyos_bgp_address_family.py +++ b/tests/unit/modules/network/vyos/test_vyos_bgp_address_family.py @@ -1,602 +1,790 @@ # (c) 2016 Red Hat Inc. # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . # Make coding more python3-ish from __future__ import absolute_import, division, print_function __metaclass__ = type from unittest.mock import patch from ansible_collections.vyos.vyos.plugins.modules import vyos_bgp_address_family from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args from .vyos_module import TestVyosModule, load_fixture -class TestVyosBgpafModule(TestVyosModule): +class TestVyosBgpafModule13(TestVyosModule): module = vyos_bgp_address_family def setUp(self): - super(TestVyosBgpafModule, self).setUp() + super(TestVyosBgpafModule13, self).setUp() self.mock_get_resource_connection_config = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", ) self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_execute_show_command = patch( "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts." + "bgp_address_family.bgp_address_family.Bgp_address_familyFacts.get_device_data", ) self.execute_show_command = self.mock_execute_show_command.start() + self.mock_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.bgp_address_family.bgp_address_family.get_os_version" + ) + self.test_version = "1.2" + self.get_os_version = self.mock_get_os_version.start() + self.get_os_version.return_value = self.test_version + self.mock_facts_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_address_family.bgp_address_family.get_os_version" + ) + self.get_facts_os_version = self.mock_facts_get_os_version.start() + self.get_facts_os_version.return_value = self.test_version + self.maxDiff = None def tearDown(self): - super(TestVyosBgpafModule, self).tearDown() + super(TestVyosBgpafModule13, self).tearDown() self.mock_get_resource_connection_config.stop() self.mock_execute_show_command.stop() + self.mock_get_os_version.stop() + self.mock_facts_get_os_version.stop() def load_fixtures(self, commands=None, filename=None): if filename is None: filename = "vyos_bgp_address_family_config.cfg" def load_from_file(*args, **kwargs): output = load_fixture(filename) return output self.execute_show_command.side_effect = load_from_file def test_vyos_bgp_address_family_merged_idempotent(self): set_module_args( dict( config=dict( as_number=65536, address_family=[ dict( afi="ipv4", aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], networks=[ dict(prefix="192.1.13.0/24", route_map="map01"), dict(prefix="192.2.13.0/24", backdoor=True), ], ), dict( afi="ipv6", redistribute=[dict(protocol="ripng", metric=20)], ), ], neighbors=[ dict( neighbor_address="192.0.2.25", address_family=[ dict( afi="ipv4", route_map=[dict(action="export", route_map="map01")], soft_reconfiguration=True, ), ], ), dict( neighbor_address="203.0.113.5", address_family=[ dict( afi="ipv6", attribute_unchanged=dict(next_hop=True), ), ], ), ], ), ), ) self.execute_module(changed=False, commands=[]) def test_vyos_bgp_address_family_merged(self): set_module_args( dict( config=dict( as_number=65536, address_family=[ dict( afi="ipv4", aggregate_address=[dict(prefix="192.0.2.0/24", summary_only=True)], networks=[ dict(prefix="192.1.13.0/24", route_map="map01"), ], ), dict( afi="ipv6", redistribute=[dict(protocol="ospfv3", metric=20)], ), ], neighbors=[ dict( neighbor_address="192.10.21.25", address_family=[ dict( afi="ipv6", distribute_list=[dict(action="export", acl=10)], route_server_client=True, ), ], ), dict( neighbor_address="203.0.113.5", address_family=[ dict( afi="ipv4", filter_list=[ dict(action="export", path_list="list01"), ], capability=dict(orf="send"), ), ], ), ], ), ), ) commands = [ "set protocols bgp 65536 address-family ipv4-unicast aggregate-address 192.0.2.0/24 as-setipv4-unicast aggregate-address 192.0.2.0/24 summary-only", "set protocols bgp 65536 address-family ipv6-unicast redistribute ospfv3 metric 20", "set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv4-unicast filter-list export list01", "set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv4-unicast capability prefix-list send", "set protocols bgp 65536 neighbor 192.10.21.25 address-family ipv6-unicast distribute-list export 10", "set protocols bgp 65536 neighbor 192.10.21.25 address-family ipv6-unicast route-server-client", ] self.execute_module(changed=True, commands=commands) def test_vyos_bgp_address_family_replaced_idempotent(self): set_module_args( dict( state="replaced", config=dict( as_number=65536, address_family=[ dict( afi="ipv4", aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], networks=[ dict(prefix="192.1.13.0/24", route_map="map01"), dict(prefix="192.2.13.0/24", backdoor=True), ], ), dict( afi="ipv6", redistribute=[dict(protocol="ripng", metric=20)], ), ], neighbors=[ dict( neighbor_address="192.0.2.25", address_family=[ dict( afi="ipv4", route_map=[dict(action="export", route_map="map01")], soft_reconfiguration=True, ), ], ), dict( neighbor_address="203.0.113.5", address_family=[ dict( afi="ipv6", attribute_unchanged=dict(next_hop=True), ), ], ), ], ), ), ) self.execute_module(changed=False, commands=[]) def test_vyos_bgp_address_family_replaced(self): set_module_args( dict( state="replaced", config=dict( as_number=65536, address_family=[ dict( afi="ipv4", aggregate_address=[dict(prefix="192.0.2.0/24", summary_only=True)], networks=[ dict(prefix="192.1.13.0/24", route_map="map01"), ], ), dict( afi="ipv6", redistribute=[dict(protocol="ospfv3", metric=20)], ), ], neighbors=[ dict( neighbor_address="192.10.21.25", address_family=[ dict( afi="ipv4", route_map=[dict(action="import", route_map="map01")], ), dict( afi="ipv6", distribute_list=[dict(action="export", acl=10)], route_server_client=True, ), ], ), dict( neighbor_address="192.0.2.25", address_family=[ dict( afi="ipv4", route_map=[dict(action="export", route_map="map01")], ), ], ), dict( neighbor_address="203.0.113.5", address_family=[ dict( afi="ipv4", filter_list=[ dict(action="export", path_list="list01"), ], capability=dict(orf="send"), ), ], ), ], ), ), ) commands = [ "delete protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged", "delete protocols bgp 65536 neighbor 192.0.2.25 address-family ipv4-unicast soft-reconfiguration", "delete protocols bgp 65536 address-family ipv6-unicast redistribute ripng", "delete protocols bgp 65536 address-family ipv4-unicast network 192.2.13.0/24", "set protocols bgp 65536 address-family ipv4-unicast aggregate-address 192.0.2.0/24 summary-only", "set protocols bgp 65536 address-family ipv6-unicast redistribute ospfv3 metric 20", "set protocols bgp 65536 neighbor 192.10.21.25 address-family ipv4-unicast route-map import map01", "set protocols bgp 65536 neighbor 192.10.21.25 address-family ipv6-unicast distribute-list export 10", "set protocols bgp 65536 neighbor 192.10.21.25 address-family ipv6-unicast route-server-client", "set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv4-unicast filter-list export list01", "set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv4-unicast capability prefix-list send", ] self.execute_module(changed=True, commands=commands) def test_vyos_bgp_address_family_overridden_idempotent(self): set_module_args( dict( state="overridden", config=dict( as_number=65536, address_family=[ dict( afi="ipv4", aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], networks=[ dict(prefix="192.1.13.0/24", route_map="map01"), dict(prefix="192.2.13.0/24", backdoor=True), ], ), dict( afi="ipv6", redistribute=[dict(protocol="ripng", metric=20)], ), ], neighbors=[ dict( neighbor_address="192.0.2.25", address_family=[ dict( afi="ipv4", route_map=[dict(action="export", route_map="map01")], soft_reconfiguration=True, ), ], ), dict( neighbor_address="203.0.113.5", address_family=[ dict( afi="ipv6", attribute_unchanged=dict(next_hop=True), ), ], ), ], ), ), ) self.execute_module(changed=False, commands=[]) def test_vyos_bgp_address_family_overridden(self): set_module_args( dict( state="overridden", config=dict( as_number=65536, address_family=[ dict( afi="ipv4", networks=[ dict(prefix="192.1.13.0/24", route_map="map01"), ], ), dict( afi="ipv6", redistribute=[dict(protocol="ospfv3", metric=20)], ), ], neighbors=[ dict( neighbor_address="192.10.21.25", address_family=[ dict( afi="ipv4", route_map=[dict(action="import", route_map="map01")], ), dict( afi="ipv6", distribute_list=[dict(action="export", acl=10)], route_server_client=True, ), ], ), ], ), ), ) commands = [ "delete protocols bgp 65536 neighbor 203.0.113.5 address-family", "delete protocols bgp 65536 neighbor 192.0.2.25 address-family", "delete protocols bgp 65536 address-family ipv6-unicast redistribute ripng", "delete protocols bgp 65536 address-family ipv4 aggregate-address", "delete protocols bgp 65536 address-family ipv4-unicast network 192.2.13.0/24", "set protocols bgp 65536 address-family ipv6-unicast redistribute ospfv3 metric 20", "set protocols bgp 65536 neighbor 192.10.21.25 address-family ipv4-unicast route-map import map01", "set protocols bgp 65536 neighbor 192.10.21.25 address-family ipv6-unicast distribute-list export 10", "set protocols bgp 65536 neighbor 192.10.21.25 address-family ipv6-unicast route-server-client", ] self.execute_module(changed=True, commands=commands) def test_vyos_bgp_address_family_deleted(self): set_module_args( dict( state="deleted", config=dict( as_number=65536, address_family=[ dict( afi="ipv4", ), ], neighbors=[ dict( neighbor_address="192.0.2.25", address_family=[ dict( afi="ipv4", ), ], ), dict( neighbor_address="203.0.113.5", ), ], ), ), ) commands = [ "delete protocols bgp 65536 address-family ipv4-unicast", "delete protocols bgp 65536 neighbor 192.0.2.25 address-family ipv4-unicast", "delete protocols bgp 65536 neighbor 203.0.113.5 address-family", ] self.execute_module(changed=True, commands=commands) def test_vyos_bgp_address_family_incorrect_instance(self): set_module_args( dict( state="overridden", config=dict( as_number=100, address_family=[ dict( afi="ipv4", networks=[ dict(prefix="192.1.13.0/24", route_map="map01"), ], ), dict( afi="ipv6", redistribute=[dict(protocol="ospfv3", metric=20)], ), ], neighbors=[ dict( neighbor_address="192.10.21.25", address_family=[ dict( afi="ipv4", route_map=[dict(action="import", route_map="map01")], ), dict( afi="ipv6", distribute_list=[dict(action="export", acl=10)], route_server_client=True, ), ], ), ], ), ), ) result = self.execute_module(failed=True) self.assertIn("Only one bgp instance is allowed per device", result["msg"]) def test_vyos_bgp_address_family_rendered(self): set_module_args( dict( state="rendered", config=dict( as_number=65536, address_family=[ dict( afi="ipv4", aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], networks=[ dict(prefix="192.1.13.0/24", route_map="map01"), dict(prefix="192.2.13.0/24", backdoor=True), ], ), dict( afi="ipv6", redistribute=[dict(protocol="ripng", metric=20)], ), ], neighbors=[ dict( neighbor_address="192.0.2.25", address_family=[ dict( afi="ipv4", route_map=[dict(action="export", route_map="map01")], soft_reconfiguration=True, ), ], ), dict( neighbor_address="203.0.113.5", address_family=[ dict( afi="ipv6", attribute_unchanged=dict(next_hop=True), ), ], ), ], ), ), ) rendered_cmds = [ "set protocols bgp 65536 address-family ipv4-unicast network 192.1.13.0/24 route-map map01", "set protocols bgp 65536 address-family ipv4-unicast network 192.2.13.0/24 backdoor", "set protocols bgp 65536 address-family ipv4-unicast aggregate-address 192.0.2.0/24 as-set", "set protocols bgp 65536 address-family ipv6-unicast redistribute ripng metric 20", "set protocols bgp 65536 neighbor 192.0.2.25 address-family ipv4-unicast route-map export map01", "set protocols bgp 65536 neighbor 192.0.2.25 address-family ipv4-unicast soft-reconfiguration inbound", "set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged next-hop", ] result = self.execute_module(changed=False) self.assertEqual( sorted(result["rendered"]), sorted(rendered_cmds), result["rendered"], ) def test_vyos_bgp_address_family_parsed(self): commands = [ "set protocols bgp 65536 address-family ipv4-unicast network 192.1.13.0/24 route-map map01", "set protocols bgp 65536 address-family ipv4-unicast network 192.2.13.0/24 backdoor", "set protocols bgp 65536 address-family ipv4-unicast aggregate-address 192.0.2.0/24 as-set", "set protocols bgp 65536 address-family ipv6-unicast redistribute ripng metric 20", "set protocols bgp 65536 neighbor 192.0.2.25 address-family ipv4-unicast route-map export map01", "set protocols bgp 65536 neighbor 192.0.2.25 address-family ipv4-unicast soft-reconfiguration inbound", "set protocols bgp 65536 neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged next-hop", ] parsed_str = "\n".join(commands) set_module_args(dict(running_config=parsed_str, state="parsed")) result = self.execute_module(changed=False) parsed_list = { "as_number": 65536, "address_family": [ { "afi": "ipv4", "networks": [ {"prefix": "192.1.13.0/24", "route_map": "map01"}, {"prefix": "192.2.13.0/24", "backdoor": True}, ], "aggregate_address": [{"prefix": "192.0.2.0/24", "as_set": True}], }, { "afi": "ipv6", "redistribute": [{"protocol": "ripng", "metric": 20}], }, ], "neighbors": [ { "neighbor_address": "192.0.2.25", "address_family": [ {"afi": "ipv4", "soft_reconfiguration": True}, ], }, { "neighbor_address": "203.0.113.5", "address_family": [ { "afi": "ipv6", "attribute_unchanged": {"next_hop": True}, }, ], }, ], } self.assertEqual(sorted(parsed_list), sorted(result["parsed"])) def test_vyos_bgp_address_family_gathered(self): set_module_args(dict(state="gathered")) result = self.execute_module(changed=False) gather_list = { "as_number": 65536, "address_family": [ { "afi": "ipv4", "networks": [ {"prefix": "192.1.13.0/24", "route_map": "map01"}, {"prefix": "192.2.13.0/24", "backdoor": True}, ], "aggregate_address": [{"prefix": "192.0.2.0/24", "as_set": True}], }, { "afi": "ipv6", "redistribute": [{"protocol": "ripng", "metric": 20}], }, ], "neighbors": [ { "neighbor_address": "192.0.2.25", "address_family": [ {"afi": "ipv4", "soft_reconfiguration": True}, ], }, { "neighbor_address": "203.0.113.5", "address_family": [ { "afi": "ipv6", "attribute_unchanged": {"next_hop": True}, }, ], }, ], } self.assertEqual(sorted(gather_list), sorted(result["gathered"])) + + +class TestVyosBgpafOpsModule13(TestVyosModule): + module = vyos_bgp_address_family + + def setUp(self): + super(TestVyosBgpafOpsModule13, self).setUp() + self.mock_get_resource_connection_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", + ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() + + self.mock_execute_show_command = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts." + + "bgp_address_family.bgp_address_family.Bgp_address_familyFacts.get_device_data", + ) + self.execute_show_command = self.mock_execute_show_command.start() + self.mock_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.bgp_address_family.bgp_address_family.get_os_version" + ) + self.test_version = "1.2" + self.get_os_version = self.mock_get_os_version.start() + self.get_os_version.return_value = self.test_version + self.mock_facts_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_address_family.bgp_address_family.get_os_version" + ) + self.get_facts_os_version = self.mock_facts_get_os_version.start() + self.get_facts_os_version.return_value = self.test_version + self.maxDiff = None + + def tearDown(self): + super(TestVyosBgpafOpsModule13, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_execute_show_command.stop() + self.mock_get_os_version.stop() + self.mock_facts_get_os_version.stop() + + def load_fixtures(self, commands=None, filename=None): + if filename is None: + filename = "vyos_bgp_af_ops_config.cfg" + + def load_from_file(*args, **kwargs): + output = load_fixture(filename) + return output + + self.execute_show_command.side_effect = load_from_file + + def test_vyos_bgp_address_family_merged(self): + set_module_args( + dict( + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + networks=[ + dict(prefix="192.3.13.0/24", backdoor=True), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ospfv3", metric=20)], + ), + ], + ), + ), + ) + commands = [ + "set protocols bgp 65536 address-family ipv4-unicast network 192.3.13.0/24 backdoor", + "set protocols bgp 65536 address-family ipv6-unicast redistribute ospfv3 metric 20", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_bgp_address_family_replaced(self): + set_module_args( + dict( + state="replaced", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + networks=[ + dict(prefix="192.1.13.0/24", backdoor=True), + ], + redistribute=[ + dict(protocol="ospf", metric=25), + ] + ), + dict( + afi="ipv6", + redistribute=[ + dict(protocol="ospfv3", metric=20), + dict(protocol="ripng") + ], + ), + ], + ), + ), + ) + commands = [ + "delete protocols bgp 65536 address-family ipv6-unicast redistribute ripng metric", + "delete protocols bgp 65536 address-family ipv4-unicast network 192.2.13.0/24", + "delete protocols bgp 65536 address-family ipv4-unicast redistribute rip", + "set protocols bgp 65536 address-family ipv4-unicast redistribute ospf metric 25", + "set protocols bgp 65536 address-family ipv4-unicast network 192.1.13.0/24 backdoor", + "set protocols bgp 65536 address-family ipv6-unicast redistribute ospfv3 metric 20", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_bgp_address_family_overridden(self): + set_module_args( + dict( + state="overridden", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + networks=[ + dict(prefix="192.1.13.0/24", backdoor=True), + ], + redistribute=[ + dict(protocol="ospf", metric=25), + ] + ), + dict( + afi="ipv6", + redistribute=[ + dict(protocol="ospfv3", metric=20), + dict(protocol="ripng") + ], + ), + ], + ), + ), + ) + commands = [ + "delete protocols bgp 65536 address-family ipv6-unicast redistribute ripng metric", + "delete protocols bgp 65536 address-family ipv4-unicast network 192.2.13.0/24", + "delete protocols bgp 65536 address-family ipv4-unicast redistribute rip", + "set protocols bgp 65536 address-family ipv4-unicast redistribute ospf metric 25", + "set protocols bgp 65536 address-family ipv4-unicast network 192.1.13.0/24 backdoor", + "set protocols bgp 65536 address-family ipv6-unicast redistribute ospfv3 metric 20", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_bgp_address_family_deleted(self): + set_module_args( + dict( + state="deleted", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + networks=[ + dict(prefix="192.2.13.0/24"), + ] + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ripng")], + ), + ], + ), + ), + ) + commands = [ + "delete protocols bgp 65536 address-family ipv4-unicast", + "delete protocols bgp 65536 address-family ipv6-unicast", + ] + + self.execute_module(changed=True, commands=commands) diff --git a/tests/unit/modules/network/vyos/test_vyos_bgp_address_family14.py b/tests/unit/modules/network/vyos/test_vyos_bgp_address_family14.py new file mode 100644 index 00000000..9e615ff0 --- /dev/null +++ b/tests/unit/modules/network/vyos/test_vyos_bgp_address_family14.py @@ -0,0 +1,1000 @@ +# (c) 2016 Red Hat Inc. +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +# Make coding more python3-ish +from __future__ import absolute_import, division, print_function + + +__metaclass__ = type + +from unittest.mock import patch + +from ansible_collections.vyos.vyos.plugins.modules import vyos_bgp_address_family +from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args + +from .vyos_module import TestVyosModule, load_fixture + + +class TestVyosBgpafModule14(TestVyosModule): + module = vyos_bgp_address_family + + def setUp(self): + super(TestVyosBgpafModule14, self).setUp() + self.mock_get_resource_connection_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", + ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() + + self.mock_execute_show_command = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts." + + "bgp_address_family.bgp_address_family.Bgp_address_familyFacts.get_device_data", + ) + self.execute_show_command = self.mock_execute_show_command.start() + self.mock_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.bgp_address_family.bgp_address_family.get_os_version" + ) + self.test_version = "1.4" + self.get_os_version = self.mock_get_os_version.start() + self.get_os_version.return_value = self.test_version + self.mock_facts_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_address_family.bgp_address_family.get_os_version" + ) + self.get_facts_os_version = self.mock_facts_get_os_version.start() + self.get_facts_os_version.return_value = self.test_version + self.maxDiff = None + + def tearDown(self): + super(TestVyosBgpafModule14, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_execute_show_command.stop() + self.mock_get_os_version.stop() + self.mock_facts_get_os_version.stop() + + def load_fixtures(self, commands=None, filename=None): + if filename is None: + filename = "vyos_bgp_address_family_config_14.cfg" + + def load_from_file(*args, **kwargs): + output = load_fixture(filename) + return output + + self.execute_show_command.side_effect = load_from_file + + def test_vyos_bgp_address_family_merged_idempotent(self): + set_module_args( + dict( + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], + networks=[ + dict(prefix="192.1.13.0/24", route_map="map01"), + dict(prefix="192.2.13.0/24", backdoor=True), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ripng", metric=20)], + ), + ], + neighbors=[ + dict( + neighbor_address="192.0.2.25", + address_family=[ + dict( + afi="ipv4", + route_map=[dict(action="export", route_map="map01")], + soft_reconfiguration=True, + ), + ], + ), + dict( + neighbor_address="203.0.113.5", + address_family=[ + dict( + afi="ipv6", + attribute_unchanged=dict(next_hop=True), + ), + ], + ), + ], + ), + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_vyos_bgp_address_family_merged(self): + set_module_args( + dict( + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + aggregate_address=[dict(prefix="192.0.2.0/24", summary_only=True)], + networks=[ + dict(prefix="192.1.13.0/24", route_map="map01"), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ospfv3", metric=20)], + ), + ], + neighbors=[ + dict( + neighbor_address="192.10.21.25", + address_family=[ + dict( + afi="ipv6", + distribute_list=[dict(action="export", acl=10)], + route_server_client=True, + ), + ], + ), + dict( + neighbor_address="203.0.113.5", + address_family=[ + dict( + afi="ipv4", + filter_list=[ + dict(action="export", path_list="list01"), + ], + capability=dict(orf="send"), + ), + ], + ), + ], + ), + ), + ) + commands = [ + "set protocols bgp address-family ipv4-unicast aggregate-address 192.0.2.0/24 as-setipv4-unicast aggregate-address 192.0.2.0/24 summary-only", + "set protocols bgp address-family ipv6-unicast redistribute ospfv3 metric 20", + "set protocols bgp neighbor 203.0.113.5 address-family ipv4-unicast filter-list export list01", + "set protocols bgp neighbor 203.0.113.5 address-family ipv4-unicast capability prefix-list send", + "set protocols bgp neighbor 192.10.21.25 address-family ipv6-unicast distribute-list export 10", + "set protocols bgp neighbor 192.10.21.25 address-family ipv6-unicast route-server-client", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_bgp_address_family_replaced_idempotent(self): + set_module_args( + dict( + state="replaced", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], + networks=[ + dict(prefix="192.1.13.0/24", route_map="map01"), + dict(prefix="192.2.13.0/24", backdoor=True), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ripng", metric=20)], + ), + ], + neighbors=[ + dict( + neighbor_address="192.0.2.25", + address_family=[ + dict( + afi="ipv4", + route_map=[dict(action="export", route_map="map01")], + soft_reconfiguration=True, + ), + ], + ), + dict( + neighbor_address="203.0.113.5", + address_family=[ + dict( + afi="ipv6", + attribute_unchanged=dict(next_hop=True), + ), + ], + ), + ], + ), + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_vyos_bgp_address_family_replaced(self): + set_module_args( + dict( + state="replaced", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + aggregate_address=[dict(prefix="192.0.2.0/24", summary_only=True)], + networks=[ + dict(prefix="192.1.13.0/24", route_map="map01"), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ospfv3", metric=20)], + ), + ], + neighbors=[ + dict( + neighbor_address="192.10.21.25", + address_family=[ + dict( + afi="ipv4", + route_map=[dict(action="import", route_map="map01")], + ), + dict( + afi="ipv6", + distribute_list=[dict(action="export", acl=10)], + route_server_client=True, + ), + ], + ), + dict( + neighbor_address="192.0.2.25", + address_family=[ + dict( + afi="ipv4", + route_map=[dict(action="export", route_map="map01")], + ), + ], + ), + dict( + neighbor_address="203.0.113.5", + address_family=[ + dict( + afi="ipv4", + filter_list=[ + dict(action="export", path_list="list01"), + ], + capability=dict(orf="send"), + ), + ], + ), + ], + ), + ), + ) + commands = [ + "delete protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged", + "delete protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast soft-reconfiguration", + "delete protocols bgp address-family ipv6-unicast redistribute ripng", + "delete protocols bgp address-family ipv4-unicast network 192.2.13.0/24", + "set protocols bgp address-family ipv4-unicast aggregate-address 192.0.2.0/24 summary-only", + "set protocols bgp address-family ipv6-unicast redistribute ospfv3 metric 20", + "set protocols bgp neighbor 192.10.21.25 address-family ipv4-unicast route-map import map01", + "set protocols bgp neighbor 192.10.21.25 address-family ipv6-unicast distribute-list export 10", + "set protocols bgp neighbor 192.10.21.25 address-family ipv6-unicast route-server-client", + "set protocols bgp neighbor 203.0.113.5 address-family ipv4-unicast filter-list export list01", + "set protocols bgp neighbor 203.0.113.5 address-family ipv4-unicast capability prefix-list send", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_bgp_address_family_overridden_idempotent(self): + set_module_args( + dict( + state="overridden", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], + networks=[ + dict(prefix="192.1.13.0/24", route_map="map01"), + dict(prefix="192.2.13.0/24", backdoor=True), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ripng", metric=20)], + ), + ], + neighbors=[ + dict( + neighbor_address="192.0.2.25", + address_family=[ + dict( + afi="ipv4", + route_map=[dict(action="export", route_map="map01")], + soft_reconfiguration=True, + ), + ], + ), + dict( + neighbor_address="203.0.113.5", + address_family=[ + dict( + afi="ipv6", + attribute_unchanged=dict(next_hop=True), + ), + ], + ), + ], + ), + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_vyos_bgp_address_family_overridden(self): + set_module_args( + dict( + state="overridden", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + networks=[ + dict(prefix="192.1.13.0/24", route_map="map01"), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ospfv3", metric=20)], + ), + ], + neighbors=[ + dict( + neighbor_address="192.10.21.25", + address_family=[ + dict( + afi="ipv4", + route_map=[dict(action="import", route_map="map01")], + ), + dict( + afi="ipv6", + distribute_list=[dict(action="export", acl=10)], + route_server_client=True, + ), + ], + ), + ], + ), + ), + ) + commands = [ + "delete protocols bgp neighbor 203.0.113.5 address-family", + "delete protocols bgp neighbor 192.0.2.25 address-family", + "delete protocols bgp address-family ipv6-unicast redistribute ripng", + "delete protocols bgp address-family ipv4 aggregate-address", + "delete protocols bgp address-family ipv4-unicast network 192.2.13.0/24", + "set protocols bgp address-family ipv6-unicast redistribute ospfv3 metric 20", + "set protocols bgp neighbor 192.10.21.25 address-family ipv4-unicast route-map import map01", + "set protocols bgp neighbor 192.10.21.25 address-family ipv6-unicast distribute-list export 10", + "set protocols bgp neighbor 192.10.21.25 address-family ipv6-unicast route-server-client", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_bgp_address_family_deleted(self): + set_module_args( + dict( + state="deleted", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + ), + ], + neighbors=[ + dict( + neighbor_address="192.0.2.25", + address_family=[ + dict( + afi="ipv4", + ), + ], + ), + dict( + neighbor_address="203.0.113.5", + ), + ], + ), + ), + ) + commands = [ + "delete protocols bgp address-family ipv4-unicast", + "delete protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast", + "delete protocols bgp neighbor 203.0.113.5 address-family", + ] + + self.execute_module(changed=True, commands=commands) + + # def test_vyos_bgp_address_family_incorrect_instance(self): + # set_module_args( + # dict( + # state="overridden", + # config=dict( + # as_number=100, + # address_family=[ + # dict( + # afi="ipv4", + # networks=[ + # dict(prefix="192.1.13.0/24", route_map="map01"), + # ], + # ), + # dict( + # afi="ipv6", + # redistribute=[dict(protocol="ospfv3", metric=20)], + # ), + # ], + # neighbors=[ + # dict( + # neighbor_address="192.10.21.25", + # address_family=[ + # dict( + # afi="ipv4", + # route_map=[dict(action="import", route_map="map01")], + # ), + # dict( + # afi="ipv6", + # distribute_list=[dict(action="export", acl=10)], + # route_server_client=True, + # ), + # ], + # ), + # ], + # ), + # ), + # ) + # result = self.execute_module(failed=True) + # self.assertIn("Only one bgp instance is allowed per device", result["msg"]) + + def test_vyos_bgp_address_family_rendered(self): + set_module_args( + dict( + state="rendered", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], + networks=[ + dict(prefix="192.1.13.0/24", route_map="map01"), + dict(prefix="192.2.13.0/24", backdoor=True), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ripng", metric=20)], + ), + ], + neighbors=[ + dict( + neighbor_address="192.0.2.25", + address_family=[ + dict( + afi="ipv4", + route_map=[dict(action="export", route_map="map01")], + soft_reconfiguration=True, + ), + ], + ), + dict( + neighbor_address="203.0.113.5", + address_family=[ + dict( + afi="ipv6", + attribute_unchanged=dict(next_hop=True), + ), + ], + ), + ], + ), + ), + ) + rendered_cmds = [ + "set protocols bgp system-as 65536", + "set protocols bgp address-family ipv4-unicast network 192.1.13.0/24 route-map map01", + "set protocols bgp address-family ipv4-unicast network 192.2.13.0/24 backdoor", + "set protocols bgp address-family ipv4-unicast aggregate-address 192.0.2.0/24 as-set", + "set protocols bgp address-family ipv6-unicast redistribute ripng metric 20", + "set protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast route-map export map01", + "set protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast soft-reconfiguration inbound", + "set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged next-hop", + ] + result = self.execute_module(changed=False) + self.assertEqual( + sorted(result["rendered"]), + sorted(rendered_cmds), + result["rendered"], + ) + + def test_vyos_bgp_address_family_parsed(self): + commands = [ + "set protocols bgp system-as 65536", + "set protocols bgp address-family ipv4-unicast network 192.1.13.0/24 route-map map01", + "set protocols bgp address-family ipv4-unicast network 192.2.13.0/24 backdoor", + "set protocols bgp address-family ipv4-unicast aggregate-address 192.0.2.0/24 as-set", + "set protocols bgp address-family ipv6-unicast redistribute ripng metric 20", + "set protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast route-map export map01", + "set protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast soft-reconfiguration inbound", + "set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged next-hop", + ] + + parsed_str = "\n".join(commands) + set_module_args(dict(running_config=parsed_str, state="parsed")) + result = self.execute_module(changed=False) + parsed_list = { + "as_number": 65536, + "address_family": [ + { + "afi": "ipv4", + "networks": [ + {"prefix": "192.1.13.0/24", "route_map": "map01"}, + {"prefix": "192.2.13.0/24", "backdoor": True}, + ], + "aggregate_address": [{"prefix": "192.0.2.0/24", "as_set": True}], + }, + { + "afi": "ipv6", + "redistribute": [{"protocol": "ripng", "metric": 20}], + }, + ], + "neighbors": [ + { + "neighbor_address": "192.0.2.25", + "address_family": [ + {"afi": "ipv4", "soft_reconfiguration": True}, + ], + }, + { + "neighbor_address": "203.0.113.5", + "address_family": [ + { + "afi": "ipv6", + "attribute_unchanged": {"next_hop": True}, + }, + ], + }, + ], + } + self.assertEqual(sorted(parsed_list), sorted(result["parsed"])) + + def test_vyos_bgp_address_family_gathered(self): + set_module_args(dict(state="gathered")) + result = self.execute_module(changed=False) + gather_list = { + "as_number": 65536, + "address_family": [ + { + "afi": "ipv4", + "networks": [ + {"prefix": "192.1.13.0/24", "route_map": "map01"}, + {"prefix": "192.2.13.0/24", "backdoor": True}, + ], + "aggregate_address": [{"prefix": "192.0.2.0/24", "as_set": True}], + }, + { + "afi": "ipv6", + "redistribute": [{"protocol": "ripng", "metric": 20}], + }, + ], + "neighbors": [ + { + "neighbor_address": "192.0.2.25", + "address_family": [ + {"afi": "ipv4", "soft_reconfiguration": True}, + ], + }, + { + "neighbor_address": "203.0.113.5", + "address_family": [ + { + "afi": "ipv6", + "attribute_unchanged": {"next_hop": True}, + }, + ], + }, + ], + } + self.assertEqual(sorted(gather_list), sorted(result["gathered"])) + + def test_vyos_bgp_address_family_replaced_asn(self): + set_module_args( + dict( + state="replaced", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], + networks=[ + dict(prefix="192.1.13.0/24", route_map="map01"), + dict(prefix="192.2.13.0/24", backdoor=True), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ripng", metric=20)], + ), + ], + neighbors=[ + dict( + neighbor_address="192.0.2.25", + address_family=[ + dict( + afi="ipv4", + route_map=[dict(action="export", route_map="map01")], + soft_reconfiguration=True, + ), + ], + ), + dict( + neighbor_address="203.0.113.5", + address_family=[ + dict( + afi="ipv6", + attribute_unchanged=dict(next_hop=True), + ), + ], + ), + ], + ), + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_vyos_bgp_address_family_overridden_asn(self): + set_module_args( + dict( + state="overridden", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], + networks=[ + dict(prefix="192.1.13.0/24", route_map="map01"), + dict(prefix="192.2.13.0/24", backdoor=True), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ripng", metric=20)], + ), + ], + neighbors=[ + dict( + neighbor_address="192.0.2.25", + address_family=[ + dict( + afi="ipv4", + route_map=[dict(action="export", route_map="map01")], + soft_reconfiguration=True, + ), + ], + ), + dict( + neighbor_address="203.0.113.5", + address_family=[ + dict( + afi="ipv6", + attribute_unchanged=dict(next_hop=True), + ), + ], + ), + ], + ), + ), + ) + self.execute_module(changed=False, commands=[]) + + def test_vyos_bgp_address_family_replaced_asn(self): + set_module_args( + dict( + state="replaced", + config=dict( + as_number=65540, + address_family=[ + dict( + afi="ipv4", + aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], + networks=[ + dict(prefix="192.1.13.0/24", route_map="map01"), + dict(prefix="192.2.13.0/24", backdoor=True), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ripng", metric=20)], + ), + ], + neighbors=[ + dict( + neighbor_address="192.0.2.25", + address_family=[ + dict( + afi="ipv4", + route_map=[dict(action="export", route_map="map01")], + soft_reconfiguration=True, + ), + ], + ), + dict( + neighbor_address="203.0.113.5", + address_family=[ + dict( + afi="ipv6", + attribute_unchanged=dict(next_hop=True), + ), + ], + ), + ], + ), + ), + ) + commands = [ + "set protocols bgp system-as 65540", + "set protocols bgp address-family ipv4-unicast aggregate-address 192.0.2.0/24 as-set", + "set protocols bgp address-family ipv4-unicast network 192.1.13.0/24 route-map map01", + "set protocols bgp address-family ipv4-unicast network 192.2.13.0/24 backdoor", + "set protocols bgp address-family ipv6-unicast redistribute ripng metric 20", + "set protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast route-map export map01", + "set protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast soft-reconfiguration inbound", + "set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged next-hop", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_bgp_address_family_overridden_asn(self): + set_module_args( + dict( + state="overridden", + config=dict( + as_number=65540, + address_family=[ + dict( + afi="ipv4", + aggregate_address=[dict(prefix="192.0.2.0/24", as_set=True)], + networks=[ + dict(prefix="192.1.13.0/24", route_map="map01"), + dict(prefix="192.2.13.0/24", backdoor=True), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ripng", metric=20)], + ), + ], + neighbors=[ + dict( + neighbor_address="192.0.2.25", + address_family=[ + dict( + afi="ipv4", + route_map=[dict(action="export", route_map="map01")], + soft_reconfiguration=True, + ), + ], + ), + dict( + neighbor_address="203.0.113.5", + address_family=[ + dict( + afi="ipv6", + attribute_unchanged=dict(next_hop=True), + ), + ], + ), + ], + ), + ), + ) + commands = [ + "delete protocols bgp address-family ipv4 aggregate-address", + "delete protocols bgp address-family ipv4 network", + "delete protocols bgp address-family ipv6 redistribute", + "delete protocols bgp neighbor 192.0.2.25 address-family", + "delete protocols bgp neighbor 203.0.113.5 address-family", + "set protocols bgp system-as 65540", + "set protocols bgp address-family ipv4-unicast aggregate-address 192.0.2.0/24 as-set", + "set protocols bgp address-family ipv4-unicast network 192.1.13.0/24 route-map map01", + "set protocols bgp address-family ipv4-unicast network 192.2.13.0/24 backdoor", + "set protocols bgp address-family ipv6-unicast redistribute ripng metric 20", + "set protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast route-map export map01", + "set protocols bgp neighbor 192.0.2.25 address-family ipv4-unicast soft-reconfiguration inbound", + "set protocols bgp neighbor 203.0.113.5 address-family ipv6-unicast attribute-unchanged next-hop", + ] + self.execute_module(changed=True, commands=commands) + + +class TestVyosBgpafOpsModule14(TestVyosModule): + module = vyos_bgp_address_family + + def setUp(self): + super(TestVyosBgpafOpsModule14, self).setUp() + self.mock_get_resource_connection_config = patch( + "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", + ) + self.get_resource_connection_config = self.mock_get_resource_connection_config.start() + + self.mock_execute_show_command = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts." + + "bgp_address_family.bgp_address_family.Bgp_address_familyFacts.get_device_data", + ) + self.execute_show_command = self.mock_execute_show_command.start() + self.mock_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.bgp_address_family.bgp_address_family.get_os_version" + ) + self.test_version = "1.4" + self.get_os_version = self.mock_get_os_version.start() + self.get_os_version.return_value = self.test_version + self.mock_facts_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_address_family.bgp_address_family.get_os_version" + ) + self.get_facts_os_version = self.mock_facts_get_os_version.start() + self.get_facts_os_version.return_value = self.test_version + self.maxDiff = None + + def tearDown(self): + super(TestVyosBgpafOpsModule14, self).tearDown() + self.mock_get_resource_connection_config.stop() + self.mock_execute_show_command.stop() + self.mock_get_os_version.stop() + self.mock_facts_get_os_version.stop() + + def load_fixtures(self, commands=None, filename=None): + if filename is None: + filename = "vyos_bgp_af_ops_config_14.cfg" + + def load_from_file(*args, **kwargs): + output = load_fixture(filename) + return output + + self.execute_show_command.side_effect = load_from_file + + def test_vyos_bgp_address_family_merged(self): + set_module_args( + dict( + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + networks=[ + dict(prefix="192.3.13.0/24", backdoor=True), + ], + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ospfv3", metric=20)], + ), + ], + ), + ), + ) + commands = [ + "set protocols bgp address-family ipv4-unicast network 192.3.13.0/24 backdoor", + "set protocols bgp address-family ipv6-unicast redistribute ospfv3 metric 20", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_bgp_address_family_replaced(self): + set_module_args( + dict( + state="replaced", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + networks=[ + dict(prefix="192.1.13.0/24", backdoor=True), + ], + redistribute=[ + dict(protocol="ospf", metric=25), + ] + ), + dict( + afi="ipv6", + redistribute=[ + dict(protocol="ospfv3", metric=20), + dict(protocol="ripng") + ], + ), + ], + ), + ), + ) + commands = [ + "delete protocols bgp address-family ipv6-unicast redistribute ripng metric", + "delete protocols bgp address-family ipv4-unicast network 192.2.13.0/24", + "delete protocols bgp address-family ipv4-unicast redistribute rip", + "set protocols bgp address-family ipv4-unicast redistribute ospf metric 25", + "set protocols bgp address-family ipv4-unicast network 192.1.13.0/24 backdoor", + "set protocols bgp address-family ipv6-unicast redistribute ospfv3 metric 20", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_bgp_address_family_overridden(self): + set_module_args( + dict( + state="overridden", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + networks=[ + dict(prefix="192.1.13.0/24", backdoor=True), + ], + redistribute=[ + dict(protocol="ospf", metric=25), + ] + ), + dict( + afi="ipv6", + redistribute=[ + dict(protocol="ospfv3", metric=20), + dict(protocol="ripng") + ], + ), + ], + ), + ), + ) + commands = [ + "delete protocols bgp address-family ipv6-unicast redistribute ripng metric", + "delete protocols bgp address-family ipv4-unicast network 192.2.13.0/24", + "delete protocols bgp address-family ipv4-unicast redistribute rip", + "set protocols bgp address-family ipv4-unicast redistribute ospf metric 25", + "set protocols bgp address-family ipv4-unicast network 192.1.13.0/24 backdoor", + "set protocols bgp address-family ipv6-unicast redistribute ospfv3 metric 20", + ] + self.execute_module(changed=True, commands=commands) + + def test_vyos_bgp_address_family_deleted(self): + set_module_args( + dict( + state="deleted", + config=dict( + as_number=65536, + address_family=[ + dict( + afi="ipv4", + networks=[ + dict(prefix="192.2.13.0/24"), + ] + ), + dict( + afi="ipv6", + redistribute=[dict(protocol="ripng")], + ), + ], + ), + ), + ) + commands = [ + "delete protocols bgp address-family ipv4-unicast", + "delete protocols bgp address-family ipv6-unicast", + ] + + self.execute_module(changed=True, commands=commands) diff --git a/tests/unit/modules/network/vyos/test_vyos_bgp_global.py b/tests/unit/modules/network/vyos/test_vyos_bgp_global.py index 99d17ce5..e363f77b 100644 --- a/tests/unit/modules/network/vyos/test_vyos_bgp_global.py +++ b/tests/unit/modules/network/vyos/test_vyos_bgp_global.py @@ -1,551 +1,488 @@ # (c) 2016 Red Hat Inc. # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . # Make coding more python3-ish from __future__ import absolute_import, division, print_function __metaclass__ = type from unittest.mock import patch from ansible_collections.vyos.vyos.plugins.modules import vyos_bgp_global from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args from .vyos_module import TestVyosModule, load_fixture class TestVyosBgpglobalModule(TestVyosModule): module = vyos_bgp_global def setUp(self): super(TestVyosBgpglobalModule, self).setUp() self.mock_get_resource_connection_config = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", ) self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_execute_show_command_config = patch( "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.bgp_global.bgp_global.Bgp_global._get_config", ) self.execute_show_command_config = self.mock_execute_show_command_config.start() self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection", ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_execute_show_command = patch( "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_global.bgp_global.Bgp_globalFacts.get_device_data", ) self.execute_show_command = self.mock_execute_show_command.start() + self.mock_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.bgp_global.bgp_global.get_os_version", + ) + self.test_version = "1.2" + self.get_os_version = self.mock_get_os_version.start() + self.get_os_version.return_value = self.test_version + self.mock_facts_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_global.bgp_global.get_os_version", + ) + self.get_facts_os_version = self.mock_facts_get_os_version.start() + self.get_facts_os_version.return_value = self.test_version + self.maxDiff = None def tearDown(self): super(TestVyosBgpglobalModule, self).tearDown() self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() self.mock_execute_show_command.stop() self.mock_execute_show_command_config.stop() + self.mock_get_os_version.stop() + self.mock_facts_get_os_version.stop() def load_fixtures(self, commands=None, filename=None): if filename is None: filename = "vyos_bgp_global_config.cfg" def load_from_file(*args, **kwargs): output = load_fixture(filename) return output self.execute_show_command.side_effect = load_from_file self.execute_show_command_config.side_effect = load_from_file def test_vyos_bgp_global_merged_idempotent(self): set_module_args( dict( config=dict( as_number="65536", neighbor=[ dict( address="10.0.0.4", disable_connected_check=True, timers=dict(holdtime=30, keepalive=10), - capability=dict(orf="receive"), ), dict( address="192.168.0.2", - attribute_unchanged=dict(as_path=True, med=True), ebgp_multihop=2, remote_as="65535", - soft_reconfiguration=True, update_source="192.168.0.1", ), dict( address="2001:db8::2", ebgp_multihop=2, remote_as="65535", - maximum_prefix=34, update_source="2001:db8::1", ), ], - network=[ - dict(address="172.16.42.32/27", backdoor=True), - dict(address="172.16.42.251/32", route_map="map01"), - ], + # network=[ + # dict(address="172.16.42.32/27", backdoor=True), + # dict(address="172.16.42.251/32", route_map="map01"), + # ], bgp_params=dict( bestpath=dict(as_path="confed", compare_routerid=True), default=dict(no_ipv4_unicast=True), router_id="10.1.1.1", ), - redistribute=[ - dict(protocol="kernel", route_map="map01"), - dict(protocol="static", metric=20), - dict(protocol="static", route_map="map01"), - ], + # redistribute=[ + # dict(protocol="kernel", route_map="map01"), + # dict(protocol="static", metric=20), + # dict(protocol="static", route_map="map01"), + # ], ), state="merged", ), ) self.execute_module(changed=False, commands=[]) def test_vyos_bgp_global_merged(self): set_module_args( dict( config=dict( as_number="65536", - maximum_paths=[ - dict(path="ebgp", count=20), - dict(path="ibgp", count=45), - ], neighbor=[ dict( address="2001:db8::2", ebgp_multihop=2, remote_as="65535", - maximum_prefix=34, update_source="2001:db8::1", - distribute_list=[ - dict(action="export", acl=31), - dict(action="import", acl=9), - ], ), ], bgp_params=dict( confederation=[dict(peers=20), dict(identifier=66)], router_id="10.1.1.1", ), ), state="merged", ), ) commands = [ - "set protocols bgp 65536 neighbor 2001:db8::2 distribute-list export 31", - "set protocols bgp 65536 neighbor 2001:db8::2 distribute-list import 9", "set protocols bgp 65536 parameters confederation peers 20", "set protocols bgp 65536 parameters confederation identifier 66", - "set protocols bgp 65536 maximum-paths ebgp 20", - "set protocols bgp 65536 maximum-paths ibgp 45", ] self.execute_module(changed=True, commands=commands) def test_vyos_bgp_global_replaced_idempotent(self): set_module_args( dict( config=dict( as_number="65536", neighbor=[ dict( address="10.0.0.4", disable_connected_check=True, timers=dict(holdtime=30, keepalive=10), - capability=dict(orf="receive"), ), dict( address="192.168.0.2", - attribute_unchanged=dict(as_path=True, med=True), ebgp_multihop=2, remote_as="65535", - soft_reconfiguration=True, update_source="192.168.0.1", ), dict( address="2001:db8::2", ebgp_multihop=2, remote_as="65535", - maximum_prefix=34, update_source="2001:db8::1", ), ], - network=[ - dict(address="172.16.42.32/27", backdoor=True), - dict(address="172.16.42.251/32", route_map="map01"), - ], + # network=[ + # dict(address="172.16.42.32/27", backdoor=True), + # dict(address="172.16.42.251/32", route_map="map01"), + # ], bgp_params=dict( bestpath=dict(as_path="confed", compare_routerid=True), default=dict(no_ipv4_unicast=True), router_id="10.1.1.1", ), - redistribute=[ - dict(protocol="kernel", route_map="map01"), - dict(protocol="static", metric=20), - dict(protocol="static", route_map="map01"), - ], + # redistribute=[ + # dict(protocol="kernel", route_map="map01"), + # dict(protocol="static", metric=20), + # dict(protocol="static", route_map="map01"), + # ], ), state="replaced", ), ) self.execute_module(changed=False, commands=[]) # def test_vyos_bgp_global_replaced(self): set_module_args( dict( config=dict( as_number="65536", timers=dict(holdtime=30, keepalive=10), neighbor=[ dict( address="200.11.155.3", - prefix_list=[ - dict(action="export", prefix_list=10), - ], - allowas_in=10, ), dict( address="2001:db8::2", remote_as="65535", - as_override=True, default_originate="map01", - route_map=[ - dict(action="export", route_map="map01"), - ], ), ], bgp_params=dict( log_neighbor_changes=True, no_client_to_client_reflection=True, confederation=[dict(peers=20), dict(identifier=66)], router_id="10.1.1.1", ), ), state="replaced", ), ) commands = [ "delete protocols bgp 65536 parameters default", "delete protocols bgp 65536 parameters bestpath compare-routerid", "delete protocols bgp 65536 parameters bestpath as-path confed", - "delete protocols bgp 65536 network", - "delete protocols bgp 65536 redistribute", + # "delete protocols bgp 65536 network", + # "delete protocols bgp 65536 redistribute", "delete protocols bgp 65536 neighbor 2001:db8::2 update-source 2001:db8::1", - "delete protocols bgp 65536 neighbor 2001:db8::2 maximum-prefix 34", "delete protocols bgp 65536 neighbor 2001:db8::2 ebgp-multihop 2", "delete protocols bgp 65536 neighbor 192.168.0.2", "delete protocols bgp 65536 neighbor 10.0.0.4", - "set protocols bgp 65536 neighbor 200.11.155.3 prefix-list export 10", - "set protocols bgp 65536 neighbor 200.11.155.3 allowas-in number 10", - "set protocols bgp 65536 neighbor 2001:db8::2 as-override", - "set protocols bgp 65536 neighbor 2001:db8::2 route-map export map01", "set protocols bgp 65536 parameters log-neighbor-changes", "set protocols bgp 65536 parameters no-client-to-client-reflection", "set protocols bgp 65536 parameters confederation peers 20", "set protocols bgp 65536 parameters confederation identifier 66", "set protocols bgp 65536 timers holdtime 30", "set protocols bgp 65536 timers keepalive 10", ] self.execute_module(changed=True, commands=commands) # def test_vyos_bgp_global_purged(self): set_module_args(dict(config=dict(as_number="65536"), state="purged")) # commands = ["delete protocols bgp 65536"] self.execute_module(changed=True, commands=commands) # def test_vyos_bgp_global_incorrect_instance(self): set_module_args( dict( config=dict( as_number="100", timers=dict(holdtime=30, keepalive=10), neighbor=[ dict( address="200.11.155.3", - prefix_list=[ - dict(action="export", prefix_list=10), - ], - allowas_in=10, ), dict( address="2001:db8::2", remote_as="65535", - as_override=True, default_originate="map01", - route_map=[ - dict(action="export", route_map="map01"), - ], ), ], bgp_params=dict( log_neighbor_changes=True, no_client_to_client_reflection=True, confederation=[dict(peers=20), dict(identifier=66)], router_id="10.1.1.1", ), ), state="replaced", ), ) result = self.execute_module(failed=True) self.assertIn("Only one bgp instance is allowed per device", result["msg"]) def test_vyos_bgp_global_replaced_af(self): set_module_args( dict( config=dict( as_number="65536", timers=dict(holdtime=30, keepalive=10), neighbor=[ dict( address="200.11.155.3", - prefix_list=[ - dict(action="export", prefix_list=10), - ], - allowas_in=10, ), dict( address="2001:db8::2", remote_as="65535", - as_override=True, default_originate="map01", - route_map=[ - dict(action="export", route_map="map01"), - ], ), ], bgp_params=dict( log_neighbor_changes=True, no_client_to_client_reflection=True, confederation=[dict(peers=20), dict(identifier=66)], router_id="10.1.1.1", ), ), state="replaced", ), ) result = self.execute_module(failed=True, filename="vyos_bgp_global_af_config.cfg") self.assertIn( "Use the _bgp_address_family module to delete the address_family under neighbor 5001::64, before replacing/deleting the neighbor.", result["msg"], ) def test_vyos_bgp_global_rendered(self): set_module_args( dict( config=dict( as_number="65536", neighbor=[ dict( address="10.0.0.4", disable_connected_check=True, timers=dict(holdtime=30, keepalive=10), - capability=dict(orf="receive"), ), dict( address="192.168.0.2", - attribute_unchanged=dict(as_path=True, med=True), ebgp_multihop=2, remote_as="65535", - soft_reconfiguration=True, update_source="192.168.0.1", ), dict( address="2001:db8::2", ebgp_multihop=2, remote_as="65535", - maximum_prefix=34, update_source="2001:db8::1", ), ], - network=[ - dict(address="172.16.42.32/27", backdoor=True), - dict(address="172.16.42.251/32", route_map="map01"), - ], + # network=[ + # dict(address="172.16.42.32/27", backdoor=True), + # dict(address="172.16.42.251/32", route_map="map01"), + # ], bgp_params=dict( bestpath=dict(as_path="confed", compare_routerid=True), default=dict(no_ipv4_unicast=True), router_id="10.1.1.1", ), - redistribute=[ - dict(protocol="kernel", route_map="map01"), - dict(protocol="static", metric=20), - dict(protocol="static", route_map="map01"), - ], + # redistribute=[ + # dict(protocol="kernel", route_map="map01"), + # dict(protocol="static", metric=20), + # dict(protocol="static", route_map="map01"), + # ], ), state="rendered", ), ) rendered_cmds = [ "set protocols bgp 65536 neighbor 10.0.0.4 disable-connected-check", "set protocols bgp 65536 neighbor 10.0.0.4 timers holdtime 30", "set protocols bgp 65536 neighbor 10.0.0.4 timers keepalive 10", - "set protocols bgp 65536 neighbor 10.0.0.4 capability orf prefix-list receive", - "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged as-path", - "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged med", - "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged next-hop", "set protocols bgp 65536 neighbor 192.168.0.2 ebgp-multihop 2", "set protocols bgp 65536 neighbor 192.168.0.2 remote-as 65535", - "set protocols bgp 65536 neighbor 192.168.0.2 soft-reconfiguration", "set protocols bgp 65536 neighbor 192.168.0.2 update-source 192.168.0.1", "set protocols bgp 65536 neighbor 2001:db8::2 ebgp-multihop 2", "set protocols bgp 65536 neighbor 2001:db8::2 remote-as 65535", - "set protocols bgp 65536 neighbor 2001:db8::2 maximum-prefix 34", "set protocols bgp 65536 neighbor 2001:db8::2 update-source 2001:db8::1", - "set protocols bgp 65536 redistribute kernel route-map map01", - "set protocols bgp 65536 redistribute static route-map map01", - "set protocols bgp 65536 network 172.16.42.32/27 backdoor", - "set protocols bgp 65536 network 172.16.42.251/32 route-map map01", + # "set protocols bgp 65536 redistribute kernel route-map map01", + # "set protocols bgp 65536 redistribute static route-map map01", + # "set protocols bgp 65536 network 172.16.42.32/27 backdoor", + # "set protocols bgp 65536 network 172.16.42.251/32 route-map map01", "set protocols bgp 65536 parameters bestpath as-path confed", "set protocols bgp 65536 parameters bestpath compare-routerid", "set protocols bgp 65536 parameters default no-ipv4-unicast", "set protocols bgp 65536 parameters router-id 10.1.1.1", ] result = self.execute_module(changed=False) self.assertEqual( sorted(result["rendered"]), sorted(rendered_cmds), result["rendered"], ) def test_vyos_bgp_global_parsed(self): commands = [ "set protocols bgp 65536 neighbor 10.0.0.4 disable-connected-check", "set protocols bgp 65536 neighbor 10.0.0.4 timers holdtime 30", "set protocols bgp 65536 neighbor 10.0.0.4 timers keepalive 10", - "set protocols bgp 65536 neighbor 10.0.0.4 capability orf prefix-list receive", - "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged as-path", - "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged med", - "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged next-hop", "set protocols bgp 65536 neighbor 192.168.0.2 ebgp-multihop 2", "set protocols bgp 65536 neighbor 192.168.0.2 remote-as 65535", - "set protocols bgp 65536 neighbor 192.168.0.2 soft-reconfiguration", "set protocols bgp 65536 neighbor 192.168.0.2 update-source 192.168.0.1", "set protocols bgp 65536 neighbor 2001:db8::2 ebgp-multihop 2", "set protocols bgp 65536 neighbor 2001:db8::2 remote-as 65535", - "set protocols bgp 65536 neighbor 2001:db8::2 maximum-prefix 34", "set protocols bgp 65536 neighbor 2001:db8::2 update-source 2001:db8::1", - "set protocols bgp 65536 redistribute kernel route-map map01", - "set protocols bgp 65536 redistribute static route-map map01", - "set protocols bgp 65536 network 172.16.42.32/27 backdoor", - "set protocols bgp 65536 network 172.16.42.251/32 route-map map01", + # "set protocols bgp 65536 redistribute kernel route-map map01", + # "set protocols bgp 65536 redistribute static route-map map01", + # "set protocols bgp 65536 network 172.16.42.32/27 backdoor", + # "set protocols bgp 65536 network 172.16.42.251/32 route-map map01", "set protocols bgp 65536 parameters bestpath as-path confed", "set protocols bgp 65536 parameters bestpath compare-routerid", "set protocols bgp 65536 parameters default no-ipv4-unicast", "set protocols bgp 65536 parameters router-id 10.1.1.1", ] parsed_str = "\n".join(commands) set_module_args(dict(running_config=parsed_str, state="parsed")) result = self.execute_module(changed=False) parsed_list = { "as_number": 65536, "bgp_params": { "bestpath": {"as_path": "confed", "compare_routerid": True}, "default": {"no_ipv4_unicast": True}, "router_id": "10.1.1.1", }, "neighbor": [ { "address": "10.0.0.4", - "capability": {"orf": "receive"}, "disable_connected_check": True, "timers": {"holdtime": 30, "keepalive": 10}, }, { "address": "192.168.0.2", - "attribute_unchanged": { - "as_path": True, - "med": True, - "next_hop": True, - }, "ebgp_multihop": 2, "remote_as": 65535, "update_source": "192.168.0.1", }, { "address": "2001:db8::2", "ebgp_multihop": 2, - "maximum_prefix": 34, "remote_as": 65535, "update_source": "2001:db8::1", }, ], - "network": [ - {"address": "172.16.42.32/27", "backdoor": True}, - {"address": "172.16.42.251/32", "route_map": "map01"}, - ], - "redistribute": [ - {"protocol": "kernel", "route_map": "map01"}, - {"protocol": "static", "route_map": "map01"}, - ], + # "network": [ + # {"address": "172.16.42.32/27", "backdoor": True}, + # {"address": "172.16.42.251/32", "route_map": "map01"}, + # ], + # "redistribute": [ + # {"protocol": "kernel", "route_map": "map01"}, + # {"protocol": "static", "route_map": "map01"}, + # ], } self.assertEqual(sorted(parsed_list), sorted(result["parsed"])) def test_vyos_bgp_global_gathered(self): set_module_args(dict(state="gathered")) result = self.execute_module(changed=False) gather_list = { "as_number": 65536, "bgp_params": { "bestpath": {"as_path": "confed", "compare_routerid": True}, "default": {"no_ipv4_unicast": True}, "router_id": "10.1.1.1", }, "neighbor": [ { "address": "10.0.0.4", - "capability": {"orf": "receive"}, "disable_connected_check": True, "timers": {"holdtime": 30, "keepalive": 10}, }, { "address": "192.168.0.2", - "attribute_unchanged": {"as_path": True, "med": True}, "ebgp_multihop": 2, "remote_as": 65535, - "soft_reconfiguration": True, "update_source": "192.168.0.1", }, { "address": "2001:db8::2", "ebgp_multihop": 2, - "maximum_prefix": 34, "remote_as": 65535, "update_source": "2001:db8::1", }, ], - "network": [ - {"address": "172.16.42.32/27", "backdoor": True}, - {"address": "172.16.42.251/32", "route_map": "map01"}, - ], - "redistribute": [ - {"protocol": "kernel", "route_map": "map01"}, - {"metric": 20, "protocol": "static"}, - {"protocol": "static", "route_map": "map01"}, - ], + # "network": [ + # {"address": "172.16.42.32/27", "backdoor": True}, + # {"address": "172.16.42.251/32", "route_map": "map01"}, + # ], + # "redistribute": [ + # {"protocol": "kernel", "route_map": "map01"}, + # {"metric": 20, "protocol": "static"}, + # {"protocol": "static", "route_map": "map01"}, + # ], } self.assertEqual(sorted(gather_list), sorted(result["gathered"])) diff --git a/tests/unit/modules/network/vyos/test_vyos_bgp_global.py b/tests/unit/modules/network/vyos/test_vyos_bgp_global14.py similarity index 52% copy from tests/unit/modules/network/vyos/test_vyos_bgp_global.py copy to tests/unit/modules/network/vyos/test_vyos_bgp_global14.py index 99d17ce5..ee647616 100644 --- a/tests/unit/modules/network/vyos/test_vyos_bgp_global.py +++ b/tests/unit/modules/network/vyos/test_vyos_bgp_global14.py @@ -1,551 +1,495 @@ # (c) 2016 Red Hat Inc. # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . # Make coding more python3-ish from __future__ import absolute_import, division, print_function __metaclass__ = type from unittest.mock import patch from ansible_collections.vyos.vyos.plugins.modules import vyos_bgp_global from ansible_collections.vyos.vyos.tests.unit.modules.utils import set_module_args from .vyos_module import TestVyosModule, load_fixture class TestVyosBgpglobalModule(TestVyosModule): module = vyos_bgp_global def setUp(self): super(TestVyosBgpglobalModule, self).setUp() self.mock_get_resource_connection_config = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.rm_base.resource_module_base.get_resource_connection", ) self.get_resource_connection_config = self.mock_get_resource_connection_config.start() self.mock_execute_show_command_config = patch( "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.bgp_global.bgp_global.Bgp_global._get_config", ) self.execute_show_command_config = self.mock_execute_show_command_config.start() self.mock_get_resource_connection_facts = patch( "ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts.get_resource_connection", ) self.get_resource_connection_facts = self.mock_get_resource_connection_facts.start() self.mock_execute_show_command = patch( "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_global.bgp_global.Bgp_globalFacts.get_device_data", ) self.execute_show_command = self.mock_execute_show_command.start() + self.mock_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.config.bgp_global.bgp_global.get_os_version", + ) + self.test_version = "1.4" + self.get_os_version = self.mock_get_os_version.start() + self.get_os_version.return_value = self.test_version + self.mock_facts_get_os_version = patch( + "ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.bgp_global.bgp_global.get_os_version", + ) + self.get_facts_os_version = self.mock_facts_get_os_version.start() + self.get_facts_os_version.return_value = self.test_version + self.maxDiff = None def tearDown(self): super(TestVyosBgpglobalModule, self).tearDown() self.mock_get_resource_connection_config.stop() self.mock_get_resource_connection_facts.stop() self.mock_execute_show_command.stop() self.mock_execute_show_command_config.stop() + self.mock_get_os_version.stop() + self.mock_facts_get_os_version.stop() def load_fixtures(self, commands=None, filename=None): if filename is None: - filename = "vyos_bgp_global_config.cfg" + filename = "vyos_bgp_global_config_14.cfg" def load_from_file(*args, **kwargs): output = load_fixture(filename) return output self.execute_show_command.side_effect = load_from_file self.execute_show_command_config.side_effect = load_from_file def test_vyos_bgp_global_merged_idempotent(self): set_module_args( dict( config=dict( as_number="65536", neighbor=[ dict( address="10.0.0.4", disable_connected_check=True, timers=dict(holdtime=30, keepalive=10), - capability=dict(orf="receive"), ), dict( address="192.168.0.2", - attribute_unchanged=dict(as_path=True, med=True), ebgp_multihop=2, remote_as="65535", - soft_reconfiguration=True, update_source="192.168.0.1", ), dict( address="2001:db8::2", ebgp_multihop=2, remote_as="65535", - maximum_prefix=34, update_source="2001:db8::1", ), ], - network=[ - dict(address="172.16.42.32/27", backdoor=True), - dict(address="172.16.42.251/32", route_map="map01"), - ], + # network=[ + # dict(address="172.16.42.32/27", backdoor=True), + # dict(address="172.16.42.251/32", route_map="map01"), + # ], bgp_params=dict( bestpath=dict(as_path="confed", compare_routerid=True), default=dict(no_ipv4_unicast=True), router_id="10.1.1.1", ), - redistribute=[ - dict(protocol="kernel", route_map="map01"), - dict(protocol="static", metric=20), - dict(protocol="static", route_map="map01"), - ], + # redistribute=[ + # dict(protocol="kernel", route_map="map01"), + # dict(protocol="static", metric=20), + # dict(protocol="static", route_map="map01"), + # ], ), state="merged", ), ) self.execute_module(changed=False, commands=[]) def test_vyos_bgp_global_merged(self): set_module_args( dict( config=dict( as_number="65536", - maximum_paths=[ - dict(path="ebgp", count=20), - dict(path="ibgp", count=45), - ], neighbor=[ dict( address="2001:db8::2", ebgp_multihop=2, remote_as="65535", - maximum_prefix=34, update_source="2001:db8::1", - distribute_list=[ - dict(action="export", acl=31), - dict(action="import", acl=9), - ], ), ], bgp_params=dict( confederation=[dict(peers=20), dict(identifier=66)], router_id="10.1.1.1", ), ), state="merged", ), ) commands = [ - "set protocols bgp 65536 neighbor 2001:db8::2 distribute-list export 31", - "set protocols bgp 65536 neighbor 2001:db8::2 distribute-list import 9", - "set protocols bgp 65536 parameters confederation peers 20", - "set protocols bgp 65536 parameters confederation identifier 66", - "set protocols bgp 65536 maximum-paths ebgp 20", - "set protocols bgp 65536 maximum-paths ibgp 45", + "set protocols bgp parameters confederation peers 20", + "set protocols bgp parameters confederation identifier 66", ] self.execute_module(changed=True, commands=commands) def test_vyos_bgp_global_replaced_idempotent(self): set_module_args( dict( config=dict( as_number="65536", neighbor=[ dict( address="10.0.0.4", disable_connected_check=True, timers=dict(holdtime=30, keepalive=10), - capability=dict(orf="receive"), ), dict( address="192.168.0.2", - attribute_unchanged=dict(as_path=True, med=True), ebgp_multihop=2, remote_as="65535", - soft_reconfiguration=True, update_source="192.168.0.1", ), dict( address="2001:db8::2", ebgp_multihop=2, remote_as="65535", - maximum_prefix=34, update_source="2001:db8::1", ), ], - network=[ - dict(address="172.16.42.32/27", backdoor=True), - dict(address="172.16.42.251/32", route_map="map01"), - ], + # network=[ + # dict(address="172.16.42.32/27", backdoor=True), + # dict(address="172.16.42.251/32", route_map="map01"), + # ], bgp_params=dict( bestpath=dict(as_path="confed", compare_routerid=True), default=dict(no_ipv4_unicast=True), router_id="10.1.1.1", ), - redistribute=[ - dict(protocol="kernel", route_map="map01"), - dict(protocol="static", metric=20), - dict(protocol="static", route_map="map01"), - ], + # redistribute=[ + # dict(protocol="kernel", route_map="map01"), + # dict(protocol="static", metric=20), + # dict(protocol="static", route_map="map01"), + # ], ), state="replaced", ), ) self.execute_module(changed=False, commands=[]) # def test_vyos_bgp_global_replaced(self): set_module_args( dict( config=dict( as_number="65536", timers=dict(holdtime=30, keepalive=10), neighbor=[ dict( address="200.11.155.3", - prefix_list=[ - dict(action="export", prefix_list=10), - ], - allowas_in=10, ), dict( address="2001:db8::2", remote_as="65535", - as_override=True, default_originate="map01", - route_map=[ - dict(action="export", route_map="map01"), - ], ), ], bgp_params=dict( log_neighbor_changes=True, no_client_to_client_reflection=True, confederation=[dict(peers=20), dict(identifier=66)], router_id="10.1.1.1", ), ), state="replaced", ), ) commands = [ - "delete protocols bgp 65536 parameters default", - "delete protocols bgp 65536 parameters bestpath compare-routerid", - "delete protocols bgp 65536 parameters bestpath as-path confed", - "delete protocols bgp 65536 network", - "delete protocols bgp 65536 redistribute", - "delete protocols bgp 65536 neighbor 2001:db8::2 update-source 2001:db8::1", - "delete protocols bgp 65536 neighbor 2001:db8::2 maximum-prefix 34", - "delete protocols bgp 65536 neighbor 2001:db8::2 ebgp-multihop 2", - "delete protocols bgp 65536 neighbor 192.168.0.2", - "delete protocols bgp 65536 neighbor 10.0.0.4", - "set protocols bgp 65536 neighbor 200.11.155.3 prefix-list export 10", - "set protocols bgp 65536 neighbor 200.11.155.3 allowas-in number 10", - "set protocols bgp 65536 neighbor 2001:db8::2 as-override", - "set protocols bgp 65536 neighbor 2001:db8::2 route-map export map01", - "set protocols bgp 65536 parameters log-neighbor-changes", - "set protocols bgp 65536 parameters no-client-to-client-reflection", - "set protocols bgp 65536 parameters confederation peers 20", - "set protocols bgp 65536 parameters confederation identifier 66", - "set protocols bgp 65536 timers holdtime 30", - "set protocols bgp 65536 timers keepalive 10", + "delete protocols bgp parameters default", + "delete protocols bgp parameters bestpath compare-routerid", + "delete protocols bgp parameters bestpath as-path confed", + # "delete protocols bgp network", + # "delete protocols bgp redistribute", + "delete protocols bgp neighbor 2001:db8::2 update-source 2001:db8::1", + "delete protocols bgp neighbor 2001:db8::2 ebgp-multihop 2", + "delete protocols bgp neighbor 192.168.0.2", + "delete protocols bgp neighbor 10.0.0.4", + "set protocols bgp parameters log-neighbor-changes", + "set protocols bgp parameters no-client-to-client-reflection", + "set protocols bgp parameters confederation peers 20", + "set protocols bgp parameters confederation identifier 66", + "set protocols bgp timers holdtime 30", + "set protocols bgp timers keepalive 10", ] self.execute_module(changed=True, commands=commands) # def test_vyos_bgp_global_purged(self): set_module_args(dict(config=dict(as_number="65536"), state="purged")) # - commands = ["delete protocols bgp 65536"] + commands = ["delete protocols bgp"] self.execute_module(changed=True, commands=commands) # - def test_vyos_bgp_global_incorrect_instance(self): - set_module_args( - dict( - config=dict( - as_number="100", - timers=dict(holdtime=30, keepalive=10), - neighbor=[ - dict( - address="200.11.155.3", - prefix_list=[ - dict(action="export", prefix_list=10), - ], - allowas_in=10, - ), - dict( - address="2001:db8::2", - remote_as="65535", - as_override=True, - default_originate="map01", - route_map=[ - dict(action="export", route_map="map01"), - ], - ), - ], - bgp_params=dict( - log_neighbor_changes=True, - no_client_to_client_reflection=True, - confederation=[dict(peers=20), dict(identifier=66)], - router_id="10.1.1.1", - ), - ), - state="replaced", - ), - ) - result = self.execute_module(failed=True) - self.assertIn("Only one bgp instance is allowed per device", result["msg"]) + # def test_vyos_bgp_global_incorrect_instance(self): + # set_module_args( + # dict( + # config=dict( + # as_number="100", + # timers=dict(holdtime=30, keepalive=10), + # neighbor=[ + # dict( + # address="200.11.155.3", + # allowas_in=10, + # ), + # dict( + # address="2001:db8::2", + # remote_as="65535", + # as_override=True, + # default_originate="map01", + # route_map=[ + # dict(action="export", route_map="map01"), + # ], + # ), + # ], + # bgp_params=dict( + # log_neighbor_changes=True, + # no_client_to_client_reflection=True, + # confederation=[dict(peers=20), dict(identifier=66)], + # router_id="10.1.1.1", + # ), + # ), + # state="replaced", + # ), + # ) + # result = self.execute_module(failed=True) + # self.assertIn("Only one bgp instance is allowed per device", result["msg"]) def test_vyos_bgp_global_replaced_af(self): set_module_args( dict( config=dict( as_number="65536", timers=dict(holdtime=30, keepalive=10), neighbor=[ dict( address="200.11.155.3", - prefix_list=[ - dict(action="export", prefix_list=10), - ], - allowas_in=10, ), dict( address="2001:db8::2", remote_as="65535", - as_override=True, default_originate="map01", - route_map=[ - dict(action="export", route_map="map01"), - ], ), ], bgp_params=dict( log_neighbor_changes=True, no_client_to_client_reflection=True, confederation=[dict(peers=20), dict(identifier=66)], router_id="10.1.1.1", ), ), state="replaced", ), ) - result = self.execute_module(failed=True, filename="vyos_bgp_global_af_config.cfg") + result = self.execute_module(failed=True, filename="vyos_bgp_global_af_config_14.cfg") self.assertIn( "Use the _bgp_address_family module to delete the address_family under neighbor 5001::64, before replacing/deleting the neighbor.", result["msg"], ) def test_vyos_bgp_global_rendered(self): set_module_args( dict( config=dict( as_number="65536", neighbor=[ dict( address="10.0.0.4", disable_connected_check=True, timers=dict(holdtime=30, keepalive=10), - capability=dict(orf="receive"), ), dict( address="192.168.0.2", - attribute_unchanged=dict(as_path=True, med=True), ebgp_multihop=2, remote_as="65535", - soft_reconfiguration=True, update_source="192.168.0.1", ), dict( address="2001:db8::2", ebgp_multihop=2, remote_as="65535", - maximum_prefix=34, update_source="2001:db8::1", ), ], - network=[ - dict(address="172.16.42.32/27", backdoor=True), - dict(address="172.16.42.251/32", route_map="map01"), - ], + # network=[ + # dict(address="172.16.42.32/27", backdoor=True), + # dict(address="172.16.42.251/32", route_map="map01"), + # ], bgp_params=dict( bestpath=dict(as_path="confed", compare_routerid=True), default=dict(no_ipv4_unicast=True), router_id="10.1.1.1", ), - redistribute=[ - dict(protocol="kernel", route_map="map01"), - dict(protocol="static", metric=20), - dict(protocol="static", route_map="map01"), - ], + # redistribute=[ + # dict(protocol="kernel", route_map="map01"), + # dict(protocol="static", metric=20), + # dict(protocol="static", route_map="map01"), + # ], ), state="rendered", ), ) rendered_cmds = [ - "set protocols bgp 65536 neighbor 10.0.0.4 disable-connected-check", - "set protocols bgp 65536 neighbor 10.0.0.4 timers holdtime 30", - "set protocols bgp 65536 neighbor 10.0.0.4 timers keepalive 10", - "set protocols bgp 65536 neighbor 10.0.0.4 capability orf prefix-list receive", - "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged as-path", - "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged med", - "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged next-hop", - "set protocols bgp 65536 neighbor 192.168.0.2 ebgp-multihop 2", - "set protocols bgp 65536 neighbor 192.168.0.2 remote-as 65535", - "set protocols bgp 65536 neighbor 192.168.0.2 soft-reconfiguration", - "set protocols bgp 65536 neighbor 192.168.0.2 update-source 192.168.0.1", - "set protocols bgp 65536 neighbor 2001:db8::2 ebgp-multihop 2", - "set protocols bgp 65536 neighbor 2001:db8::2 remote-as 65535", - "set protocols bgp 65536 neighbor 2001:db8::2 maximum-prefix 34", - "set protocols bgp 65536 neighbor 2001:db8::2 update-source 2001:db8::1", - "set protocols bgp 65536 redistribute kernel route-map map01", - "set protocols bgp 65536 redistribute static route-map map01", - "set protocols bgp 65536 network 172.16.42.32/27 backdoor", - "set protocols bgp 65536 network 172.16.42.251/32 route-map map01", - "set protocols bgp 65536 parameters bestpath as-path confed", - "set protocols bgp 65536 parameters bestpath compare-routerid", - "set protocols bgp 65536 parameters default no-ipv4-unicast", - "set protocols bgp 65536 parameters router-id 10.1.1.1", + "set protocols bgp system-as 65536", + "set protocols bgp neighbor 10.0.0.4 disable-connected-check", + "set protocols bgp neighbor 10.0.0.4 timers holdtime 30", + "set protocols bgp neighbor 10.0.0.4 timers keepalive 10", + "set protocols bgp neighbor 192.168.0.2 ebgp-multihop 2", + "set protocols bgp neighbor 192.168.0.2 remote-as 65535", + "set protocols bgp neighbor 192.168.0.2 update-source 192.168.0.1", + "set protocols bgp neighbor 2001:db8::2 ebgp-multihop 2", + "set protocols bgp neighbor 2001:db8::2 remote-as 65535", + "set protocols bgp neighbor 2001:db8::2 update-source 2001:db8::1", + # "set protocols bgp redistribute kernel route-map map01", + # "set protocols bgp redistribute static route-map map01", + # "set protocols bgp network 172.16.42.32/27 backdoor", + # "set protocols bgp network 172.16.42.251/32 route-map map01", + "set protocols bgp parameters bestpath as-path confed", + "set protocols bgp parameters bestpath compare-routerid", + "set protocols bgp parameters default no-ipv4-unicast", + "set protocols bgp parameters router-id 10.1.1.1", ] result = self.execute_module(changed=False) self.assertEqual( sorted(result["rendered"]), sorted(rendered_cmds), result["rendered"], ) def test_vyos_bgp_global_parsed(self): commands = [ - "set protocols bgp 65536 neighbor 10.0.0.4 disable-connected-check", - "set protocols bgp 65536 neighbor 10.0.0.4 timers holdtime 30", - "set protocols bgp 65536 neighbor 10.0.0.4 timers keepalive 10", - "set protocols bgp 65536 neighbor 10.0.0.4 capability orf prefix-list receive", - "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged as-path", - "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged med", - "set protocols bgp 65536 neighbor 192.168.0.2 attribute-unchanged next-hop", - "set protocols bgp 65536 neighbor 192.168.0.2 ebgp-multihop 2", - "set protocols bgp 65536 neighbor 192.168.0.2 remote-as 65535", - "set protocols bgp 65536 neighbor 192.168.0.2 soft-reconfiguration", - "set protocols bgp 65536 neighbor 192.168.0.2 update-source 192.168.0.1", - "set protocols bgp 65536 neighbor 2001:db8::2 ebgp-multihop 2", - "set protocols bgp 65536 neighbor 2001:db8::2 remote-as 65535", - "set protocols bgp 65536 neighbor 2001:db8::2 maximum-prefix 34", - "set protocols bgp 65536 neighbor 2001:db8::2 update-source 2001:db8::1", - "set protocols bgp 65536 redistribute kernel route-map map01", - "set protocols bgp 65536 redistribute static route-map map01", - "set protocols bgp 65536 network 172.16.42.32/27 backdoor", - "set protocols bgp 65536 network 172.16.42.251/32 route-map map01", - "set protocols bgp 65536 parameters bestpath as-path confed", - "set protocols bgp 65536 parameters bestpath compare-routerid", - "set protocols bgp 65536 parameters default no-ipv4-unicast", - "set protocols bgp 65536 parameters router-id 10.1.1.1", + "set protocols bgp system-as 65536", + "set protocols bgp neighbor 10.0.0.4 disable-connected-check", + "set protocols bgp neighbor 10.0.0.4 timers holdtime 30", + "set protocols bgp neighbor 10.0.0.4 timers keepalive 10", + "set protocols bgp neighbor 192.168.0.2 ebgp-multihop 2", + "set protocols bgp neighbor 192.168.0.2 remote-as 65535", + "set protocols bgp neighbor 192.168.0.2 update-source 192.168.0.1", + "set protocols bgp neighbor 2001:db8::2 ebgp-multihop 2", + "set protocols bgp neighbor 2001:db8::2 remote-as 65535", + "set protocols bgp neighbor 2001:db8::2 update-source 2001:db8::1", + # "set protocols bgp redistribute kernel route-map map01", + # "set protocols bgp redistribute static route-map map01", + # "set protocols bgp network 172.16.42.32/27 backdoor", + # "set protocols bgp network 172.16.42.251/32 route-map map01", + "set protocols bgp parameters bestpath as-path confed", + "set protocols bgp parameters bestpath compare-routerid", + "set protocols bgp parameters default no-ipv4-unicast", + "set protocols bgp parameters router-id 10.1.1.1", ] parsed_str = "\n".join(commands) set_module_args(dict(running_config=parsed_str, state="parsed")) result = self.execute_module(changed=False) parsed_list = { "as_number": 65536, "bgp_params": { "bestpath": {"as_path": "confed", "compare_routerid": True}, "default": {"no_ipv4_unicast": True}, "router_id": "10.1.1.1", }, "neighbor": [ { "address": "10.0.0.4", - "capability": {"orf": "receive"}, "disable_connected_check": True, "timers": {"holdtime": 30, "keepalive": 10}, }, { "address": "192.168.0.2", - "attribute_unchanged": { - "as_path": True, - "med": True, - "next_hop": True, - }, "ebgp_multihop": 2, "remote_as": 65535, "update_source": "192.168.0.1", }, { "address": "2001:db8::2", "ebgp_multihop": 2, - "maximum_prefix": 34, "remote_as": 65535, "update_source": "2001:db8::1", }, ], - "network": [ - {"address": "172.16.42.32/27", "backdoor": True}, - {"address": "172.16.42.251/32", "route_map": "map01"}, - ], - "redistribute": [ - {"protocol": "kernel", "route_map": "map01"}, - {"protocol": "static", "route_map": "map01"}, - ], + # "network": [ + # {"address": "172.16.42.32/27", "backdoor": True}, + # {"address": "172.16.42.251/32", "route_map": "map01"}, + # ], + # "redistribute": [ + # {"protocol": "kernel", "route_map": "map01"}, + # {"protocol": "static", "route_map": "map01"}, + # ], } self.assertEqual(sorted(parsed_list), sorted(result["parsed"])) def test_vyos_bgp_global_gathered(self): set_module_args(dict(state="gathered")) result = self.execute_module(changed=False) gather_list = { "as_number": 65536, "bgp_params": { "bestpath": {"as_path": "confed", "compare_routerid": True}, "default": {"no_ipv4_unicast": True}, "router_id": "10.1.1.1", }, "neighbor": [ { "address": "10.0.0.4", - "capability": {"orf": "receive"}, "disable_connected_check": True, "timers": {"holdtime": 30, "keepalive": 10}, }, { "address": "192.168.0.2", - "attribute_unchanged": {"as_path": True, "med": True}, "ebgp_multihop": 2, "remote_as": 65535, - "soft_reconfiguration": True, "update_source": "192.168.0.1", }, { "address": "2001:db8::2", "ebgp_multihop": 2, - "maximum_prefix": 34, "remote_as": 65535, "update_source": "2001:db8::1", }, ], - "network": [ - {"address": "172.16.42.32/27", "backdoor": True}, - {"address": "172.16.42.251/32", "route_map": "map01"}, - ], - "redistribute": [ - {"protocol": "kernel", "route_map": "map01"}, - {"metric": 20, "protocol": "static"}, - {"protocol": "static", "route_map": "map01"}, - ], + # "network": [ + # {"address": "172.16.42.32/27", "backdoor": True}, + # {"address": "172.16.42.251/32", "route_map": "map01"}, + # ], + # "redistribute": [ + # {"protocol": "kernel", "route_map": "map01"}, + # {"metric": 20, "protocol": "static"}, + # {"protocol": "static", "route_map": "map01"}, + # ], } self.assertEqual(sorted(gather_list), sorted(result["gathered"]))