Class: Rbeapi::Api::EthernetInterface

Inherits:
BaseInterface show all
Defined in:
lib/rbeapi/api/interfaces.rb

Overview

The EthernetInterface class manages all Ethernet interfaces on an EOS node.

Constant Summary collapse

DEFAULT_ETH_FLOWC_TX =
'off'
DEFAULT_ETH_FLOWC_RX =
'off'
DEFAULT_SPEED =
'auto'
DEFAULT_FORCED =
false

Constants inherited from BaseInterface

BaseInterface::DEFAULT_INTF_DESCRIPTION

Instance Attribute Summary

Attributes inherited from Entity

#config, #error, #node

Instance Method Summary collapse

Methods inherited from BaseInterface

#default, #set_description, #set_shutdown

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

#create(_name) ⇒ Object

create overrides the create method from the BaseInterface and raises an exception because Ethernet interface creation is not supported.

Parameters:

  • :name (String)

    The name of the interface

Raises:

  • (NotImplementedError)

    Creation of physical Ethernet interfaces is not supported



398
399
400
401
# File 'lib/rbeapi/api/interfaces.rb', line 398

def create(_name)
  fail NotImplementedError, 'creating Ethernet interfaces is '\
        'not supported'
end

#delete(_name) ⇒ Object

delete overrides the delete method fro the BaseInterface instance and raises an exception because Ethernet interface deletion is not supported.

Parameters:

  • :name (String)

    The name of the interface

Raises:

  • (NotImplementedError)

    Deletion of physical Ethernet interfaces is not supported



412
413
414
415
# File 'lib/rbeapi/api/interfaces.rb', line 412

def delete(_name)
  fail NotImplementedError, 'deleting Ethernet interfaces is '\
        'not supported'
end

#get(name) ⇒ nil, Hash<Symbol, Object>

get returns the specified Ethernet interface resource hash that represents the interface’s current configuration in the node.

The resource hash returned contains the following information:

* name (string): the interface name (eg Ethernet1)
* type (string): will always be 'ethernet'
* description (string): the interface description value
* speed (string): the current speed setting for the interface speed
* forced (boolean): true if auto negotiation is disabled otherwise
  false
* sflow (boolean): true if sflow is enabled on the interface
  otherwise false
* flowcontrol_send (string): the interface flowcontrol send value.
  Valid values are 'on' or 'off'
* flowconrol_receive (string): the interface flowcontrol receive
  value.  Valid values are 'on' or 'off'

Parameters:

  • :name (String)

    The interface name to return a resource hash for from the node’s running configuration

Returns:

  • (nil, Hash<Symbol, Object>)

    Returns the interface resource as a hash. If the specified interface name is not found in the node’s configuration a nil object is returned



311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/rbeapi/api/interfaces.rb', line 311

def get(name)
  config = get_block("^interface #{name}")
  return nil unless config

  response = super(name)
  response[:type] = 'ethernet'

  response.merge!(parse_speed(config))
  response.merge!(parse_sflow(config))
  response.merge!(parse_flowcontrol_send(config))
  response.merge!(parse_flowcontrol_receive(config))

  response
end

#set_flowcontrol(name, direction, opts = {}) ⇒ Boolean

set_flowcontrol configures the flowcontrol value either on or off for the for the specified interface in the specified direction (either send or receive). If the enable keyword is false then the configuration is negated using the no keyword. If the default keyword is set to true, then the state value is defaulted using the default keyword. The default keyword takes precedence over the enable keyword

Parameters:

  • :name (String)

    The interface name to apply the configuration values to. The name must be the full interface identifier.

  • :direction (String)

    Specifies the flowcontrol direction to configure. Valid values include send and receive.

  • :opts (Hash)

    optional keyword arguments

Returns:

  • (Boolean)

    returns true if the command completed successfully



519
520
521
522
# File 'lib/rbeapi/api/interfaces.rb', line 519

def set_flowcontrol(name, direction, opts = {})
  commands = command_builder("flowcontrol #{direction}", opts)
  configure_interface(name, commands)
end

#set_flowcontrol_receive(name, opts = {}) ⇒ Boolean

set_flowcontrol_receive is a convenience function for configuring th e value of interface flowcontrol

Parameters:

  • :name (String)

    The interface name to apply the configuration values to. The name must be the full interface identifier.

  • :opts (Hash)

    optional keyword arguments

Returns:

  • (Boolean)

    returns true if the command completed successfully

See Also:



574
575
576
# File 'lib/rbeapi/api/interfaces.rb', line 574

def set_flowcontrol_receive(name, opts = {})
  set_flowcontrol(name, 'receive', opts)
end

#set_flowcontrol_send(name, opts = {}) ⇒ Boolean

set_flowcontrol_send is a convenience function for configuring the value of interface flowcontrol.

Parameters:

  • :name (String)

    The interface name to apply the configuration values to. The name must be the full interface identifier.

  • :opts (Hash)

    optional keyword arguments

Returns:

  • (Boolean)

    returns true if the command completed successfully

See Also:



547
548
549
# File 'lib/rbeapi/api/interfaces.rb', line 547

def set_flowcontrol_send(name, opts = {})
  set_flowcontrol(name, 'send', opts)
end

#set_sflow(name, opts = {}) ⇒ Boolean

set_sflow configures the administrative state of sflow on the interface. Setting the enable keyword to true enables sflow on the interface and setting enable to false disables sflow on the interface. If the default keyword is set to true, then the sflow value is defaulted using the default keyword. The default keyword takes precedence over the enable keyword

Parameters:

  • :name (String)

    The interface name to apply the configuration values to. The name must be the full interface identifier.

  • :opts (Hash)

    optional keyword arguments

Returns:

  • (Boolean)

    returns true if the command completed successfully



486
487
488
489
# File 'lib/rbeapi/api/interfaces.rb', line 486

def set_sflow(name, opts = {})
  commands = command_builder('sflow enable', opts)
  configure_interface(name, commands)
end

#set_speed(name, opts = {}) ⇒ Boolean

set_speed configures the interface speed and negotiation values on the specified interface. If the enable option is false the speed setting is configured using the no keyword. If the default options is set to true, then the speed setting is configured using the default keyword. If both options are specified, the default keyword takes precedence.

Parameters:

  • :name (String)

    The interface name to apply the configuration values to. The name must be the full interface identifier.

  • :opts (Hash)

    optional keyword arguments

  • [String] (Hash)

    a customizable set of options

  • [Boolean] (Hash)

    a customizable set of options

Returns:

  • (Boolean)

    returns true if the command completed successfully



445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'lib/rbeapi/api/interfaces.rb', line 445

def set_speed(name, opts = {})
  value = opts[:value]
  forced = opts.fetch(:forced, false)
  enable = opts.fetch(:enable, true)
  default = opts.fetch(:default, false)

  forced = 'forced' if forced
  forced = '' if value == 'auto'

  cmds = ["interface #{name}"]
  case default
  when true
    cmds << 'default speed'
  when false
    cmds << enable ? "speed #{forced} #{value}" : 'no speed'
  end
  configure cmds
end