class Rbeapi::Api::Varp

The Varp class provides an instance for working with the global VARP configuration of the node.

Public Instance Methods

get() click to toggle source

Returns the global VARP configuration from the node.

@example

{
  mac_address: <string>,
  interfaces: {
    <name>: {
      addresses: <array>
    },
    <name>: {
      addresses: <array>
    },
    ...
  }
}

@return [Hash] A Ruby hash object that provides the Varp settings as

key / value pairs.
# File lib/rbeapi/api/varp.rb, line 63
def get
  response = {}
  response.merge!(parse_mac_address(config))
  response[:interfaces] = interfaces.getall
  response
end
interfaces() click to toggle source
# File lib/rbeapi/api/varp.rb, line 88
def interfaces
  return @interfaces if @interfaces
  @interfaces = VarpInterfaces.new(node)
  @interfaces
end
set_mac_address(opts = {}) click to toggle source

Configure the VARP virtual-router mac-address value.

@param opts [Hash] The configuration parameters.

@option opts value [string] The value to set the mac-address to.

@option opts enable [Boolean] If false then the command is

negated. Default is true.

@option opts default [Boolean] The value should be set to default.

@return [Boolean] Returns true if the command completed successfully.

# File lib/rbeapi/api/varp.rb, line 107
def set_mac_address(opts = {})
  cmd = command_builder('ip virtual-router mac-address', opts)
  configure(cmd)
end

Private Instance Methods

parse_mac_address(config) click to toggle source

parse_mac_address parses mac-address values from the provided config.

@api private

@param config [String] The configuration block returned

from the node's running configuration.

@return [Hash<Symbol, Object>] Returns the resource hash attribute.

# File lib/rbeapi/api/varp.rb, line 79
def parse_mac_address(config)
  # ip virtual-router mac-address value will always
  #   be stored in aa:bb:cc:dd:ee:ff format.
  regex = /mac-address ((?:[a-f0-9]{2}:){5}[a-f0-9]{2})$/
  mdata = regex.match(config)
  { mac_address: mdata.nil? ? '' : mdata[1] }
end