class Rbeapi::Api::VarpInterfaces
The VarpInterfaces
class provides an instance for working with the global VARP interface configuration of the node.
Public Instance Methods
The add_address
method assigns one virtual IPv4 address.
@param name [String] The name of the interface. The
name argument must be the full interface name. Valid interfaces are restricted to VLAN interfaces.
@param value [string] The virtual router address to add.
@return [Boolean] True if the commands succeeds otherwise False.
# File lib/rbeapi/api/varp.rb, line 244 def add_address(name, value) configure(["interface #{name}", "ip virtual-router address #{value}"]) end
Returns a single VARP interface configuration.
@example
{ "addresses": array<string> }
@param name [String] The interface name to return the configuration
values for. This must be the full interface identifier.
@return [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
# 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
Returns the collection of MLAG interfaces as a hash index by the interface name.
@example
{ <name>: { addresses: <array> }, <name>: { addresses: <array> }, ... }
@return [nil, Hash<String, String>] A Ruby hash that represents the
MLAG interface configuration. A nil object is returned if no interfaces are configured.
# 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
The remove_address
method removes one virtual IPv4 address.
@param name [String] The name of the interface. The
name argument must be the full interface name. Valid interfaces are restricted to VLAN interfaces.
@param value [string] The virtual router address to remove.
@return [Boolean] True if the commands succeeds otherwise False.
# File lib/rbeapi/api/varp.rb, line 258 def remove_address(name, value) configure(["interface #{name}", "no ip virtual-router address #{value}"]) end
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.
@param name [String] The name of the interface. The
name argument must be the full interface name. Valid interfaces are restricted to VLAN interfaces.
@param opts [Hash] The configuration parameters.
@option opts value [Array] Array of IPv4 addresses to add to
the virtual router.
@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] True if the commands succeeds otherwise False. rubocop:disable Metrics/MethodLength
# 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
Private Instance Methods
parse_addresses
parses ip virtual-router address 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 176 def parse_addresses(config) addrs = config.scan(/(?<=\s{3}ip\svirtual-router\saddress\s).+$/) { addresses: addrs } end