Class: Rbeapi::Api::Bgp
Overview
The Bgp class implements global BGP router configuration.
Instance Attribute Summary collapse
-
#neighbors ⇒ Object
readonly
Returns the value of attribute neighbors.
Attributes inherited from Entity
Class Method Summary collapse
-
.parse_bgp_as(config) ⇒ Hash<Symbol, Object>
parse_bgp_as scans the BGP routing configuration for the AS number.
Instance Method Summary collapse
-
#add_network(prefix, masklen, route_map = nil) ⇒ Boolean
add_network creates a new instance of a BGP network on the node.
-
#create(bgp_as, opts = {}) ⇒ Boolean
create will create a new instance of BGP routing on the node.
-
#default ⇒ Boolean
default will configure the BGP routing using the default keyword.
-
#delete ⇒ Boolean
delete will delete the BGP routing instance from the node.
-
#get ⇒ nil, Hash<Symbol, Object>
get returns the BGP routing configuration from the nodes current configuration.
-
#initialize(node) ⇒ Bgp
constructor
A new instance of Bgp.
-
#remove_network(prefix, masklen, route_map = nil) ⇒ Boolean
remove_network removes the instance of a BGP network on the node.
-
#set_maximum_paths(maximum_paths, maximum_ecmp_paths, opts = {}) ⇒ Boolean
set_maximum_paths sets the maximum number of equal cost paths and the maximum number of installed ECMP routes.
-
#set_router_id(opts = {}) ⇒ Boolean
set_router_id sets the router_id for the BGP routing instance.
-
#set_shutdown(opts = {}) ⇒ Boolean
set_shutdown configures the administrative state for the global BGP routing process.
Methods inherited from Entity
#command_builder, #configure, #configure_interface, #get_block, instance
Constructor Details
#initialize(node) ⇒ Bgp
Returns a new instance of Bgp.
45 46 47 48 |
# File 'lib/rbeapi/api/bgp.rb', line 45 def initialize(node) super(node) @neighbors = BgpNeighbors.new(node) end |
Instance Attribute Details
#neighbors ⇒ Object (readonly)
Returns the value of attribute neighbors.
43 44 45 |
# File 'lib/rbeapi/api/bgp.rb', line 43 def neighbors @neighbors end |
Class Method Details
.parse_bgp_as(config) ⇒ Hash<Symbol, Object>
parse_bgp_as scans the BGP routing configuration for the AS number. Defined as a class method. Used by the BgpNeighbors class below.
121 122 123 124 |
# File 'lib/rbeapi/api/bgp.rb', line 121 def self.parse_bgp_as(config) value = config.scan(/^router bgp (\d+)/).first { bgp_as: value[0] } end |
Instance Method Details
#add_network(prefix, masklen, route_map = nil) ⇒ Boolean
add_network creates a new instance of a BGP network on the node.
Commands
router bgp <bgp_as>
network <prefix>/<masklen>
route-map <route_map>
409 410 411 412 413 |
# File 'lib/rbeapi/api/bgp.rb', line 409 def add_network(prefix, masklen, route_map = nil) cmd = "network #{prefix}/#{masklen}" cmd << " route-map #{route_map}" if route_map configure_bgp(cmd) end |
#create(bgp_as, opts = {}) ⇒ Boolean
create will create a new instance of BGP routing on the node. Optional parameters can be passed in to initialize BGP specific settings.
Commands
router bgp <bgp_as>
paths.
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/rbeapi/api/bgp.rb', line 227 def create(bgp_as, opts = {}) if opts[:maximum_ecmp_paths] && !opts[:maximum_paths] = 'maximum_paths must be set if maximum_ecmp_paths is set' raise ArgumentError, end cmds = ["router bgp #{bgp_as}"] if opts.key?(:enable) cmds << (opts[:enable] == true ? 'no shutdown' : 'shutdown') end cmds << "router-id #{opts[:router_id]}" if opts.key?(:router_id) if opts.key?(:maximum_paths) cmd = "maximum-paths #{opts[:maximum_paths]}" if opts.key?(:maximum_ecmp_paths) cmd << " ecmp #{opts[:maximum_ecmp_paths]}" end cmds << cmd end configure(cmds) end |
#default ⇒ Boolean
default will configure the BGP routing using the default keyword. This command has the same effect as deleting the BGP routine instance from the nodes running configuration.
Commands
default router bgp <bgp_as>
269 270 271 272 273 |
# File 'lib/rbeapi/api/bgp.rb', line 269 def default config = get return true unless config configure("default router bgp #{config[:bgp_as]}") end |
#delete ⇒ Boolean
delete will delete the BGP routing instance from the node.
Commands
no router bgp <bgp_as>
254 255 256 257 258 |
# File 'lib/rbeapi/api/bgp.rb', line 254 def delete config = get return true unless config configure("no router bgp #{config[:bgp_as]}") end |
#get ⇒ nil, Hash<Symbol, Object>
get returns the BGP routing configuration from the nodes current configuration.
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rbeapi/api/bgp.rb', line 100 def get config = get_block('^router bgp .*') return nil unless config response = Bgp.parse_bgp_as(config) response.merge!(parse_router_id(config)) response.merge!(parse_shutdown(config)) response.merge!(parse_maximum_paths(config)) response.merge!(parse_networks(config)) response[:neighbors] = @neighbors.getall response end |
#remove_network(prefix, masklen, route_map = nil) ⇒ Boolean
remove_network removes the instance of a BGP network on the node.
Commands
router bgp <bgp_as>
{no} shutdown
432 433 434 435 436 |
# File 'lib/rbeapi/api/bgp.rb', line 432 def remove_network(prefix, masklen, route_map = nil) cmd = "no network #{prefix}/#{masklen}" cmd << " route-map #{route_map}" if route_map configure_bgp(cmd) end |
#set_maximum_paths(maximum_paths, maximum_ecmp_paths, opts = {}) ⇒ Boolean
set_maximum_paths sets the maximum number of equal cost paths and the maximum number of installed ECMP routes.
Commands
router bgp <bgp_as>
{no | default}
maximum-paths <maximum_paths> [ecmp <maximum_ecmp_paths>]
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
# File 'lib/rbeapi/api/bgp.rb', line 374 def set_maximum_paths(maximum_paths, maximum_ecmp_paths, opts = {}) enable = opts.fetch(:enable, true) default = opts[:default] || false case default when true cmd = 'default maximum-paths' when false if enable cmd = "maximum-paths #{maximum_paths} ecmp #{maximum_ecmp_paths}" else cmd = 'no maximum-paths' end end configure_bgp(cmd) end |
#set_router_id(opts = {}) ⇒ Boolean
set_router_id sets the router_id for the BGP routing instance.
Commands
router bgp <bgp_as>
{no | default} router-id <router_id>
320 321 322 |
# File 'lib/rbeapi/api/bgp.rb', line 320 def set_router_id(opts = {}) configure_bgp(command_builder('router-id', opts)) end |
#set_shutdown(opts = {}) ⇒ Boolean
set_shutdown configures the administrative state for the global BGP routing process. The value option is not used by this method.
Commands
router bgp <bgp_as>
{no | default} shutdown
343 344 345 346 347 348 349 |
# File 'lib/rbeapi/api/bgp.rb', line 343 def set_shutdown(opts = {}) raise 'set_shutdown has the value option set' if opts[:value] # Shutdown semantics are opposite of enable semantics so invert enable value = !opts[:enable] opts[:enable] = value configure_bgp(command_builder('shutdown', opts)) end |