Class: Rbeapi::Api::Ipinterfaces

Inherits:
Entity
  • Object
show all
Defined in:
lib/rbeapi/api/ipinterfaces.rb

Overview

The Ipinterface class provides an instance for managing logical IP interfaces configured using eAPI.

Constant Summary collapse

DEFAULT_ADDRESS =
''.freeze
DEFAULT_LOAD_INTERVAL =
''.freeze

Instance Attribute Summary

Attributes inherited from Entity

#config, #error, #node

Instance Method Summary collapse

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) ⇒ Boolean

create will create a new IP interface on the node. If the ip interface already exists in the configuration, this method will still return successful. This method will cause an existing layer 2 interface (switchport) to be deleted if it exists in the node’s configuration.

Commands

interface <name>
  no switchport

Parameters:

  • name (String)

    The full interface name of the port to create the logical interface on. The name must be the full interface identifier.

Returns:

  • (Boolean)

    Returns true if the commands complete successfully.

Since:

  • eos_version 4.13.7M



205
206
207
# File 'lib/rbeapi/api/ipinterfaces.rb', line 205

def create(name)
  configure(["interface #{name}", 'no switchport'])
end

#delete(name) ⇒ Boolean

delete will delete an existing IP interface in the node’s current configuration. If the IP interface does not exist on the specified interface, this method will still return success. This command will default the interface back to being a switchport.

Commands

interface <name>
  no ip address
  switchport

Parameters:

  • name (String)

    The full interface name of the port to delete the logical interface from. The name must be the full interface name

Returns:

  • (Boolean)

    Returns true if the commands complete successfully.

Since:

  • eos_version 4.13.7M



226
227
228
# File 'lib/rbeapi/api/ipinterfaces.rb', line 226

def delete(name)
  configure(["interface #{name}", 'no ip address', 'switchport'])
end

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

get returns a resource hash that represents the configuration of the IP interface from the nodes running configuration.

Examples:

{
  address: <string>,
  mtu: <string>,
  helper_addresses: array<strings>
  load_interval: <string>
}

Parameters:

  • name (String)

    The full interface identifier of the interface to return the resource configuration hash for. The name must be the full name (Ethernet, not Et).

Returns:

  • (nil, Hash<Symbol, Object>)

    Returns the ip interface configuration as a hash. If the provided interface name is not a configured ip address, nil is returned.



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/rbeapi/api/ipinterfaces.rb', line 66

def get(name)
  config = get_block("interface #{name}")
  return nil unless config
  return nil if /\s{3}switchport$/ =~ config

  response = {}
  response.merge!(parse_address(config))
  response.merge!(parse_mtu(config))
  response.merge!(parse_helper_addresses(config))
  response.merge!(parse_load_interval(config))
  response
end

#getallHash<Symbol, Object>

getall returns a hash object that represents all ip interfaces configured on the node from the current running configuration.

Examples:

{
  <name>: {
    address: <string>,
    mtu: <string>,
    helper_addresses: array<strings>
    load_interval: <string>
  },
  <name>: {
    address: <string>,
    mtu: <string>,
    helper_addresses: array<strings>
    load_interval: <string>
  },
  ...
}

Returns:

  • (Hash<Symbol, Object>)

    Returns a hash object that represents all of the configured IP addresses found. If no IP addresses are configured, then an empty hash is returned.

See Also:



105
106
107
108
109
110
111
# File 'lib/rbeapi/api/ipinterfaces.rb', line 105

def getall
  interfaces = config.scan(/(?<=^interface\s).+/)
  interfaces.each_with_object({}) do |name, hsh|
    values = get name
    hsh[name] = values if values
  end
end

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

set_address configures a logical IP interface with an address. The address value must be in the form of A.B.C.D/E. If the enable keyword is false, then the interface address is negated using the config no keyword. If the default option is set to true, then the ip address # value is defaulted using the default keyword. The default keyword has precedence over the enable keyword if both options are specified.

Commands

interface <name>
  ip address <value>
  no ip address
  default ip address

Parameters:

  • name (String)

    The name of the interface to configure the address in the node. The name must be the full interface name.

  • opts (Hash) (defaults to: {})

    Optional keyword arguments.

Options Hash (opts):

  • value (String)

    The value to configure the address to for the specified interface name. The value must be in the form of A.B.C.D/E.

  • enable (Boolean)

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

  • default (Boolean)

    Configure the ip address value using the default keyword.

Returns:

  • (Boolean)

    Returns True if the command completed successfully.

Since:

  • eos_version 4.13.7M



263
264
265
266
# File 'lib/rbeapi/api/ipinterfaces.rb', line 263

def set_address(name, opts = {})
  cmds = command_builder('ip address', opts)
  configure_interface(name, cmds)
end

#set_helper_addresses(name, opts = {}) ⇒ Object

set_helper_addresses configures the list of helper addresses on the ip interface. An IP interface can have one or more helper addresses configured. If no value is provided, the helper address configuration is set using the no keyword. If the default option is specified and set to true, then the helper address values are defaulted using the default keyword.

Commands

interface <name>
  ip helper-address <value>
  no ip helper-address
  default ip helper-address

Parameters:

  • name (String)

    The name of the interface to configure the address in the node. The name must be the full interface name.

  • opts (Hash) (defaults to: {})

    Optional keyword arguments.

Options Hash (opts):

  • value (Array)

    The list of IP addresses to configure as helper address on the interface. The helper addresses must be valid addresses in the main interface’s subnet.

  • default (Boolean)

    Configure the ip helper address values using the default keyword.

Since:

  • eos_version 4.13.7M



333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'lib/rbeapi/api/ipinterfaces.rb', line 333

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

  if value
    unless value.is_a?(Array)
      raise ArgumentError, 'value must be an Array'
    end
  end

  case default
  when true
    cmds = 'default ip helper-address'
  when false
    cmds = ['no ip helper-address']
    value.each { |addr| cmds << "ip helper-address #{addr}" } if enable
  end
  configure_interface(name, cmds)
end

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

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

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

load-interval setting for. Valid values are between 5 and 600.

the interface using the default keyword.

Parameters:

  • name (String)

    The interface name to apply the configuration

  • opts (Hash) (defaults to: {})

    Optional keyword arguments.

Options Hash (opts):

  • value (String)

    Specifies the value to configure the

  • default (Boolean)

    Configures the load-interval value on

Returns:

  • (Boolean)

    Returns true if the command completed successfully.



370
371
372
373
# File 'lib/rbeapi/api/ipinterfaces.rb', line 370

def set_load_interval(name, opts = {})
  cmds = command_builder('load-interval', opts)
  configure_interface(name, cmds)
end

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

set_mtu configures the IP mtu value of the ip interface in the nodes configuration. If the enable option is false, then the ip mtu value is configured using the no keyword. If the default keyword option is provided and set to true then the ip mtu value is configured using the default keyword. The default keyword has precedence over the enable keyword if both options are specified.

Commands

interface <name>
  mtu <value>
  no mtu
  default mtu

Parameters:

  • name (String)

    The name of the interface to configure the address in the node. The name must be the full interface name.

  • opts (Hash) (defaults to: {})

    Optional keyword arguments.

Options Hash (opts):

  • value (String)

    The value to configure the IP MTU to in the nodes configuration. Valid values are in the range of 68 to 9214 bytes. The default is 1500 bytes.

  • enable (Boolean)

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

  • default (Boolean)

    Configure the ip mtu value using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



300
301
302
303
# File 'lib/rbeapi/api/ipinterfaces.rb', line 300

def set_mtu(name, opts = {})
  cmds = command_builder('mtu', opts)
  configure_interface(name, cmds)
end