class Rbeapi::Api::Ospf
The Ospf
class is a global class that provides an instance for working with the node's OSPF configuration.
Public Instance Methods
add_network
adds network settings for router ospf and network area.
@param pid [String] The pid for router ospf.
@param net [String] The network name.
@param area [String] The network area name.
@return [Boolean] Returns true if the command completed successfully.
# File lib/rbeapi/api/ospf.rb, line 324 def add_network(pid, net, area) configure ["router ospf #{pid}", "network #{net} area #{area}"] end
create will create a router ospf with the specified pid.
@param pid [String] The router ospf to create.
@return [Boolean] Returns true if the command completed successfully.
# File lib/rbeapi/api/ospf.rb, line 154 def create(pid) configure "router ospf #{pid}" end
delete will remove the specified router ospf.
@param pid [String] The router ospf to remove.
@return [Boolean] Returns true if the command completed successfully.
# File lib/rbeapi/api/ospf.rb, line 164 def delete(pid) configure "no router ospf #{pid}" end
Returns the global OSPF configuration from the node.
rubocop:disable Metrics/MethodLength
@example
{ router_id: <string>, max_lsa: <integer>, maximum_paths: <integer>, passive_interface_default <boolean>, passive_interfaces: array<string>, active_interfaces: array<string>, areas: { <string>: array<string> }, redistribute: { <string>: {route_map: <string>} } }
@param inst [String] The ospf instance name.
@return [Hash] A Ruby hash object that provides the OSPF settings as
key / value pairs.
# 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
Returns the OSPF configuration from the node as a Ruby hash.
@example
{ <pid>: { router_id: <string>, max_lsa: <integer>, maximum_paths: <integer>, passive_interface_default <boolean>, passive_interfaces: array<string>, active_interfaces: array<string>, areas: {}, redistribute: {} }, interfaces: {} }
@return [Hash] A Ruby hash object that provides the OSPF settings as
key / value pairs.
# 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
# File lib/rbeapi/api/ospf.rb, line 142 def interfaces @interfaces if @interfaces @interfaces = OspfInterfaces.new(node) @interfaces end
remove_network
removes network settings for router ospf and network
area.
@param pid [String] The pid for router ospf.
@param net [String] The network name.
@param area [String] The network area name.
@return [Boolean] Returns true if the command completed successfully.
# 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
sets router ospf no passive interface with pid and options, when passive interfaces default is configured.
@param pid [String] The router ospf name.
@param opts [hash] Optional keyword arguments.
@option opts enable [Boolean] If false then the command is
negated. Default is true.
@option opts default [Boolean] Configure the active interface to default.
@return [Boolean] Returns true if the command completed successfully.
# 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
sets router ospf max-lsa with pid and options.
@param pid [String] The router ospf name.
@param opts [hash] Optional keyword arguments.
@option opts enable [Boolean] If false then the command is
negated. Default is true.
@option opts default [Boolean] Configure the max-lsa to default.
@return [Boolean] Returns true if the command completed successfully.
# 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
sets router ospf maximum-paths with pid and options.
@param pid [String] The router ospf name.
@param opts [hash] Optional keyword arguments.
@option opts enable [Boolean] If false then the command is
negated. Default is true.
@option opts default [Boolean] Configure the maximum-paths to default.
@return [Boolean] Returns true if the command completed successfully.
# 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
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.
@param pid [String] The router ospf name.
@param opts [hash] Optional keyword arguments.
@option opts enable [Boolean] If false then the command is
negated. Default is true.
@option opts default [Boolean] Configure the passive-interface default to default.
@return [Boolean] Returns true if the command completed successfully.
# 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
sets router ospf passive interface with pid and options.
@param pid [String] The router ospf name.
@param opts [hash] Optional keyword arguments.
@option opts enable [Boolean] If false then the command is
negated. Default is true.
@option opts default [Boolean] Configure the passive interface to default.
@return [Boolean] Returns true if the command completed successfully.
# 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
sets router ospf router-id with pid and options.
@param pid [String] The router ospf name.
@param proto [String] The redistribute value.
@param opts [hash] Optional keyword arguments.
@option opts routemap [String] The route-map value.
@option opts enable [Boolean] If false then the command is
negated. Default is true.
@option opts default [Boolean] Configure the router-id to default.
@return [Boolean] Returns true if the command completed successfully.
# 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
sets router ospf router-id with pid and options.
@param pid [String] The router ospf name.
@param opts [hash] Optional keyword arguments.
@option opts enable [Boolean] If false then the command is
negated. Default is true.
@option opts default [Boolean] Configure the router-id to default.
@return [Boolean] Returns true if the command completed successfully.
# 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