Class: Rbeapi::Api::BgpNeighbors
Overview
The BgpNeighbors class implements BGP neighbor configuration
Instance Attribute Summary
Attributes inherited from Entity
Instance Method Summary collapse
-
#create(name) ⇒ Boolean
create will create a new instance of a BGP neighbor on the node.
-
#delete(name) ⇒ Boolean
delete will delete the BGP neighbor from the node.
-
#get(name) ⇒ nil, Hash<Symbol, Object>
get returns a single BGP neighbor entry from the nodes current configuration.
-
#getall ⇒ nil, Hash<Symbol, Object>
getall returns the collection of all neighbor entries for the BGP router instance.
-
#neigh_command_builder(name, cmd, opts) ⇒ String
neigh_command_builder for neighbors which calls command_builder.
-
#set_description(name, opts = {}) ⇒ Boolean
set_description associates descriptive text with the specified peer or peer group.
-
#set_next_hop_self(name, opts = {}) ⇒ Boolean
set_next_hop_self configures the switch to list its address as the next hop in routes that it advertises to the specified BGP-speaking neighbor or neighbors in the specified peer group.
-
#set_peer_group(name, opts = {}) ⇒ Boolean
set_peer_group creates a BGP static peer group name.
-
#set_remote_as(name, opts = {}) ⇒ Boolean
set_remote_as configures the expected AS number for a neighbor (peer).
-
#set_route_map_in(name, opts = {}) ⇒ Boolean
set_route_map_in command applies a route map to inbound BGP routes.
-
#set_route_map_out(name, opts = {}) ⇒ Boolean
set_route_map_out command applies a route map to outbound BGP routes.
-
#set_send_community(name, opts = {}) ⇒ Boolean
set_send_community configures the switch to send community attributes to the specified BGP neighbor.
-
#set_shutdown(name, opts = {}) ⇒ Boolean
set_shutdown disables the specified neighbor.
Methods inherited from Entity
#command_builder, #configure, #configure_interface, #get_block, #initialize, instance
Constructor Details
This class inherits a constructor from Rbeapi::Api::Entity
Instance Method Details
#create(name) ⇒ Boolean
create will create a new instance of a BGP neighbor on the node. The neighbor is created in the shutdown state and then enabled.
716 717 718 |
# File 'lib/rbeapi/api/bgp.rb', line 716 def create(name) set_shutdown(name, enable: false) end |
#delete(name) ⇒ Boolean
delete will delete the BGP neighbor from the node.
Commands
no neighbor <name>
or
no neighbor <name> peer-group
733 734 735 736 737 738 739 740 741 |
# File 'lib/rbeapi/api/bgp.rb', line 733 def delete(name) cmd = "no neighbor #{name}" response = configure_bgp(cmd) unless response cmd = "no neighbor #{name} peer-group" response = configure_bgp(cmd) end response end |
#get(name) ⇒ nil, Hash<Symbol, Object>
get returns a single BGP neighbor entry from the nodes current configuration.
464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
# File 'lib/rbeapi/api/bgp.rb', line 464 def get(name) config = get_block('^router bgp .*') return nil unless config response = parse_peer_group(config, name) response.merge!(parse_remote_as(config, name)) response.merge!(parse_send_community(config, name)) response.merge!(parse_shutdown(config, name)) response.merge!(parse_description(config, name)) response.merge!(parse_next_hop_self(config, name)) response.merge!(parse_route_map_in(config, name)) response.merge!(parse_route_map_out(config, name)) response end |
#getall ⇒ nil, Hash<Symbol, Object>
getall returns the collection of all neighbor entries for the BGP router instance.
513 514 515 516 517 518 519 520 521 522 |
# File 'lib/rbeapi/api/bgp.rb', line 513 def getall config = get_block('^router bgp .*') return nil unless config entries = config.scan(/neighbor ([^\s]+)/) entries.uniq.each_with_object({}) do |name, hsh| resource = get(name[0]) hsh[name[0]] = resource if resource end end |
#neigh_command_builder(name, cmd, opts) ⇒ String
neigh_command_builder for neighbors which calls command_builder.
761 762 763 |
# File 'lib/rbeapi/api/bgp.rb', line 761 def neigh_command_builder(name, cmd, opts) command_builder("neighbor #{name} #{cmd}", opts) end |
#set_description(name, opts = {}) ⇒ Boolean
set_description associates descriptive text with the specified peer or peer group.
Commands
router bgp <bgp_as>
{no | default} neighbor <name> description <string>
965 966 967 |
# File 'lib/rbeapi/api/bgp.rb', line 965 def set_description(name, opts = {}) configure_bgp(neigh_command_builder(name, 'description', opts)) end |
#set_next_hop_self(name, opts = {}) ⇒ Boolean
set_next_hop_self configures the switch to list its address as the next hop in routes that it advertises to the specified BGP-speaking neighbor or neighbors in the specified peer group. The value option is not used by this method.
Commands
router bgp <bgp_as>
{no | default} neighbor <name> next-hop-self
887 888 889 890 |
# File 'lib/rbeapi/api/bgp.rb', line 887 def set_next_hop_self(name, opts = {}) raise 'set_next_hop_self has the value option set' if opts[:value] configure_bgp(neigh_command_builder(name, 'next-hop-self', opts)) end |
#set_peer_group(name, opts = {}) ⇒ Boolean
set_peer_group creates a BGP static peer group name.
Commands
router bgp <bgp_as>
{no | default} neighbor <name> peer-group <group-name>
785 786 787 |
# File 'lib/rbeapi/api/bgp.rb', line 785 def set_peer_group(name, opts = {}) configure_bgp(neigh_command_builder(name, 'peer-group', opts)) end |
#set_remote_as(name, opts = {}) ⇒ Boolean
set_remote_as configures the expected AS number for a neighbor (peer).
Commands
router bgp <bgp_as>
{no | default} neighbor <name> remote-as <as-id>
810 811 812 |
# File 'lib/rbeapi/api/bgp.rb', line 810 def set_remote_as(name, opts = {}) configure_bgp(neigh_command_builder(name, 'remote-as', opts)) end |
#set_route_map_in(name, opts = {}) ⇒ Boolean
set_route_map_in command applies a route map to inbound BGP routes.
Commands
router bgp <bgp_as>
{no | default} neighbor <name> route-map <name> in
913 914 915 916 |
# File 'lib/rbeapi/api/bgp.rb', line 913 def set_route_map_in(name, opts = {}) cmd = neigh_command_builder(name, 'route-map', opts) + ' in' configure_bgp(cmd) end |
#set_route_map_out(name, opts = {}) ⇒ Boolean
set_route_map_out command applies a route map to outbound BGP routes.
Commands
router bgp <bgp_as>
{no | default} neighbor <name> route-map <name> out
939 940 941 942 |
# File 'lib/rbeapi/api/bgp.rb', line 939 def set_route_map_out(name, opts = {}) cmd = neigh_command_builder(name, 'route-map', opts) + ' out' configure_bgp(cmd) end |
#set_send_community(name, opts = {}) ⇒ Boolean
set_send_community configures the switch to send community attributes to the specified BGP neighbor. The value option is not used by this method.
Commands
router bgp <bgp_as>
{no | default} neighbor <name> send-community
861 862 863 864 |
# File 'lib/rbeapi/api/bgp.rb', line 861 def set_send_community(name, opts = {}) raise 'send_community has the value option set' if opts[:value] configure_bgp(neigh_command_builder(name, 'send-community', opts)) end |
#set_shutdown(name, opts = {}) ⇒ Boolean
set_shutdown disables the specified neighbor. The value option is not used by this method.
Commands
router bgp <bgp_as>
{no | default} neighbor <name> shutdown
833 834 835 836 837 838 839 |
# File 'lib/rbeapi/api/bgp.rb', line 833 def set_shutdown(name, opts = {}) raise 'set_shutdown has value option set' if opts[:value] # Shutdown semantics are opposite of enable semantics so invert enable. value = !opts[:enable] opts[:enable] = value configure_bgp(neigh_command_builder(name, 'shutdown', opts)) end |