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) ⇒ Object
- #create(pid) ⇒ Object
- #delete(pid) ⇒ Object
-
#get(inst) ⇒ Hash
Returns the global OSPF configuration from the node.
-
#getall ⇒ Object
Returns the OSPF configuration from the node as a Ruby hash.
- #interfaces ⇒ Object
- #remove_network(pid, net, area) ⇒ Object
- #set_redistribute(pid, proto, opts = {}) ⇒ Object
- #set_router_id(pid, opts = {}) ⇒ Object
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) ⇒ Object
125 126 127 |
# File 'lib/rbeapi/api/ospf.rb', line 125 def add_network(pid, net, area) configure ["router ospf #{pid}", "network #{net} area #{area}"] end |
#create(pid) ⇒ Object
111 112 113 |
# File 'lib/rbeapi/api/ospf.rb', line 111 def create(pid) configure "router ospf #{pid}" end |
#delete(pid) ⇒ Object
115 116 117 |
# File 'lib/rbeapi/api/ospf.rb', line 115 def delete(pid) configure "no router ospf #{pid}" end |
#get(inst) ⇒ Hash
Returns the global OSPF configuration from the node
rubocop:disable Metrics/MethodLength
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/rbeapi/api/ospf.rb', line 60 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] 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 ⇒ Object
Returns the OSPF configuration from the node as a Ruby hash
<pid>: {...
"interfaces": ...
}
96 97 98 99 100 101 102 103 |
# File 'lib/rbeapi/api/ospf.rb', line 96 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
105 106 107 108 109 |
# File 'lib/rbeapi/api/ospf.rb', line 105 def interfaces @interfaces if @interfaces @interfaces = OspfInterfaces.new(node) @interfaces end |
#remove_network(pid, net, area) ⇒ Object
129 130 131 |
# File 'lib/rbeapi/api/ospf.rb', line 129 def remove_network(pid, net, area) configure ["router ospf #{pid}", "no network #{net} area #{area}"] end |
#set_redistribute(pid, proto, opts = {}) ⇒ Object
133 134 135 136 137 138 |
# File 'lib/rbeapi/api/ospf.rb', line 133 def set_redistribute(pid, proto, opts = {}) routemap = opts[:routemap] cmds = ["router ospf #{pid}", "redistribute #{proto}"] cmds[1] << " route-map #{routemap}" if routemap configure cmds end |
#set_router_id(pid, opts = {}) ⇒ Object
119 120 121 122 123 |
# File 'lib/rbeapi/api/ospf.rb', line 119 def set_router_id(pid, opts = {}) cmd = command_builder('router-id', opts) cmds = ["router ospf #{pid}", cmd] configure cmds end |