Class: Rbeapi::Api::Vrrp

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

Overview

The Vrrp class manages the set of virtual routers. rubocop:disable Metrics/ClassLength

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, instance

Constructor Details

#initialize(node) ⇒ Vrrp

Returns a new instance of Vrrp.



44
45
46
# File 'lib/rbeapi/api/vrrp.rb', line 44

def initialize(node)
  super(node)
end

Instance Method Details

#create(name, vrid, opts = {}) ⇒ Boolean

create will create a new virtual router ID resource for the interface in the nodes current. If the create method is called and the virtual router ID already exists for the interface, this method will still return true. Create takes optional parameters, but at least one parameter needs to be set or the command will fail.

Commands

interface <name>
  vrrp <vrid> ...

rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, rubocop:disable Metrics/PerceivedComplexity

Parameters:

  • name (String)

    The layer 3 interface name.

  • vrid (String)

    The virtual router id.

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

    Optional keyword arguments.

Options Hash (opts):

  • enable (Boolean)

    Enable the virtual router.

  • primary_ip (String)

    The primary IPv4 address.

  • priority (Integer)

    The priority setting for a virtual router.

  • description (String)

    Associates a text string to a virtual router.

  • secondary_ip (Array<String>)

    The secondary IPv4 address to the specified virtual router.

  • ip_version (Integer)

    Configures the VRRP version for the VRRP router.

  • timers_advertise (Integer)

    The interval between successive advertisement messages that the switch sends to routers in the specified virtual router ID.

  • mac_addr_adv_interval (Integer)

    Specifies interval in seconds between advertisement packets sent to VRRP group members.

  • preempt (Boolean)

    A virtual router preempt mode setting. When preempt mode is enabled, if the switch has a higher priority it will preempt the current master virtual router. When preempt mode is disabled, the switch can become the master virtual router only when a master virtual router is not present on the subnet, regardless of priority settings.

  • preempt_delay_min (Integer)

    Interval in seconds between VRRP preempt event and takeover. Minimum delays takeover when VRRP is fully implemented.

  • preempt_delay_reload (Integer)

    Interval in seconds between VRRP preempt event and takeover. Reload delays takeover after initialization following a switch reload.

  • delay_reload (Integer)

    Delay between system reboot and VRRP initialization.

  • track (Array<Hash>)

    The track hash contains the name of an interface to track, the action to take on state-change of the tracked interface, and the amount to decrement the priority.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Raises:

  • (ArgumentError)

Since:

  • eos_version 4.13.7M



515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
# File 'lib/rbeapi/api/vrrp.rb', line 515

def create(name, vrid, opts = {})
  raise ArgumentError, 'create has no options set' if opts.empty?

  if opts[:secondary_ip] && !opts[:secondary_ip].is_a?(Array)
    raise ArgumentError, 'opts secondary_ip must be an Array'
  end

  if opts[:track] && !opts[:track].is_a?(Array)
    raise ArgumentError, 'opts track must be an Array'
  end

  cmds = []
  if opts.key?(:enable)
    cmds << if opts[:enable]
              "no vrrp #{vrid} shutdown"
            else
              "vrrp #{vrid} shutdown"
            end
  end
  cmds << "vrrp #{vrid} ip #{opts[:primary_ip]}" if opts.key?(:primary_ip)
  if opts.key?(:priority)
    cmds << "vrrp #{vrid} priority #{opts[:priority]}"
  end
  if opts.key?(:description)
    cmds << "vrrp #{vrid} description #{opts[:description]}"
  end
  if opts.key?(:secondary_ip)
    cmds += build_secondary_ip_cmd(name, vrid, opts[:secondary_ip])
  end
  if opts.key?(:ip_version)
    cmds << "vrrp #{vrid} ip version #{opts[:ip_version]}"
  end
  if opts.key?(:timers_advertise)
    cmds << "vrrp #{vrid} timers advertise #{opts[:timers_advertise]}"
  end
  if opts.key?(:mac_addr_adv_interval)
    val = opts[:mac_addr_adv_interval]
    cmds << "vrrp #{vrid} mac-address advertisement-interval #{val}"
  end
  if opts.key?(:preempt)
    cmds << if opts[:preempt]
              "vrrp #{vrid} preempt"
            else
              "no vrrp #{vrid} preempt"
            end
  end
  if opts.key?(:preempt_delay_min)
    val = opts[:preempt_delay_min]
    cmds << "vrrp #{vrid} preempt delay minimum #{val}"
  end
  if opts.key?(:preempt_delay_reload)
    val = opts[:preempt_delay_reload]
    cmds << "vrrp #{vrid} preempt delay reload #{val}"
  end
  if opts.key?(:delay_reload)
    cmds << "vrrp #{vrid} delay reload #{opts[:delay_reload]}"
  end
  cmds += build_tracks_cmd(name, vrid, opts[:track]) if opts.key?(:track)
  configure_interface(name, cmds)
