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) ⇒ Boolean

The add_address method assigns one virtual IPv4 address.

Parameters:

  • name (String)

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

  • value (string)

    The virtual router address to add.

Returns:

  • (Boolean)

    True if the commands succeeds otherwise False.



244
245
246
# File 'lib/rbeapi/api/varp.rb', line 244

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.

Examples:

{
  "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



131
132
133
134
135
136
# File 'lib/rbeapi/api/varp.rb', line 131

def get(name)
  config = get_block("^interface #{name}")
  return nil unless config
  response = parse_addresses(config)
  response
end

#getallnil, Hash<String, String>

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

Examples:

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

Returns:

  • (nil, Hash<String, String>)

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



156
157
158
159
160
161
162
163
164
# File 'lib/rbeapi/api/varp.rb', line 156

def getall
  interfaces = config.scan(/(?<=^interface\s)(Vl.+)$/)
  return nil unless interfaces

  interfaces.each_with_object({}) do |name, resp|
    data = get(name[0])
    resp[name.first] = data if data
  end
end

#remove_address(name, value) ⇒ Boolean

The remove_address method removes one virtual IPv4 address.

Parameters:

  • name (String)

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

  • value (string)

    The virtual router address to remove.

Returns:

  • (Boolean)

    True if the commands succeeds otherwise False.



258
259
260
261
# File 'lib/rbeapi/api/varp.rb', line 258

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.

rubocop:disable Metrics/MethodLength

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.



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/rbeapi/api/varp.rb', line 203

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

  if value
    unless value.is_a?(Array)
      raise ArgumentError, 'value must be an Array'
    end
  end

  case default
  when true
    cmds << 'default ip virtual-router address'
  when false
    cmds << 'no ip virtual-router address'
    if enable
      unless value
        raise ArgumentError,
              'no values for addresses provided'
      end
      value.each do |addr|
        cmds << "ip virtual-router address #{addr}"
      end
    end
  end
  configure(cmds)
end