Class: Construqt::Flavour::Ubuntu::Vrrp

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/construqt/flavour/ubuntu/flavour_ubuntu_vrrp.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cfg) ⇒ Vrrp

Returns a new instance of Vrrp.



6
7
8
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_vrrp.rb', line 6

def initialize(cfg)
  super(cfg)
end

Class Method Details

.header(host) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_vrrp.rb', line 10

def self.header(host)
  host.result.add(self, <<GLOBAL, Construqt::Resources::Rights::ROOT_0644, "etc", "keepalived", "keepalived.conf")
global_defs {
  lvs_id #{host.name}
}
GLOBAL
end

Instance Method Details

#build_config(host, iface) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_vrrp.rb', line 18

def build_config(host, iface)
  iface = iface.delegate
  my_iface = iface.interfaces.find{|iface| iface.host == host }
  ret = []
  ret << "vrrp_instance #{iface.name} {"
  ret << "  state MASTER"
  ret << "  interface #{my_iface.name}"
  ret << "  virtual_router_id #{iface.vrid||iface.interfaces.map{|a,b| a.priority<=>b.priority}.first}"
  ret << "  priority #{my_iface.priority}"
  ret << "  authentication {"
  ret << "        auth_type PASS"
  ret << "        auth_pass fw"
  ret << "  }"
  ret << "  virtual_ipaddress {"
  iface.address.ips.each do |ip|
    ret << "    #{ip.to_string} dev #{my_iface.name}"
  end

  ret << "  }"
  if iface.services && !iface.services.empty?
    ret << "  notify /etc/network/vrrp.#{iface.name}.sh"
    writer = host.result.etc_network_interfaces.get(iface)
    iface.services.each do |service|
      Services.get_renderer(service).interfaces(host, my_iface.name, my_iface, writer)
      Services.get_renderer(service).vrrp(host, my_iface.name, iface)
    end
  end

  ret << "}"
  host.result.add(self, ret.join("\n"), Construqt::Resources::Rights::ROOT_0644, "etc", "keepalived", "keepalived.conf")
end