Class: Rbeapi::Api::EthernetInterface

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

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

#configure, #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


432
433
434
435
# File 'lib/rbeapi/api/interfaces.rb', line 432

def create(name)
  raise 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


446
447
448
449
# File 'lib/rbeapi/api/interfaces.rb', line 446

def delete(name)
  raise NotImplementedError, 'deleting Ethernet interfaces is '\
        'not supported'
end

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

get returns the specified Etherent interface resource hash that respresents the interface's current configuration in th e 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 autonegotiation is disabled otherwise false

  • sflow (boolean): true if sflow is enabled on the interface otherwise false

  • flowcontrol_send (string): the inteface 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


345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/rbeapi/api/interfaces.rb', line 345

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 value is not provided 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 value 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


574
575
576
577
578
579
580
581
582
583
584
585
586
587
# File 'lib/rbeapi/api/interfaces.rb', line 574

def set_flowcontrol(name, direction, opts = {})
  value = opts[:value]
  default = opts.fetch(:default, false)

  commands = ["interface #{name}"]
  case default
  when true
    commands << "default flowcontrol #{direction}"
  when false
    commands << (value.nil? ? "no flowcontrol #{direction}" :
                              "flowcontrol #{direction} #{value}")
  end
  configure(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:


645
646
647
# File 'lib/rbeapi/api/interfaces.rb', line 645

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:


615
616
617
# File 'lib/rbeapi/api/interfaces.rb', line 615

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 value to true enables sflow on the interface and setting the value to false disables sflow on the interface. If the value is not provided, the sflow state is negated using the no keyword. 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 value 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


529
530
531
532
533
534
535
536
537
538
539
540
541
# File 'lib/rbeapi/api/interfaces.rb', line 529

def set_sflow(name, opts = {})
  value = opts[:value]
  default = opts.fetch(:default, false)

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

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

set_speed configures the interface speed and negotiation values on the specified interface. If the value option is not provide, 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


482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
# File 'lib/rbeapi/api/interfaces.rb', line 482

def set_speed(name, opts = {})
  value = opts[:value]
  forced = opts.fetch(:forced, false)
  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 << value ? "speed #{forced} #{value}" : 'no speed'
  end
  configure cmds
end