Module: EtcdTools::Watchdog::Vip

Included in:
VipWatchdog
Defined in:
lib/etcd-tools/watchdog/vip.rb

Instance Method Summary collapse

Instance Method Details

#got_vip?Boolean

check whether VIP is assigned to me <IMPLEMENTED>

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/etcd-tools/watchdog/vip.rb', line 52

def got_vip?
  cmd = [ iproute,
          'address',
          'show',
          'label',
          "#{@config[:parameters][:interface]}-vip",
          '|',
          'grep',
          '-q',
          "#{@config[:parameters][:interface]}-vip"
        ]
  debug "CMD #{cmd.join(' ')}"
  if system(cmd.join(' '))
    return true
  else
    return false
  end
end

#vip_alive?(icmp) ⇒ Boolean

check reachability of VIP by ICMP echo <— REWORK

Returns:

  • (Boolean)


73
74
75
76
# File 'lib/etcd-tools/watchdog/vip.rb', line 73

def vip_alive?(icmp)
  (1..@config[:parameters][:icmp_count]).each { return true if icmp.ping }
  return false
end

#vip_dup?Boolean

check whether the IP is registered anywhere

Returns:

  • (Boolean)


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/etcd-tools/watchdog/vip.rb', line 80

def vip_dup?
  cmd_arp = [ arp, '-d', @config[:parameters][:vip], '>/dev/null 2>&1' ]
  cmd_arping = [  arping, '-D', '-q',
                  '-c', @config[:parameters][:arping_count],
                  '-w', @config[:parameters][:arping_wait],
                  '-I', @config[:parameters][:interface],
                  @config[:parameters][:vip] ]
  debug "CMD #{cmd_arp.join(' ')}"
  system(cmd_arp.join(' '))
  debug "CMD #{cmd_arping.join(' ')}"
  if system(cmd_arping.join(' '))
    return false
  else
    return true
  end
end

#vip_handle!(leader) ⇒ Object

add or remove VIP on interface <IMPLEMENTED>



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/etcd-tools/watchdog/vip.rb', line 6

def vip_handle!(leader)
  ip = IPAddr.new(@config[:parameters][:vip])
  mask = @config[:parameters][:mask]
  cmd = [ iproute,
          'address',
          '',
          "#{ip}/#{mask}",
          'dev',
          @config[:parameters][:interface],
          'label',
          @config[:parameters][:interface] + '-vip',
          '>/dev/null 2>&1'
        ]
  case leader
  when true
    cmd[2] = 'add'
  when false
    cmd[2] = 'delete'
  end
  debug "CMD #{cmd.join(' ')}"
  if system(cmd.join(' '))
    info "IP '#{cmd[2]}' operation done"
  else
    err "IP '#{cmd[2]}' operation failed"
  end
end

#vip_update_arp!Object

send gratuitous ARP to the network <IMPLEMENTED>



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/etcd-tools/watchdog/vip.rb', line 35

def vip_update_arp!
  cmd = [ arping, '-U', '-q',
          '-c', @config[:parameters][:arping_count],
          '-I', @config[:parameters][:interface],
          @config[:parameters][:vip] ]
  debug "CMD #{cmd.join(' ')}"
  if system(cmd.join(' '))
    info 'gratuitous ARP packet sent'
    return true
  else
    err 'gratuitous ARP packet failed to send'
    return false
  end
end