Class: Rbeapi::Api::OspfInterfaces

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

Overview

The OspfInterfaces class is a global class that provides an instance for working with the node’s OSPF interface configuration.

Instance Attribute Summary

Attributes inherited from Entity

#config, #error, #node

Instance Method Summary collapse

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

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

Returns a single MLAG interface configuration.

Example

{
   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 configuration. A nil object is returned if the specified interface is not configured



388
389
390
391
392
393
394
395
396
397
398
399
# File 'lib/rbeapi/api/ospf.rb', line 388

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

  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>: {
    network_type: <string>
  },
  <name>: {
    network_type: <string>
  },
  ...
}

Returns:

  • (nil, Hash<String, String>)

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



419
420
421
422
423
424
425
# File 'lib/rbeapi/api/ospf.rb', line 419

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 = {}) ⇒ Boolean

set_network_type sets network type with options.

Parameters:

  • name (String)

    The name of the interface.

  • opts (hash) (defaults to: {})

    Optional keyword arguments.

Options Hash (opts):

  • value (String)

    The point-to-point value.

  • enable (Boolean)

    If false then the command is negated. Default is true.

  • default (Boolean)

    Configure the ip ospf network to default.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.



443
444
445
446
447
448
# File 'lib/rbeapi/api/ospf.rb', line 443

def set_network_type(name, opts = {})
  value = opts[:value]
  return false unless [nil, 'point-to-point'].include?(value)
  cmd = command_builder('ip ospf network', opts)
  configure_interface(name, cmd)
end