class Rbeapi::Api::BaseInterface

The BaseInterface class extends Entity and provides an implementation that is common to all interfaces configured in EOS.

Constants

DEFAULT_INTF_DESCRIPTION
DEFAULT_INTF_ENCAPSULATION
DEFAULT_LOAD_INTERVAL

Public Instance Methods

create(value) click to toggle source

create will create a new interface resource in the node's current configuration with the specified interface name. If the create method is called and the interface already exists, this method will return successful.

@since eos_version 4.13.7M

@param value [String] The interface name to create on the node. The

interface name must be the full interface identifier (ie Loopback,
not Lo).

@return [Boolean] Returns true if the command completed successfully.

# File lib/rbeapi/api/interfaces.rb, line 280
def create(value)
  configure("interface #{value}")
end
default(value) click to toggle source

default will configure the interface using the default keyword. For virtual interfaces this is equivalent to deleting the interface. For physical interfaces, the entire interface configuration will be set to defaults.

@since eos_version 4.13.7M

@param value [String] The interface name to default in the node. The

interface name must be the full interface identifier (ie Loopback,
not Lo).

@return [Boolean] Returns true if the command completed successfully.

# File lib/rbeapi/api/interfaces.rb, line 314
def default(value)
  configure("default interface #{value}")
end
delete(value) click to toggle source

delete will delete an existing interface resource in the node's current configuration with the specified interface name. If the delete method is called and interface does not exist, this method will return successful.

@since eos_version 4.13.7M

@param value [String] The interface name to delete from the node.

The interface name must be the full interface identifier
(ie Loopback, no Lo).

@return [Boolean] Returns true if the command completed successfully.

# File lib/rbeapi/api/interfaces.rb, line 297
def delete(value)
  configure("no interface #{value}")
end
get(name) click to toggle source

get returns the specified interface resource hash that represents the node's current interface configuration. The BaseInterface class provides all the set of attributes that are common to all interfaces in EOS. This method will return an interface type of generic.

@example

{
  name: <string>
  type: 'generic'
  description: <string>
  encapsulation: <integer>
  shutdown: [true, false]
  load_interval: <string>
}

@param name [String] The name of the interface to return from the

running-configuration.

@return [nil, Hash<String, Object>] Returns a hash of the interface

properties if the interface name was found in the running
configuration.  If the interface was not found, nil is returned.
# File lib/rbeapi/api/interfaces.rb, line 179
def get(name)
  config = get_block("^interface #{name}")
  return nil unless config

  response = { name: name, type: 'generic' }
  response.merge!(parse_description(config))
  response.merge!(parse_encapsulation(config))
  response.merge!(parse_shutdown(config))
  response.merge!(parse_load_interval(config))
  response
end
set_description(name, opts = {}) click to toggle source

set_description configures the description value for the specified interface name in the nodes running configuration. If the enable keyword is false then the description value is negated using the no keyword. If the default keyword is set to true, then the description value is defaulted using the default keyword. The default keyword takes precedence over the enable keyword if both are provided.

@since eos_version 4.13.7M

@param name [String] The interface name to apply the configuration

to. The name value must be the full interface identifier.

@param opts [hash] Optional keyword arguments.

@option opts value [String] The value to configure the description

to in the node's configuration.

@option opts enable [Boolean] If false then the command is

negated. Default is true.

@option opts default [Boolean] Configure the interface description

using the default keyword.

@return [Boolean] Returns true if the command completed successfully.

# File lib/rbeapi/api/interfaces.rb, line 343
def set_description(name, opts = {})
  commands = command_builder('description', opts)
  configure_interface(name, commands)
end
set_encapsulation(name, opts = {}) click to toggle source

set_encapsulation configures the VLAN ID value for the specified interface name in the nodes running configuration. If the enable keyword is false then the encapsulation value is negated using the no keyword. If the default keyword is set to true, then the encapsulation value is defaulted using the default keyword. The default keyword takes precedence over the enable keyword if both are provided.

@since eos_version X.XX.XM

@param name [String] The interface name to apply the configuration

to. The name value must be the full interface identifier.

@param opts [hash] Optional keyword arguments.

@option opts value [String] The value to configure the VLAN ID to be

used in the encapsulation dot1q vlan setting for a subinterface.

@option opts enable [Boolean] If false then the command is

negated. Default is true.

@option opts default [Boolean] Configure the interface encapsulation

using the default keyword.

@return [Boolean] Returns true if the command completed successfully.

# File lib/rbeapi/api/interfaces.rb, line 373
def set_encapsulation(name, opts = {})
  unless name =~ /\./
    raise ArgumentError, 'Parameter encapsulation can be set only on '\
      'subinterfaces'
  end
  unless name.downcase =~ /et|po/
    raise ArgumentError, 'Parameter encapsulation can be set only on '\
      'Ethernet and PostChannel interfaces'
  end
  commands = command_builder('encapsulation dot1q vlan', opts)
  configure_interface(name, commands)