end

#default(name, vrid) ⇒ Boolean

default will default the virtual router ID on the interface from the nodes current running configuration. This command has the same effect as deleting the virtual router id from the interface in the nodes running configuration. If the default method is called and the virtual router id does not exist on the interface, this method will succeed.

Commands

interface <name>
  default vrrp <vrid>

Parameters:

  • name (String)

    The layer 3 interface name.

  • vrid (Integer)

    The virtual router ID.

Returns:

  • (Boolean)

    Returns true if the command complete successfully.

Since:

  • eos_version 4.13.7M



618
619
620
# File 'lib/rbeapi/api/vrrp.rb', line 618

def default(name, vrid)
  configure_interface(name, "default vrrp #{vrid}")
end

#delete(name, vrid) ⇒ Boolean

delete will delete the virtual router ID on the interface from the nodes current running configuration. If the delete method is called and the virtual router id does not exist on the interface, this method will succeed.

Commands

interface <name>
  no vrrp <vrid>

Parameters:

  • name (String)

    The layer 3 interface name.

  • vrid (Integer)

    The virtual router ID.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



595
596
597
# File 'lib/rbeapi/api/vrrp.rb', line 595

def delete(name, vrid)
  configure_interface(name, "no vrrp #{vrid}")
end

#get(name) ⇒ nil, Hash<Symbol, Object>

get returns the all the virtual router IPs for the given layer 3 interface name from the nodes current configuration.

rubocop:disable Metrics/MethodLength

Examples:

{
  1: {
       enable: <True|False>
       primary_ip: <String>
       priority: <Integer>
       description: <String>
       secondary_ip: [ <ip_string1>, <ip_string2> ]
       ip_version: <Integer>
       timers_advertise: <Integer>
       mac_addr_adv_interval: <Integer>
       preempt: <True|False>
       preempt_delay_min: <Integer>
       preempt_delay_reload: <Integer>
       delay_reload: <Integer>
       track: [
         { name: 'Ethernet3', action: 'decrement', amount: 33 },
         { name: 'Ethernet2', action: 'decrement', amount: 22 },
         { name: 'Ethernet2', action: 'shutdown' }
       ]
     }
}

Parameters:

  • name (String)

    The layer 3 interface name.

Returns:

  • (nil, Hash<Symbol, Object>)

    Returns the VRRP resource as a Hash with the virtual router ID as the key. If the interface name does not exist then a nil object is returned.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/rbeapi/api/vrrp.rb', line 82

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

  response = {}

  vrids = config.scan(/^\s+(?:no |)vrrp (\d+)/)
  vrids.uniq.each do |vrid_arr|
    # Parse the vrrp configuration for the vrid(s) in the list
    entry = {}
    vrid = vrid_arr[0]
    entry.merge!(parse_delay_reload(config, vrid))
    entry.merge!(parse_description(config, vrid))
    entry.merge!(parse_enable(config, vrid))
    entry.merge!(parse_ip_version(config, vrid))
    entry.merge!(parse_mac_addr_adv_interval(config, vrid))
    entry.merge!(parse_preempt(config, vrid))
    entry.merge!(parse_preempt_delay_min(config, vrid))
    entry.merge!(parse_preempt_delay_reload(config, vrid))
    entry.merge!(parse_primary_ip(config, vrid))
    entry.merge!(parse_priority(config, vrid))
    entry.merge!(parse_secondary_ip(config, vrid))
    entry.merge!(parse_timers_advertise(config, vrid))
    entry.merge!(parse_track(config, vrid))

    response[vrid.to_i] = entry unless entry.nil?
  end
  response
end

#getallnil, Hash<Symbol, Object>

