Module: PortAuthority::Mechanism::FloatingIP

Extended by:
FloatingIP
Included in:
FloatingIP
Defined in:
lib/port-authority/mechanism/floating_ip.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_icmpObject

Returns the value of attribute _icmp.



10
11
12
# File 'lib/port-authority/mechanism/floating_ip.rb', line 10

def _icmp
  @_icmp
end

Instance Method Details

#arp_del!Object



39
40
41
42
# File 'lib/port-authority/mechanism/floating_ip.rb', line 39

def arp_del!
  return true if shellcmd Config.commands[:arp], '-d', Config.lbaas[:floating_ip], '>/dev/null 2>&1'
  false
end

#arp_update!Object

send gratuitous ARP to the network



23
24
25
26
# File 'lib/port-authority/mechanism/floating_ip.rb', line 23

def arp_update!
  return true if shellcmd Config.commands[:arping], '-U', '-q', '-c', Config.lbaas[:arping_count], '-I', Config.lbaas[:interface], Config.lbaas[:floating_ip]
  false
end

#duplicate?Boolean

check whether the IP is registered anywhere



45
46
47
48
# File 'lib/port-authority/mechanism/floating_ip.rb', line 45

def duplicate?
  return true if shellcmd Config.commands[:arping], '-D', '-q', '-c', Config.lbaas[:arping_count], '-w', Config.lbaas[:arping_wait], '-I', Config.lbaas[:interface], Config.lbaas[:floating_ip]
  false
end

#handle!(leader) ⇒ Object

add or remove VIP on interface



17
18
19
20
# File 'lib/port-authority/mechanism/floating_ip.rb', line 17

def handle!(leader)
  return true if shellcmd Config.commands[:iproute], 'address', leader ? 'add' : 'delete', "#{Config.lbaas[:floating_ip]}/32", 'dev', Config.lbaas[:interface], '>/dev/null 2>&1'
  false
end

#init!Object



12
13
14
# File 'lib/port-authority/mechanism/floating_ip.rb', line 12

def init!
  @_icmp = Net::Ping::ICMP.new(Config.lbaas[:floating_ip])
end

#reachable?Boolean

check reachability of VIP by ICMP echo



34
35
36
37
# File 'lib/port-authority/mechanism/floating_ip.rb', line 34

def reachable?
  (1..Config.lbaas[:icmp_count]).each { return true if @_icmp.ping }
  false
end

#up?Boolean

check whether VIP is assigned to me



29
30
31
# File 'lib/port-authority/mechanism/floating_ip.rb', line 29

def up?
  Socket.ip_address_list.map(&:ip_address).member?(Config.lbaas[:floating_ip])
end