end
set_load_interval(name, opts = {}) click to toggle source

set_load_interval is a convenience function for configuring the value of interface load-interval

@param name [String] The interface name to apply the configuration values to. The name must be the full interface identifier.

@param opts [Hash] Optional keyword arguments.

@option opts value [String] Specifies the value to configure the load-interval setting for. Valid values are between 5 and 600.

@option opts default [Boolean] Configures the load-interval value on the interface using the default keyword.

@return [Boolean] Returns true if the command completed successfully.

# File lib/rbeapi/api/interfaces.rb, line 435
def set_load_interval(name, opts = {})
  commands = command_builder('load-interval', opts)
  configure_interface(name, commands)
end
set_shutdown(name, opts = {}) click to toggle source

set_shutdown configures the administrative state of the specified interface in the node. If the enable keyword is false, then the interface is administratively disabled. If the enable keyword is true, then the interface is administratively enabled. If the default keyword is set to true, then the interface shutdown value is configured using the default keyword. The default keyword takes precedence over the enable keyword if both are provided.

@since eos_version 4.13.7M

@param name [String] The interface name to apply the configuration

to. The name value must be the full interface identifier.

@param opts [hash] Optional keyword arguments.

@option opts enable [Boolean] True if the interface should be

administratively enabled or false if the interface should be
administratively disabled.

@option opts default [Boolean] Configure the interface shutdown

using the default keyword.

@return [Boolean] Returns true if the command completed successfully.

# File lib/rbeapi/api/interfaces.rb, line 410
def set_shutdown(name, opts = {})
  raise 'set_shutdown has the value option set' if opts[:value]
  # Shutdown semantics are opposite of enable semantics so invert enable.
  value = !opts[:enable]
  opts[:enable] = value
  commands = command_builder('shutdown', opts)
  configure_interface(name, commands)
end

Private Instance Methods

parse_description(config) click to toggle source

parse_description scans the provided configuration block and parses the description value if it exists in the configuration. If the description value is not configured, then the DEFALT_INTF_DESCRIPTION value is returned. The hash returned by this method is intended to be merged into the interface resource hash returned by the get method.

@api private

@param config [String] The configuration block retrieved from the

nodes current running configuration.

@return [Hash<Symbol, Object>] Returns the resource hash attribute.

# File lib/rbeapi/api/interfaces.rb, line 204
def parse_description(config)
  mdata = /^\s{3}description\s(.+)$/.match(config)
  { description: mdata.nil? ? DEFAULT_INTF_DESCRIPTION : mdata[1] }
end
parse_encapsulation(config) click to toggle source

parse_encapsulation scans the provided configuration block and parses the encapsulation value if it exists in the configuration. If the encapsulation value is not configured, then the DEFALT_INTF_ENCAPSULATION value is returned. The hash returned by this method is intended to be merged into the interface resource hash returned by the get method.

@api private

@param config [String] The configuration block retrieved from the

nodes current running configuration.

@return [Hash<Symbol, Object>] Returns the resource hash attribute.

# File lib/rbeapi/api/interfaces.rb, line 224
def parse_encapsulation(config)
  mdata = /^\s{3}encapsulation dot1q vlan\s(.+)$/.match(config)
  { encapsulation: mdata.nil? ? DEFAULT_INTF_ENCAPSULATION : mdata[1] }
end
parse_load_interval(config) click to toggle source

parse_load_interval scans the provided configuration block and parse the load-interval value. If the interface load-interval value is not configured, then this method will return the value of DEFAULT_LOAD_INTERVAL. The hash returned is intended to be merged into the interface resource hash.

@api private

@param config [String] The configuration block to parse.

@return [Hash<Symbol, Object>] Returns the resource hash attribute.

# File lib/rbeapi/api/interfaces.rb, line 261
def parse_load_interval(config)
  mdata = /load-interval (\w+)$/.match(config)
  { load_interval: mdata.nil? ? DEFAULT_LOAD_INTERVAL : mdata[1] }
end
parse_shutdown(config) click to toggle source

parse_shutdown scans the provided configuration block and parses the shutdown value. If the shutdown value is configured then true is returned as its value otherwise false is returned. The hash returned by this method is intended to be merged into the interface resource hash returned by the get method.

@api private

@param config [String] The configuration block retrieved from the

nodes current running configuration.

@return [Hash<Symbol, Object>] Returns the resource hash attribute.

# File lib/rbeapi/api/interfaces.rb, line 243
def parse_shutdown(config)
  value = /no shutdown/ =~ config
  { shutdown: value.nil? }
end