getall returns the collection of virtual router IPs for all the layer 3 interfaces from the nodes running configuration as a hash. The resource collection hash is keyed by the ACL name.

}

Examples:

{
  'Vlan100': {
        1: { data },
      250: { data },
  },
  'Vlan200': {
        2: { data },
      250: { data },
  }

Returns:

  • (nil, Hash<Symbol, Object>)

    Returns a hash that represents the entire virtual router IPs collection for all the layer 3 interfaces from the nodes running configuration. If there are no virtual routers configured, this method will return an empty hash.



133
134
135
136
137
138
139
# File 'lib/rbeapi/api/vrrp.rb', line 133

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

#set_delay_reload(name, vrid, opts = {}) ⇒ Boolean

set_delay_reload sets the delay between system reboot and VRRP initialization for the virtual router.

Commands

interface <name>
  {no | default} vrrp <vrid> delay reload <secs>

Parameters:

  • name (String)

    The layer 3 interface name.

  • vrid (Integer)

    The virtual router ID.

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

    Optional keyword arguments

Options Hash (opts):

  • value (String)

    The delay reload value.

  • enable (Boolean)

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

  • default (Boolean)

    Configure the delay reload value using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command complete successfully.



1009
1010
1011
1012
# File 'lib/rbeapi/api/vrrp.rb', line 1009

def set_delay_reload(name, vrid, opts = {})
  cmd = "vrrp #{vrid} delay reload"
  configure_interface(name, command_builder(cmd, opts))
end

#set_description(name, vrid, opts = {}) ⇒ Boolean

set_description sets the description for a virtual router.

Commands

interface <name>
  {no | default} vrrp <vrid> description <description>

Parameters:

  • name (String)

    The layer 3 interface name.

  • vrid (Integer)

    The virtual router ID.

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

    Optional keyword arguments.

Options Hash (opts):

  • value (String)

    The description value.

  • enable (Boolean)

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

  • default (Boolean)

    Configure the description using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command complete successfully.



729
730
731
732
# File 'lib/rbeapi/api/vrrp.rb', line 729

def set_description(name, vrid, opts = {})
  cmd = "vrrp #{vrid} description"
  configure_interface(name, command_builder(cmd, opts))
end

#set_ip_version(name, vrid, opts = {}) ⇒ Boolean

set_ip_version sets the VRRP version for a virtual router.

Commands

interface <name>
  {no | default} vrrp <vrid> ip version <version>

Parameters:

  • name (String)

    The layer 3 interface name.

  • vrid (Integer)

    The virtual router ID.

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

    Optional keyword arguments.

Options Hash (opts):

  • value (String)

    The VRRP version.

  • enable (Boolean)

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

  • default (Boolean)

    Configure the VRRP version using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command complete successfully.



832
833
834
835
# File 'lib/rbeapi/api/vrrp.rb', line 832

def set_ip_version(name, vrid, opts = {})
  cmd = "vrrp #{vrid} ip version"
  configure_interface(name, command_builder(cmd, opts))
end

#set_mac_addr_adv_interval(name, vrid, opts = {}) ⇒ Boolean

set_mac_addr_adv_interval sets the interval in seconds between advertisement packets sent to VRRP group members for the specified virtual router ID.

Commands

interface <name>
  {no | default} vrrp <vrid> mac-address advertisement-interval <secs>

Parameters:

  • name (String)

    The layer 3 interface name.

  • vrid (Integer)

    The virtual router ID.

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

    Optional keyword arguments

Options Hash (opts):

  • value (String)

    The mac address advertisement interval value in seconds.

  • enable (Boolean)

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

  • default (Boolean)

    Configure the timer advertise value using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command complete successfully.



891
892
893
894
# File 'lib/rbeapi/api/vrrp.rb', line 891

def set_mac_addr_adv_interval(name, vrid, opts = {})
  cmd = "vrrp #{vrid} mac-address advertisement-interval"
  configure_interface(name, command_builder(cmd, opts))
end

#set_preempt(name, vrid, opts = {}) ⇒ Boolean

set_preempt sets the virtual router’s preempt mode setting. When preempt mode is enabled, if the switch has a higher priority it will preempt the current master virtual router. When preempt mode is disabled, the switch can become the master virtual router only when a master virtual router is not present on the subnet, regardless of priority settings.

Commands

interface <name>
  {no | default} vrrp <vrid> preempt

Parameters:

  • name (String)

    The layer 3 interface name.

  • vrid (Integer)

    The virtual router ID.

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

    Optional keyword arguments.

Options Hash (opts):

  • enable (Boolean)

    If enable is true then the virtual router preempt mode is administratively enabled for the interface and if enable is false then the virtual router preempt mode is administratively disabled for the interface. Default is true.

  • default (Boolean)

    Configure the timer advertise value using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command complete successfully.



923
924
925
926
927
# File 'lib/rbeapi/api/vrrp.rb', line 923

def set_preempt(name, vrid, opts = {})
  raise 'set_preempt has the value option set' if opts[:value]
  cmd = "vrrp #{vrid} preempt"
  configure_interface(name, command_builder(cmd, opts))
end

#set_preempt_delay_min(name, vrid, opts = {}) ⇒ Boolean

set_preempt_delay_min sets the minimum time in seconds for the virtual router to wait before taking over the active role.

Commands

interface <name>
  {no | default} vrrp <vrid> preempt delay minimum <secs>

Parameters:

  • name (String)

    The layer 3 interface name.

  • vrid (Integer)

    The virtual router ID.

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

    Optional keyword arguments.

Options Hash (opts):

  • value (String)

    The preempt delay minimum value.

  • enable (Boolean)

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

  • default (Boolean)

    Configure the preempt delay minimum value using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command complete successfully.



952
953
954
955
# File 'lib/rbeapi/api/vrrp.rb', line 952

def set_preempt_delay_min(name, vrid, opts = {})
  cmd = "vrrp #{vrid} preempt delay minimum"
  configure_interface(name, command_builder(cmd, opts))
end

#set_preempt_delay_reload(name, vrid, opts = {}) ⇒ Boolean

set_preempt_delay_reload sets the preemption delay after a reload only. This delay period applies only to the first interface-up event after the virtual router has reloaded.

Commands

interface <name>
  {no | default} vrrp <vrid> preempt delay reload <secs>

Parameters:

  • name (String)

    The layer 3 interface name.

  • vrid (Integer)

    The virtual router ID.

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

    Optional keyword arguments.

Options Hash (opts):

  • value (String)

    The preempt delay reload value.

  • enable (Boolean)

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

  • default (Boolean)

    :default Configure the preempt delay reload value using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command complete successfully.



981
982
983
984
# File 'lib/rbeapi/api/vrrp.rb', line 981

def set_preempt_delay_reload(name, vrid, opts = {})
  cmd = "vrrp #{vrid} preempt delay reload"
  configure_interface(name, command_builder(cmd, opts))
end

#set_primary_ip(name, vrid, opts = {}) ⇒ Boolean

set_primary_ip sets the primary IP address for the virtual router.

Commands

interface <name>
  {no | default} vrrp <vrid> ip <A.B.C.D>

Parameters:

  • name (String)

    The layer 3 interface name.

  • vrid (Integer)

    The virtual router ID.

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

    Optional keyword arguments.

Options Hash (opts):

  • value (String)

    The primary IPv4 address.

  • enable (Boolean)

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

  • default (Boolean)

    Configure the primary IP address using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command complete successfully.



675
676
677
678
# File 'lib/rbeapi/api/vrrp.rb', line 675

def set_primary_ip(name, vrid, opts = {})
  cmd = "vrrp #{vrid} ip"
  configure_interface(name, command_builder(cmd, opts))
end

#set_priority(name, vrid, opts = {}) ⇒ Boolean

set_priority sets the priority for a virtual router.

Commands

interface <name>
  {no | default} vrrp <vrid> priority <priority>

Parameters:

  • name (String)

    The layer 3 interface name.

  • vrid (Integer)

    The virtual router ID.

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

    Optional keyword arguments.

Options Hash (opts):

  • value (String)

    The priority value.

  • enable (Boolean)

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

  • default (Boolean)

    Configure the priority using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command complete successfully.



702
703
704
705
# File 'lib/rbeapi/api/vrrp.rb', line 702

def set_priority(name, vrid, opts = {})
  cmd = "vrrp #{vrid} priority"
  configure_interface(name, command_builder(cmd, opts))
end

#set_secondary_ip(name, vrid, ip_addrs) ⇒ Boolean

set_secondary_ips configures the set of secondary IP addresses associated with the virtual router. The ip_addrs value passed should be an array of IP Addresses. This method will remove secondary IP addresses that are currently set for the virtual router but not included in the ip_addrs array value passed in. The method will then add secondary IP addresses that are not currently set for the virtual router but are included in the ip_addrs array value passed in.

Commands

interface <name>
  {no} vrrp <vrid> ip <A.B.C.D> secondary

Parameters:

  • name (String)

    The layer 3 interface name.

  • vrid (Integer)

    The virtual router ID.

  • ip_addrs (Array<String>)

    Array of secondary IPv4 address. An empty array will remove all secondary IPv4 addresses set for the virtual router on the specified layer 3 interface.

Returns:

  • (Boolean)

    Returns true if the command complete successfully.



804
805
806
807
808
# File 'lib/rbeapi/api/vrrp.rb', line 804

def set_secondary_ip(name, vrid, ip_addrs)
  cmds = build_secondary_ip_cmd(name, vrid, ip_addrs)
  return true if cmds.empty?
  configure_interface(name, cmds)
end

#set_shutdown(name, vrid, opts = {}) ⇒ Boolean

set_shutdown enables and disables the virtual router.

Commands

interface <name>
  {no | default} vrrp <vrid> shutdown

Parameters:

  • name (String)

    The layer 3 interface name.

  • vrid (Integer)

    The virtual router ID.

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

    Optional keyword arguments.

Options Hash (opts):

  • enable (Boolean)

    If enable is true then the virtual router is administratively enabled for the interface and if enable is false then the virtual router is administratively disabled for the interface. Default is true.

  • default (Boolean)

    Configure shutdown using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command complete successfully.



644
645
646
647
648
649
650
651
# File 'lib/rbeapi/api/vrrp.rb', line 644

def set_shutdown(name, vrid, opts = {})
  raise 'set_shutdown has the value option set' if opts[:value]
  # Shutdown semantics are opposite of enable semantics so invert enable.
  enable = opts.fetch(:enable, true)
  opts[:enable] = !enable
  cmd = "vrrp #{vrid} shutdown"
  configure_interface(name, command_builder(cmd, opts))
end

#set_timers_advertise(name, vrid, opts = {}) ⇒ Boolean

set_timers_advertise sets the interval between successive advertisement messages that the switch sends to routers in the specified virtual router ID.

Commands

interface <name>
  {no | default} vrrp <vrid> timers advertise <secs>

Parameters:

  • name (String)

    The layer 3 interface name.

  • vrid (Integer)

    The virtual router ID.

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

    Optional keyword arguments.

Options Hash (opts):

  • value (String)

    The timer value in seconds.

  • enable (Boolean)

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

  • default (Boolean)

    Configure the timer advertise value using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command complete successfully.



861
862
863
864
# File 'lib/rbeapi/api/vrrp.rb', line 861

def set_timers_advertise(name, vrid, opts = {})
  cmd = "vrrp #{vrid} timers advertise"
  configure_interface(name, command_builder(cmd, opts))
end

#set_tracks(name, vrid, tracks) ⇒ Boolean

set_tracks configures the set of track settings associated with the virtual router. The tracks value passed should be an array of hashes, each hash containing a track entry. This method will remove tracks that are currently set for the virtual router but not included in the tracks array value passed in. The method will then add tracks that are not currently set for the virtual router but are included in the tracks array value passed in.

Commands

interface <name>
  {no} vrrp <vrid> track <name> <action> [<amount>]

Parameters:

  • name (String)

    The layer 3 interface name.

  • vrid (Integer)

    The virtual router ID.

  • tracks (Array<Hash>)

    Array of a hash of track information. Hash format: { name: ‘Eth2’, action: ‘decrement’, amount: 33 }, An empty array will remove all tracks set for the virtual router on the specified layer 3 interface.

Returns:

  • (Boolean)

    Returns true if the command complete successfully.



1115
1116
1117
1118
1119
# File 'lib/rbeapi/api/vrrp.rb', line 1115

def set_tracks(name, vrid, tracks)
  cmds = build_tracks_cmd(name, vrid, tracks)
  return true if cmds.empty?
  configure_interface(name, cmds)
end