Class: Rbeapi::Api::VarpInterfaces

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

Overview

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

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

#add_address(name, value) ⇒ Object



175
176
177
# File 'lib/rbeapi/api/varp.rb', line 175

def add_address(name, value)
  configure(["interface #{name}", "ip virtual-router address #{value}"])
end

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

Returns a single VARP interface configuration

Example

{
  "name": <string>,
  "addresses": array<string>
}

Parameters:

  • :name (String)

    The interface name to return the configuration values for. This must be the full interface identifier.

Returns:

  • (nil, Hash<String, String>)

    A Ruby hash that represents the VARP interface configuration. A nil object is returned if the specified interface is not configured



108
109
110
111
112
113
# File 'lib/rbeapi/api/varp.rb', line 108

def get(name)
  config = get_block("^interface #{name}")
  return nil unless config
  addrs = config.scan(/(?<=\s{3}ip\svirtual-router\saddress\s).+$/)
  { 'addresses' => addrs }
end

#getallnil, Hash<String, String>

Returns the collection of MLAG interfaces as a hash index by the interface name

Example

{
  <name>: {...},
  <name>: {...}
}

Returns:

  • (nil, Hash<String, String>)

    A Ruby hash that represents the MLAG interface configuration. A nil object is returned if no interfaces are configured.



128
129
130
131
132
133
134
# File 'lib/rbeapi/api/varp.rb', line 128

def getall
  interfaces = config.scan(/(?<=^interface\s)(Vl.+)$/)
  interfaces.first.each_with_object({}) do |name, resp|
    data = get(name)
    resp[name] = data if data
  end
end

#remove_address(name, value) ⇒ Object



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

def remove_address(name, value)
  configure(["interface #{name}",
             "no ip virtual-router address #{value}"])
end

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

The set_addresses method assigns one or more virtual IPv4 address to the specified VLAN interface. All existing addresses are removed before the ones in value are added.

Parameters:

  • :name (String)

    The name of the interface. The name argument must be the full interface name. Valid interfaces are restricted to VLAN interfaces

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

    The configuration parameters

Options Hash (opts):

  • :value (Array)

    Array of IPv4 addresses to add to the virtual router.

  • :enable (Boolean)

    If false then the command is negated. Default is true.

  • :default (Boolean)

    The value should be set to default

Returns:

  • (Boolean)

    True if the commands succeeds otherwise False



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/rbeapi/api/varp.rb', line 152

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

  case default
  when true
    configure(["interface #{name}", 'default ip virtual-router address'])
  when false
    get(name)['addresses'].each do |addr|
      result = remove_address(name, addr)
      return result unless result
    end
    if enable
      value.each do |addr|
        result = add_address(name, addr)
        return result unless result
      end
    end
  end
  true
end