Class: Rbeapi::Api::Varp

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

Overview

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

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

#getHash

Returns the global VARP configuration from the node

Example

{
  "mac_address": <string>,
  "interfaces": {...}
}

Returns:

  • (Hash)

    A Ruby hash object that provides the Varp settings as key / value pairs.


54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rbeapi/api/varp.rb', line 54

def get
  response = {}

  regex = %r{
    (?<=^ip\svirtual-router\smac-address\s)
    ((?:[a-f0-9]{2}:){5}[a-f0-9]{2})$
  }x

  mdata = regex.match(config)
  response['mac_address'] = mdata.nil? ? '' : mdata[1]
  response['interfaces'] = interfaces.getall
  response
end

#interfacesObject


68
69
70
71
72
# File 'lib/rbeapi/api/varp.rb', line 68

def interfaces
  return @interfaces if @interfaces
  @interfaces = VarpInterfaces.new(node)
  @interfaces
end

#set_mac_address(opts = {}) ⇒ Boolean

Configure the VARP virtual-router mac-address value

Parameters:

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

    The configuration parameters

Options Hash (opts):

  • :value (string)

    The value to set the mac-address to

  • :default (Boolean)

    The value should be set to default

Returns:

  • (Boolean)

    returns true if the command completed successfully


82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rbeapi/api/varp.rb', line 82

def set_mac_address(opts = {})
  value = opts[:value]
  default = opts[:default] || false

  case default
  when true
    cmds = ['default ip virtual-router mac-address']
  when false
    cmds = (value ? "ip virtual-router mac-address #{value}" : \
                    'no ip virtual-router mac-address')
  end
  configure(cmds)
end