Class: Construqt::Flavour::Ubuntu::Gre

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

Instance Method Summary collapse

Constructor Details

#initialize(cfg) ⇒ Gre

Returns a new instance of Gre.



294
295
296
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu.rb', line 294

def initialize(cfg)
  super(cfg)
end

Instance Method Details

#build_config(host, gre) ⇒ Object



298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu.rb', line 298

def build_config(host, gre)
  gre_delegate = gre.delegate
  #      binding.pry
  cfg = nil
  if gre_delegate.local.first_ipv6
    cfg = OpenStruct.new(:prefix=>6, :my=>gre_delegate.local.first_ipv6, :other => gre_delegate.remote.first_ipv6, :mode => "ip6gre")
  elsif gre_delegate.local.first_ipv4
    cfg = OpenStruct.new(:prefix=>4, :my=>gre_delegate.local.first_ipv4, :other => gre_delegate.remote.first_ipv4, :mode => "ipgre")
  end

  throw "need a local address #{host.name}:#{gre_delegate.name}" unless cfg
  local_iface = host.interfaces.values.find { |iface| iface.address.match_network(cfg.my) }
  throw "need a interface with address #{host.name}:#{cfg.my}" unless local_iface
  iname = Util.clean_if("gt#{cfg.prefix}", gre_delegate.name)

  writer_local = host.result.etc_network_interfaces.get(local_iface)
  writer_local.lines.up("/bin/bash /etc/network/#{iname}-up.iface")
  writer_local.lines.down("/bin/bash /etc/network/#{iname}-down.iface")


  writer = host.result.etc_network_interfaces.get(gre_delegate)
  writer.skip_interfaces.header.interface_name(iname)
  writer.lines.up("ip -#{cfg.prefix} tunnel add #{iname} mode #{cfg.mode} local #{cfg.my.to_s} remote #{cfg.other.to_s}")
  #      writer.lines.up("ip -#{cfg.prefix} link set dev #{iname} up")
  Device.build_config(host, gre)
  #      Device.add_address(host, iname, iface, writer.lines, writer)
  writer.lines.down("ip -#{cfg.prefix} tunnel del #{iname}")
end