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