class Rbeapi::Api::EthernetInterface
The EthernetInterface
class manages all Ethernet interfaces on an EOS node.
Constants
- DEFAULT_ETH_FLOWC_RX
- DEFAULT_ETH_FLOWC_TX
- DEFAULT_LACP_PRIORITY
- DEFAULT_SPEED
Public Instance Methods
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
@param name [String] The name of the interface.
@raise [NotImplementedError] Creation of physical Ethernet interfaces
is not supported. Only subinterfaces are allowed.
# 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 overrides the delete method fro the BaseInterface
instance and raises an exception because Ethernet interface deletion is not supported.
@param name [String] The name of the interface.
@raise [NotImplementedError] Deletion of physical Ethernet interfaces
is not supported.
# 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 returns the specified Ethernet interface resource hash that represents the interface's current configuration in the node.
@example
{ 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> }
@param name [String] The interface name to return a resource hash
for from the node's running configuration.
@return [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.
Rbeapi::Api::BaseInterface#get
# 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
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
@since eos_version 4.13.7M
@param name [String] The interface name to apply the configuration
values to. The name must be the full interface identifier.
@param direction [String] Specifies the flowcontrol direction to
configure. Valid values include send and receive.
@param opts [Hash] Optional keyword arguments.
@option opts value [String] Specifies the value to configure the
flowcontrol setting for. Valid values include on or off.
@option opts enable [Boolean] If false then the command is
negated. Default is true.
@option opts default [Boolean] Configures the flowcontrol value on
the interface using the default keyword.
@return [Boolean] Returns true if the command completed successfully.
# 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
is a convenience function for configuring the value of interface flowcontrol.
@see set_flowcontrol
@since eos_version 4.13.7M
@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
flowcontrol setting for. Valid values include on or off.
@option opts enable [Boolean] If false then the command is
negated. Default is true.
@option opts default [Boolean] Configures the flowcontrol value on
the interface using the default keyword.
@return [Boolean] Returns true if the command completed successfully.
# File lib/rbeapi/api/interfaces.rb, line 763 def set_flowcontrol_receive(name, opts = {}) set_flowcontrol(name, 'receive', opts) end
set_flowcontrol_send
is a convenience function for configuring the value of interface flowcontrol.
@see set_flowcontrol
@since eos_version 4.13.7M
@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
flowcontrol setting for. Valid values include on or off.
@option opts enable [Boolean] If false then the command is
negated. Default is true.
@option opts default [Boolean] Configures the flowcontrol value on
the interface using the default keyword.
@return [Boolean] Returns true if the command completed successfully.
# File lib/rbeapi/api/interfaces.rb, line 736 def set_flowcontrol_send(name, opts = {}) set_flowcontrol(name, 'send', opts) end
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
@since eos_version 4.13.7M
@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 enable [Boolean] Enables sflow if the value is true or
disables the lacp port-priority on the interface if false. Default is true.
@option opts default [Boolean] Configures the lacp port-priority value
on the interface using the default keyword.
@return [Boolean] Returns true if the command completed successfully.
# 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
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
@since eos_version 4.13.7M
@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 enable [Boolean] Enables sflow if the value is true or
disables sflow on the interface if false. Default is true.
@option opts default [Boolean] Configures the sflow value on the
interface using the default keyword.
@return [Boolean] Returns true if the command completed successfully.
# 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
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.
@since eos_version 4.13.7M
@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] The value to configure the speed setting to
in the nodes running configuration.
@option opts enable [Boolean] If false then the command is
negated. Default is true.
@return [Boolean] Returns true if the command completed successfully.
# 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
Private Instance Methods
parse_flowcontrol_receive
scans the provided configuration block and parse the flowcontrol receive value. If the interface flowcontrol value is not configured, then this method will return the value of DEFAULT_ETH_FLOWC_RX
. 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 554 def parse_flowcontrol_receive(config) mdata = /flowcontrol receive (\w+)$/.match(config) { flowcontrol_receive: mdata.nil? ? DEFAULT_ETH_FLOWC_RX : mdata[1] } end
parse_flowcontrol_send
scans the provided configuration block and parses the flowcontrol send value. If the interface flowcontrol value is not configured, then this method will return the value of DEFAULT_ETH_FLOWC_TX
. 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 536 def parse_flowcontrol_send(config) mdata = /flowcontrol send (\w+)$/.match(config) { flowcontrol_send: mdata.nil? ? DEFAULT_ETH_FLOWC_TX : mdata[1] } end
parse_lacp_priority
scans the provided configuration block and parse the lacp port-priority value. If the interface lacp port-priority value is not configured, then this method will return the value of DEFAULT_LACP_PRIORITY
. 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 572 def parse_lacp_priority(config) mdata = /lacp port-priority (\d+)$/.match(config) { lacp_priority: mdata.nil? ? DEFAULT_LACP_PRIORITY : mdata[1] } end
parse_sflow
scans the provided configuration block and parse the sflow value. The sflow values true if sflow is enabled on the interface or returns false if it is not enabled. The hash returned is intended to be merged into the interface 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 518 def parse_sflow(config) value = /no sflow enable/ =~ config { sflow: value.nil? } end
parse_speed
scans the provided configuration block and parses the speed value. If the speed value is not found in the interface configuration block provided, DEFAULT_SPEED
and DEFAULT_FORCED are used. The returned hash 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 501 def parse_speed(config) value = config.scan(/speed (.*)/).first { speed: value.nil? ? DEFAULT_SPEED : value.first } end