Class: Rbeapi::Api::OspfInterfaces

Inherits:
Entity
  • Object
show all
Defined in:
lib/rbeapi/api/ospf.rb

Instance Attribute Summary

Attributes inherited from Entity

#config, #error, #node

Instance Method Summary collapse

Methods inherited from Entity

#configure, #get_block, #initialize, instance

Constructor Details

This class inherits a constructor from Rbeapi::Api::Entity

Instance Method Details

#get(name) ⇒ nil, Hash<String, String>

Returns a single MLAG interface configuration

Example

{
  "name": <string>,
  "network_type": <string>
}

Parameters:

  • :name (String)

    The interface name to return the configuration values for. This must be the full interface identifier.

Returns:

  • (nil, Hash<String, String>)

    A Ruby hash that represents the MLAG interface confguration. A nil object is returned if the specified interface is not configured


165
166
167
168
169
170
171
172
173
174
# File 'lib/rbeapi/api/ospf.rb', line 165

def get(name)
  config = get_block("interface #{name}")
  return nil unless config
  return nil unless /no switchport$/ =~ config

  response = {}
  nettype = /ip ospf network point-to-point/ =~ config
  response['network_type'] = nettype.nil? ? 'broadcast' : 'point-to-point'
  response
end

#getallnil, Hash<String, String>

Returns the collection of MLAG interfaces as a hash index by the interface name

Example

{
  <name>: {...},
  <name>: {...}
}

Returns:

  • (nil, Hash<String, String>)

    A Ruby hash that represents the MLAG interface confguration. A nil object is returned if no interfaces are configured.


189
190
191
192
193
194
195
# File 'lib/rbeapi/api/ospf.rb', line 189

def getall
  interfaces = config.scan(/(?<=interface\s)[Et|Po|Lo|Vl].+/)
  interfaces.each_with_object({}) do |intf, hsh|
    values = get(intf)
    hsh[intf] = values if values
  end
end

#set_network_type(name, opts = {}) ⇒ Object


197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/rbeapi/api/ospf.rb', line 197

def set_network_type(name, opts = {})
  value = opts[:value]
  default = opts[:default] || false

  return false unless %w(nil point-to-point).include?(value)

  cmds = ["interface #{name}"]
  case default
  when true
    cmds << 'default ip ospf network'
  when false
    cmds << (value ? "ip ospf network #{value}" : 'no ip ospf netework')
  end
  configure(cmds)
end