Class: Rbeapi::Api::BaseInterface

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

Overview

The BaseInterface class extends Entity and provides an implementation that is common to all interfaces configured in EOS.

Constant Summary collapse

DEFAULT_INTF_DESCRIPTION =
''

Instance Attribute Summary

Attributes inherited from Entity

#config, #error, #node

Instance Method Summary collapse

Methods inherited from Entity

#configure, #get_block, #initialize, instance

Constructor Details

This class inherits a constructor from Rbeapi::Api::Entity

Instance Method Details

#create(value) ⇒ Boolean

create will create a new interface resource in the node's current configuration with the specified interface name. If the create method is called and the interface already exists, this method will return successful

Parameters:

  • :value (String)

    The interface name to create on the node. The interface name must be the full interface identifier (ie Loopback, not Lo)

Returns:

  • (Boolean)

    returns true if the command completed succesfully


180
181
182
# File 'lib/rbeapi/api/interfaces.rb', line 180

def create(value)
  configure("interface #{value}")
end

#default(value) ⇒ Boolean

default will configure the interface using the default keyword. For virtual interfaces this is equivalent to deleting the interface. For physical interfaces, the entire interface configuration will be set to defaults.

Parameters:

  • :value (String)

    The interface name to default in the node. The interface name must be the full interface identifier (ie Loopback, not Lo)

Returns:

  • (Boolean)

    returns true if the command completed successfully


220
221
222
# File 'lib/rbeapi/api/interfaces.rb', line 220

def default(value)
  configure("default interface #{value}")
end

#delete(value) ⇒ Boolean

delete will delete an existing interface resource in the node's current configuration with the specified interface name. If the delete method is called and interface does not exist, this method will return successful

Parameters:

  • :value (String)

    The interface name to delete from the node. The interface name must be the full interface identifier (ie Loopback, no Lo)

Returns:

  • (Boolean)

    returns true if the command completed successfully


200
201
202
# File 'lib/rbeapi/api/interfaces.rb', line 200

def delete(value)
  configure("no interface #{value}")
end

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

get returns the specified interface resource hash that represents the node's current interface configuration. The BaseInterface class provides all the set of attributres that are common to all interfaces in EOS. This method will return an interface type of generic

Examples:

{
  name: <string>
  type: 'generic'
  description: <string>
  shutdown: [true, false]
}

Parameters:

  • :name (String)

    The name of the interface to return from the running-configuration

Returns:

  • (nil, Hash<String, Object>)

    Returns a hash of the interface properties if the interface name was found in the running configuration. If the interface was not found, nil is returned


122
123
124
125
126
127
128
129
130
# File 'lib/rbeapi/api/interfaces.rb', line 122

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

  response = { name: name, type: 'generic' }
  response.merge!(parse_description(config))
  response.merge!(parse_shutdown(config))
  response
end

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

set_description configures the description value for the specified interface name in the nodes running configuration. If the value is not provided in the opts keyword hash then the description value is negated using the no keyword. If the default keyword is set to true, then the description value is defaulted using the default keyword. The default keyword takes precedence over the value keyword if both are provided.

Parameters:

  • :name (String)

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

  • :opts (hash)

    Optional keyword arguments

Returns:

  • (Boolean)

    returns true if the command completed successfully


253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/rbeapi/api/interfaces.rb', line 253

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

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

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

set_shutdown configures the adminstrative state of the specified interface in the node. If the value is true, then the interface is adminstratively disabled. If the value is false, then the interface is adminstratively enabled. If no value is provided, then the interface is configured with the no keyword which is equivalent to false. If the default keyword is set to true, then the interface shutdown value is configured using the default keyword. The default keyword takes precedence over the value keyword if both are provided.

Parameters:

  • :name (String)

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

  • :opts (hash)

    Optional keyword arguments

Returns:

  • (Boolean)

    returns true if the command completed successfully


298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/rbeapi/api/interfaces.rb', line 298

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

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