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
#configure, #get_block, #initialize, instance
Constructor Details
This class inherits a constructor from Rbeapi::Api::Entity
Instance Method Details
#add_network(pid, net, area) ⇒ Object
132 133 134 |
# File 'lib/rbeapi/api/ospf.rb', line 132 def add_network(pid, net, area) configure ["router ospf #{pid}", "network #{net} area #{area}"] end |
#create(pid) ⇒ Object
110 111 112 |
# File 'lib/rbeapi/api/ospf.rb', line 110 def create(pid) configure "router ospf #{pid}" end |
#delete(pid) ⇒ Object
114 115 116 |
# File 'lib/rbeapi/api/ospf.rb', line 114 def delete(pid) configure "no router ospf #{pid}" end |
#get(inst) ⇒ Hash
Returns the global OSPF configuration from the node
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rbeapi/api/ospf.rb', line 57 def get(inst) config = get_block("router ospf #{inst}") return nil unless config resp = {} mdata = /(?<=^\s{3}router-id\s)(.+)$/.match(config) resp['router_id'] = mdata.nil? ? '' : mdata[0] mdata = /^\s{3}network\s(.+)\sarea\s(.+)$/.match(config) 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 resp['areas'] = areas values = config.scan(/(?<=^\s{3}redistribute\s)(\w+)[\s|$]*(route-map\s(.+))?/) resp['redistribute'] = values.each_with_object({}) do |value, hsh| hsh[value[0]] = { 'route_map' => value[2] } end resp end |
#getall ⇒ Object
Returns the OSPF configuration from the node as a Ruby hash
<pid>: {...
"interfaces": ...
}
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/rbeapi/api/ospf.rb', line 93 def getall response = {} 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
104 105 106 107 108 |
# File 'lib/rbeapi/api/ospf.rb', line 104 def interfaces @interfaces if @interfaces @interfaces = OspfInterfaces.new(node) @interfaces end |
#remove_network(pid, net, area) ⇒ Object
136 137 138 |
# File 'lib/rbeapi/api/ospf.rb', line 136 def remove_network(pid, net, area) configure ["router ospf #{pid}", "no network #{net} area #{area}"] end |
#set_redistribute(pid, proto, opts = {}) ⇒ Object
140 141 142 143 144 145 |
# File 'lib/rbeapi/api/ospf.rb', line 140 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
118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/rbeapi/api/ospf.rb', line 118 def set_router_id(pid, opts = {}) value = opts[:value] default = opts[:default] || false cmds = ["router ospf #{pid}"] case default when true cmds << 'default router-id' when false cmds << (value ? "router-id #{value}" : 'no router-id') end configure cmds end |