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'.freeze
DEFAULT_ETH_FLOWC_RX =
'off'.freeze
DEFAULT_SPEED =
'default'.freeze
DEFAULT_LACP_PRIORITY =
32_768

Constants inherited from BaseInterface

BaseInterface::DEFAULT_INTF_DESCRIPTION, BaseInterface::DEFAULT_INTF_ENCAPSULATION, BaseInterface::DEFAULT_LOAD_INTERVAL

Instance Attribute Summary

Attributes inherited from Entity

#config, #error, #node

Instance Method Summary collapse

Methods inherited from BaseInterface

#default, #set_description, #set_encapsulation, #set_load_interval, #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. This doesn’t happen for Ethernet subinterfaces

Parameters:

  • name (String)

    The name of the interface.

Raises:

  • (NotImplementedError)

    Creation of physical Ethernet interfaces is not supported. Only subinterfaces are allowed.



587
588
589
590
591
592
593
594
# File 'lib/rbeapi/api/interfaces.rb', line 587

def create(name)
  if name !~ /\./
    raise NotImplementedError, 'creating Ethernet interfaces is '\
      'not supported'
  else
    configure("interface #{name}")
  end
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.



605
606
607
608
609
610
611
612
# File 'lib/rbeapi/api/interfaces.rb', line 605

def delete(name)
  if name !~ /\./
    raise NotImplementedError, 'deleting Ethernet interfaces is '\
      'not supported'
  else
    configure("no interface #{name}")
  end
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.

Examples:

{
  name: <string>,
  type: <string>,
  description: <string>,
  encapsulation: <integer>,
  shutdown: <boolean>,
  load_interval: <string>
  speed: <string>,
  sflow: <boolean>,
  flowcontrol_send: <string>,
  flowcontrol_receive: <string>
  lacp_priority: <integer>
}

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.



475
476
477
478
479
480
481
482
483
484
485
486
487
488
# File 'lib/rbeapi/api/interfaces.rb', line 475

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.merge!(parse_lacp_priority(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) (defaults to: {})

    Optional keyword arguments.

Options Hash (opts):

  • value (String)

    Specifies the value to configure the flowcontrol setting for. Valid values include on or off.

  • enable (Boolean)

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

  • default (Boolean)

    Configures the flowcontrol value on the interface using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



708
709
710
711
# File 'lib/rbeapi/api/interfaces.rb', line 708

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 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) (defaults to: {})

    Optional keyword arguments.

Options Hash (opts):

  • value (String)

    Specifies the value to configure the flowcontrol setting for. Valid values include on or off.

  • enable (Boolean)

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

  • default (Boolean)

    Configures the flowcontrol value on the interface using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

See Also:

Since:

  • eos_version 4.13.7M



763
764
765
# File 'lib/rbeapi/api/interfaces.rb', line 763

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) (defaults to: {})

    Optional keyword arguments.

Options Hash (opts):

  • value (String)

    Specifies the value to configure the flowcontrol setting for. Valid values include on or off.

  • enable (Boolean)

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

  • default (Boolean)

    Configures the flowcontrol value on the interface using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

See Also:

Since:

  • eos_version 4.13.7M



736
737
738
# File 'lib/rbeapi/api/interfaces.rb', line 736

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

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

set_lacp_priority configures the lacp port-priority on the interface. Setting the enable keyword to true enables the lacp port-priority on the interface and setting enable to false disables the lacp port-priority on the interface. If the default keyword is set to true, then the lacp port-priority 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) (defaults to: {})

    Optional keyword arguments.

Options Hash (opts):

  • enable (Boolean)

    Enables sflow if the value is true or disables the lacp port-priority on the interface if false. Default is true.

  • default (Boolean)

    Configures the lacp port-priority value on the interface using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



791
792
793
794
# File 'lib/rbeapi/api/interfaces.rb', line 791

def set_lacp_priority(name, opts = {})
  commands = command_builder('lacp port-priority', opts)
  configure_interface(name, commands)
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) (defaults to: {})

    Optional keyword arguments.

Options Hash (opts):

  • enable (Boolean)

    Enables sflow if the value is true or disables sflow on the interface if false. Default is true.

  • default (Boolean)

    Configures the sflow value on the interface using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



675
676
677
678
# File 'lib/rbeapi/api/interfaces.rb', line 675

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) (defaults to: {})

    Optional keyword arguments.

Options Hash (opts):

  • value (String)

    The value to configure the speed setting to in the nodes running configuration.

  • enable (Boolean)

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

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
# File 'lib/rbeapi/api/interfaces.rb', line 636

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

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

  configure cmds
end