Method: Rbeapi::Api::Ospf#get

Defined in:
lib/rbeapi/api/ospf.rb

#get(inst) ⇒ Hash

Returns the global OSPF configuration from the node

Examples:

{
  "router_id": <string>
  "areas": {
    <string>: array<string>
  },
  "resdistribute"
}

Returns:

  • (Hash)

    A Ruby hash object that provides the OSPF settings as key / value pairs.



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