Method: Rbeapi::Api::Vrrp#create

Defined in:
lib/rbeapi/api/vrrp.rb

#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

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.

Raises:

Since:

  • eos_version 4.13.7M

Parameters:

  • The layer 3 interface name.

  • The virtual router id.

  • (defaults to: {})

    Optional keyword arguments.

Returns:

  • Returns true if the command completed successfully.



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