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) ⇒ 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_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.
76 77 78 79 |
# File 'lib/rbeapi/api/bgp.rb', line 76 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.
269 270 271 272 273 |
# File 'lib/rbeapi/api/bgp.rb', line 269 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) ⇒ Boolean
create will create a new instance of BGP routing on the node.
144 145 146 147 |
# File 'lib/rbeapi/api/bgp.rb', line 144 def create(bgp_as) value = bgp_as configure("router bgp #{value}") 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.
171 172 173 174 175 |
# File 'lib/rbeapi/api/bgp.rb', line 171 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.
156 157 158 159 160 |
# File 'lib/rbeapi/api/bgp.rb', line 156 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.
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rbeapi/api/bgp.rb', line 56 def get config = get_block('^router bgp .*') return {} unless config response = Bgp.parse_bgp_as(config) response.merge!(parse_router_id(config)) response.merge!(parse_shutdown(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.
290 291 292 293 294 |
# File 'lib/rbeapi/api/bgp.rb', line 290 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_router_id(opts = {}) ⇒ Boolean
set_router_id sets the router_id for the BGP routing instance.
222 223 224 |
# File 'lib/rbeapi/api/bgp.rb', line 222 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.
245 246 247 248 249 250 251 |
# File 'lib/rbeapi/api/bgp.rb', line 245 def set_shutdown(opts = {}) fail 'set_shutdown has the 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(command_builder('shutdown', opts)) end |