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

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


169
170
171
# File 'lib/rbeapi/api/ipinterfaces.rb', line 169

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


190
191
192
# File 'lib/rbeapi/api/ipinterfaces.rb', line 190

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.


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

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:


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

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 no value is provided, 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 value 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


223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/rbeapi/api/ipinterfaces.rb', line 223

def set_address(name, opts = {})
  value = opts[:value]
  default = opts[:default] || false

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


308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/rbeapi/api/ipinterfaces.rb', line 308

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

  cmds = ["interface #{name}"]
  case default
  when true
    cmds << 'default ip helper-address'
  when false
    if value.nil?
      cmds << 'no ip helper-address'
    else
      cmds << 'no ip helper-address'
      value.each { |addr| cmds << "ip helper-address #{addr}" }
    end
  end
  configure cmds
end

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

set_mtu configures the IP mtu value of the ip interface in the nodes configuration. If the value is not provided, then the ip mtu value is configured using the no keyword. If the default keywork 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 value 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
270
271
272
273
274
275
276
277
278
# File 'lib/rbeapi/api/ipinterfaces.rb', line 266

def set_mtu(name, opts = {})
  value = opts[:value]
  default = opts[:default] || false

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