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.
526 527 528 |
# File 'lib/rbeapi/api/bgp.rb', line 526 def create(name) set_shutdown(name, enable: false) end |
#delete(name) ⇒ Boolean
delete will delete the BGP neighbor from the node.
543 544 545 546 547 548 549 550 551 |
# File 'lib/rbeapi/api/bgp.rb', line 543 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.
310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/rbeapi/api/bgp.rb', line 310 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.
334 335 336 337 338 339 340 341 342 343 |
# File 'lib/rbeapi/api/bgp.rb', line 334 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
569 570 571 |
# File 'lib/rbeapi/api/bgp.rb', line 569 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.
765 766 767 |
# File 'lib/rbeapi/api/bgp.rb', line 765 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.
690 691 692 693 |
# File 'lib/rbeapi/api/bgp.rb', line 690 def set_next_hop_self(name, opts = {}) fail '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.
592 593 594 |
# File 'lib/rbeapi/api/bgp.rb', line 592 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).
616 617 618 |
# File 'lib/rbeapi/api/bgp.rb', line 616 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.
715 716 717 718 |
# File 'lib/rbeapi/api/bgp.rb', line 715 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.
740 741 742 743 |
# File 'lib/rbeapi/api/bgp.rb', line 740 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.
665 666 667 668 |
# File 'lib/rbeapi/api/bgp.rb', line 665 def set_send_community(name, opts = {}) fail '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.
638 639 640 641 642 643 644 |
# File 'lib/rbeapi/api/bgp.rb', line 638 def set_shutdown(name, opts = {}) fail 'set_shutdown has value option set' if opts[:value] # Shutdown semantics are opposite of enable semantics so invert enable value = !opts[:enable] opts.merge!(enable: value) configure_bgp(neigh_command_builder(name, 'shutdown', opts)) end |