Class: Rbeapi::Api::Ospf
Overview
The Ospf class is a global class that provides an instance for working with the node’s OSPF configuration.
Instance Attribute Summary
Attributes inherited from Entity
Instance Method Summary collapse
-
#add_network(pid, net, area) ⇒ Boolean
add_network adds network settings for router ospf and network area.
-
#create(pid) ⇒ Boolean
create will create a router ospf with the specified pid.
-
#delete(pid) ⇒ Boolean
delete will remove the specified router ospf.
-
#get(inst) ⇒ Hash
Returns the global OSPF configuration from the node.
-
#getall ⇒ Hash
Returns the OSPF configuration from the node as a Ruby hash.
- #interfaces ⇒ Object
-
#remove_network(pid, net, area) ⇒ Boolean
remove_network removes network settings for router ospf and network area.
-
#set_active_interfaces(pid, opts = {}) ⇒ Boolean
set_active_interfaces sets router ospf no passive interface with pid and options, when passive interfaces default is configured.
-
#set_max_lsa(pid, opts = {}) ⇒ Boolean
set_max_lsa sets router ospf max-lsa with pid and options.
-
#set_maximum_paths(pid, opts = {}) ⇒ Boolean
set_maximum_paths sets router ospf maximum-paths with pid and options.
-
#set_passive_interface_default(pid, opts = {}) ⇒ Boolean
set_passive_interface_default sets router ospf passive-interface default with pid and options.
-
#set_passive_interfaces(pid, opts = {}) ⇒ Boolean
set_passive_interfaces sets router ospf passive interface with pid and options.
-
#set_redistribute(pid, proto, opts = {}) ⇒ Boolean
set_redistribute sets router ospf router-id with pid and options.
-
#set_router_id(pid, opts = {}) ⇒ Boolean
set_router_id sets router ospf router-id with pid and options.
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
#add_network(pid, net, area) ⇒ Boolean
add_network adds network settings for router ospf and network area.
324 325 326 |
# File 'lib/rbeapi/api/ospf.rb', line 324 def add_network(pid, net, area) configure ["router ospf #{pid}", "network #{net} area #{area}"] end |
#create(pid) ⇒ Boolean
create will create a router ospf with the specified pid.
154 155 156 |
# File 'lib/rbeapi/api/ospf.rb', line 154 def create(pid) configure "router ospf #{pid}" end |
#delete(pid) ⇒ Boolean
delete will remove the specified router ospf.
164 165 166 |
# File 'lib/rbeapi/api/ospf.rb', line 164 def delete(pid) configure "no router ospf #{pid}" end |
#get(inst) ⇒ Hash
Returns the global OSPF configuration from the node.
rubocop:disable Metrics/MethodLength
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rbeapi/api/ospf.rb', line 69 def get(inst) config = get_block("router ospf #{inst}") return nil unless config response = {} mdata = /(?<=^\s{3}router-id\s)(.+)$/.match(config) response[:router_id] = mdata.nil? ? '' : mdata[0] mdata = /(?<=^\s{3}max-lsa\s)(\d+)(?=.*$)/.match(config) response[:max_lsa] = mdata.nil? ? '' : mdata[0].to_i mdata = /(?<=^\s{3}maximum-paths\s)(\d+)$/.match(config) response[:maximum_paths] = mdata.nil? ? '' : mdata[0].to_i mdata = /^\s{3}passive-interface default$/ =~ config response[:passive_interface_default] = !mdata.nil? response[:passive_interfaces] = config.scan(/(?<=^\s{3}passive-interface\s)(?!default)(.*)$/) .flatten!.to_a response[:active_interfaces] = config.scan(/(?<=^\s{3}no passive-interface\s)(.*)$/).flatten!.to_a networks = config.scan(/^\s{3}network\s(.+)\sarea\s(.+)$/) areas = networks.each_with_object({}) do |cfg, hsh| net, area = cfg if hsh.include?(area) hsh[area] << net else hsh[area] = [net] end end response[:areas] = areas values = \ config.scan(/(?<=^\s{3}redistribute\s)(\w+)[\s|$]*(route-map\s(.+))?/) response[:redistribute] = values.each_with_object({}) do |value, hsh| hsh[value[0]] = { route_map: value[2] } end response end |
#getall ⇒ Hash
Returns the OSPF configuration from the node as a Ruby hash.
133 134 135 136 137 138 139 140 |
# File 'lib/rbeapi/api/ospf.rb', line 133 def getall instances = config.scan(/(?<=^router\sospf\s)\d+$/) response = instances.each_with_object({}) do |inst, hsh| hsh[inst] = get inst end response[:interfaces] = interfaces.getall response end |
#interfaces ⇒ Object
142 143 144 145 146 |
# File 'lib/rbeapi/api/ospf.rb', line 142 def interfaces @interfaces if @interfaces @interfaces = OspfInterfaces.new(node) @interfaces end |
#remove_network(pid, net, area) ⇒ Boolean
remove_network removes network settings for router ospf and network
area.
339 340 341 |
# File 'lib/rbeapi/api/ospf.rb', line 339 def remove_network(pid, net, area) configure ["router ospf #{pid}", "no network #{net} area #{area}"] end |
#set_active_interfaces(pid, opts = {}) ⇒ Boolean
set_active_interfaces sets router ospf no passive interface with pid and options, when passive interfaces default is configured.
default.
269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/rbeapi/api/ospf.rb', line 269 def set_active_interfaces(pid, opts = {}) values = opts[:value] current = get(pid)[:active_interfaces] cmds = ["router ospf #{pid}"] current.each do |name| unless Array(values).include?(name) cmds << "passive-interface #{name}" end end Array(values).each do |name| cmds << "no passive-interface #{name}" end configure cmds end |
#set_max_lsa(pid, opts = {}) ⇒ Boolean
set_max_lsa sets router ospf max-lsa with pid and options.
200 201 202 203 204 |
# File 'lib/rbeapi/api/ospf.rb', line 200 def set_max_lsa(pid, opts = {}) cmd = command_builder('max-lsa', opts) cmds = ["router ospf #{pid}", cmd] configure cmds end |
#set_maximum_paths(pid, opts = {}) ⇒ Boolean
set_maximum_paths sets router ospf maximum-paths with pid and options.
219 220 221 222 223 |
# File 'lib/rbeapi/api/ospf.rb', line 219 def set_maximum_paths(pid, opts = {}) cmd = command_builder('maximum-paths', opts) cmds = ["router ospf #{pid}", cmd] configure cmds end |
#set_passive_interface_default(pid, opts = {}) ⇒ Boolean
set_passive_interface_default sets router ospf passive-interface default with pid and options. If the passive-interface default keyword is false, then the passive-interface default is disabled. If the enable keyword is true, then the passive-interface default is enabled. If the default keyword is set to true, then the passive-interface default is configured using the default keyword. The default keyword takes precedence ver the enable keyword if both are provided.
to default.
246 247 248 249 250 251 252 |
# File 'lib/rbeapi/api/ospf.rb', line 246 def set_passive_interface_default(pid, opts = {}) opts[:enable] = opts[:value] | false opts[:value] = nil cmd = command_builder('passive-interface default', opts) cmds = ["router ospf #{pid}", cmd] configure cmds end |
#set_passive_interfaces(pid, opts = {}) ⇒ Boolean
set_passive_interfaces sets router ospf passive interface with pid and options.
default.
299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/rbeapi/api/ospf.rb', line 299 def set_passive_interfaces(pid, opts = {}) values = opts[:value] current = get(pid)[:passive_interfaces] cmds = ["router ospf #{pid}"] current.each do |name| unless Array(values).include?(name) cmds << "no passive-interface #{name}" end end Array(values).each do |name| cmds << "passive-interface #{name}" end configure cmds end |
#set_redistribute(pid, proto, opts = {}) ⇒ Boolean
set_redistribute sets router ospf router-id with pid and options.
360 361 362 363 364 365 366 367 |
# File 'lib/rbeapi/api/ospf.rb', line 360 def set_redistribute(pid, proto, opts = {}) routemap = opts[:route_map] redistribute = "redistribute #{proto}" redistribute << " route-map #{routemap}" if routemap cmd = command_builder(redistribute, opts) cmds = ["router ospf #{pid}", cmd] configure cmds end |
#set_router_id(pid, opts = {}) ⇒ Boolean
set_router_id sets router ospf router-id with pid and options.
181 182 183 184 185 |
# File 'lib/rbeapi/api/ospf.rb', line 181 def set_router_id(pid, opts = {}) cmd = command_builder('router-id', opts) cmds = ["router ospf #{pid}", cmd] configure cmds end |