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

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

Defined Under Namespace

Classes: RouteService

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(Construqt::Resources::Component::VRRP), "etc", "keepalived", "keepalived.conf")
global_defs {
  lvs_id #{host.name}
}
GLOBAL
end

Instance Method Details

#build_config(host, iface) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_vrrp.rb', line 26

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 #{iface.password||"fw"}"
  ret << "  }"
  ret << "  virtual_ipaddress {"
  iface.address.ips.each do |ip|
    ret << "    #{ip.to_string} dev #{my_iface.name}"
  end
  iface.address.routes.each do |rt|
    key = "#{iface.name}-#{rt.dst.to_string}-#{rt.via}"
    next if iface.services.find{ |i| i.name == key }
    iface.services << RouteService.new(key, rt)
  end


  ret << "  }"
  if iface.services && !iface.services.empty?
    ret << "  notify /etc/network/vrrp.#{iface.name}.sh"
    ret << "  notify_stop /etc/network/vrrp.#{iface.name}.stop.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(Construqt::Resources::Component::VRRP), "etc", "keepalived", "keepalived.conf")
end