Class: Construqt::Flavour::Ubuntu::Services::DhcpV6Relay

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

Instance Method Summary collapse

Constructor Details

#initialize(service) ⇒ DhcpV6Relay

Returns a new instance of DhcpV6Relay.



47
48
49
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_services.rb', line 47

def initialize(service)
  @service = service
end

Instance Method Details

#down(ifname, inbounds, upstreams) ⇒ Object



59
60
61
62
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_services.rb', line 59

def down(ifname, inbounds, upstreams)
  #"kill `cat /run/dhcrelay-v6.#{ifname}.pid`"
  "kill `cat /run/dhcp6relay-v6.#{ifname}.pid`"
end

#interfaces(host, ifname, iface, writer) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_services.rb', line 77

def interfaces(host, ifname, iface, writer)
  inbounds = Construqt::Tags.find(@service.inbound_tag).select{ |cqip| cqip.container.interface.host == host && cqip.ipv6? }
  return if inbounds.empty?
  upstreams = Construqt::Tags.find(@service.upstream_tag).select{ |cqip| cqip.ipv6? }
  return if upstreams.empty?
  writer.lines.up(up(ifname, inbounds, upstreams))
  writer.lines.down(down(ifname, inbounds, upstreams))
  host.result.add_component(Construqt::Resources::Component::DHCPRELAY)
end

#up(ifname, inbounds, upstreams) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_services.rb', line 51

def up(ifname, inbounds, upstreams)
  inbound_ifs = inbounds.map { |cqip| "#{cqip.container.interface.name}" }.join(' ')
  minus_s = upstreams.map{ |cqip| "-s #{cqip}" }.join(' ')
  minus_r = upstreams.map{ |cqip| "-r #{ifname}" }.join(' ')
  #"/usr/sbin/dhcrelay -pf /run/dhcrelay-v6.#{ifname}.pid -q -6 #{minus_l} #{minus_o}"
  "/usr/sbin/dhcp6relay -d -p /run/dhcp6relay-v6.#{ifname}.pid #{minus_s} #{minus_r} #{inbound_ifs}"
end

#vrrp(host, ifname, vrrp) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_services.rb', line 64

def vrrp(host, ifname, vrrp)
  inbounds = Construqt::Tags.find(@service.inbound_tag).select{ |cqip| cqip.container.interface.host == host && cqip.ipv6? }
  return if inbounds.empty?
  iface = vrrp.interfaces.find{|_| _.host == host }
  return unless iface
  #binding.pry
  upstreams = Construqt::Tags.find(@service.upstream_tag).select{ |cqip| cqip.ipv6? }
  return if upstreams.empty?
  host.result.etc_network_vrrp(vrrp.name).add_master(up(ifname, inbounds, upstreams))
                                          .add_backup(down(ifname, inbounds, upstreams))
  host.result.add_component(Construqt::Resources::Component::DHCPRELAY)
end