Class: Rbeapi::Api::Vrrp
Overview
The Vrrp class manages the set of virtual routers. rubocop:disable Metrics/ClassLength
Instance Attribute Summary
Attributes inherited from Entity
Instance Method Summary collapse
-
#create(name, vrid, opts = {}) ⇒ Boolean
create will create a new virtual router ID resource for the interface in the nodes current.
-
#default(name, vrid) ⇒ Boolean
default will default the virtual router ID on the interface from the nodes current running configuration.
-
#delete(name, vrid) ⇒ Boolean
delete will delete the virtual router ID on the interface from the nodes current running configuration.
-
#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.
-
#getall ⇒ nil, 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.
-
#initialize(node) ⇒ Vrrp
constructor
A new instance of Vrrp.
-
#set_delay_reload(name, vrid, opts = {}) ⇒ Boolean
set_delay_reload sets the delay between system reboot and VRRP initialization for the virtual router.
-
#set_description(name, vrid, opts = {}) ⇒ Boolean
set_description sets the description for a virtual router.
-
#set_ip_version(name, vrid, opts = {}) ⇒ Boolean
set_ip_version sets the VRRP version for a virtual router.
-
#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.
-
#set_preempt(name, vrid, opts = {}) ⇒ Boolean
set_preempt sets the virtual router’s preempt mode setting.
-
#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.
-
#set_preempt_delay_reload(name, vrid, opts = {}) ⇒ Boolean
set_preempt_delay_reload sets the preemption delay after a reload only.
-
#set_primary_ip(name, vrid, opts = {}) ⇒ Boolean
set_primary_ip sets the primary IP address for the virtual router.
-
#set_priority(name, vrid, opts = {}) ⇒ Boolean
set_priority sets the priority for a virtual router.
-
#set_secondary_ip(name, vrid, ip_addrs) ⇒ Boolean
set_secondary_ips configures the set of secondary IP addresses associated with the virtual router.
-
#set_shutdown(name, vrid, opts = {}) ⇒ Boolean
set_shutdown enables and disables the virtual router.
-
#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.
-
#set_tracks(name, vrid, tracks) ⇒ Boolean
set_tracks configures the set of track settings associated with the virtual router.
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
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>
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>
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
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 |
#getall ⇒ nil, 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.
}
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>
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>
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>
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>
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
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>
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>
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>
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>
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
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
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>
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>]
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 |