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_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.
| 169 170 171 | # File 'lib/rbeapi/api/ospf.rb', line 169 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
| 126 127 128 | # File 'lib/rbeapi/api/ospf.rb', line 126 def create(pid) configure "router ospf #{pid}" end | 
#delete(pid) ⇒ Boolean
delete will remove the specified router ospf
| 136 137 138 | # File 'lib/rbeapi/api/ospf.rb', line 136 def delete(pid) configure "no router ospf #{pid}" end | 
#get(inst) ⇒ Hash
Returns the global OSPF configuration from the node
rubocop:disable Metrics/MethodLength
| 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 87 88 | # File 'lib/rbeapi/api/ospf.rb', line 62 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 ⇒ Hash
Returns the OSPF configuration from the node as a Ruby hash
<pid>: {
  router_id: <string>,
  areas: {,
  redistribute: {}
},
interfaces: {}
}
| 105 106 107 108 109 110 111 112 | # File 'lib/rbeapi/api/ospf.rb', line 105 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
| 114 115 116 117 118 | # File 'lib/rbeapi/api/ospf.rb', line 114 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.
| 184 185 186 | # File 'lib/rbeapi/api/ospf.rb', line 184 def remove_network(pid, net, area) configure ["router ospf #{pid}", "no network #{net} area #{area}"] end | 
#set_redistribute(pid, proto, opts = {}) ⇒ Boolean
set_redistribute sets router ospf router-id with pid and options
| 205 206 207 208 209 210 | # File 'lib/rbeapi/api/ospf.rb', line 205 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 = {}) ⇒ Boolean
set_router_id sets router ospf router-id with pid and options
| 153 154 155 156 157 | # File 'lib/rbeapi/api/ospf.rb', line 153 def set_router_id(pid, opts = {}) cmd = command_builder('router-id', opts) cmds = ["router ospf #{pid}", cmd] configure cmds end |