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 =
''

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.

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



171
172
173
# File 'lib/rbeapi/api/ipinterfaces.rb', line 171

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.

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



192
193
194
# File 'lib/rbeapi/api/ipinterfaces.rb', line 192

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>
}

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.



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

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
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>: {...}
}

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:



90
91
92
93
94
95
96
# File 'lib/rbeapi/api/ipinterfaces.rb', line 90

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

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)

    Optional keyword arguments

Returns:

  • (Boolean)

    returns true if the command completed successfully



229
230
231
232
# File 'lib/rbeapi/api/ipinterfaces.rb', line 229

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.

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)

    Optional keyword arguments



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

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

  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_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.

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)

    Optional keyword arguments

Returns:

  • (Boolean)

    returns true if the command completed successfully



266
267
268
269
# File 'lib/rbeapi/api/ipinterfaces.rb', line 266

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