Module: Construqt::Ipsecs

Defined in:
lib/construqt/ipsecs.rb

Defined Under Namespace

Classes: Ipsec

Class Method Summary collapse

Class Method Details

.add_connection(cfg, id, to_id, iname) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/construqt/ipsecs.rb', line 20

def self.add_connection(cfg, id, to_id, iname)
  throw "my not found #{cfg[id].inspect}" unless cfg[id]['my']
  throw "host not found #{cfg[id].inspect}" unless cfg[id]['host']
  throw "remote not found #{cfg[id].inspect}" unless cfg[id]['remote']
  cfg[id]['other'] = nil
  cfg[id]['cfg'] = nil
  cfg[id]['my'].host = cfg[id]['host']
  cfg[id]['my'].name = "#{iname}-#{cfg[id]['host'].name}"
  cfg[id]['interface'] = nil
  cfg[id] = cfg[id]['host'].flavour.create_ipsec(cfg[id])
end

.build_configObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/construqt/ipsecs.rb', line 61

def self.build_config()
  hosts = {}
  @ipsecs.values.each do |ipsec|
    hosts[ipsec.left.host.object_id] ||= ipsec.left.host
    hosts[ipsec.right.host.object_id] ||= ipsec.right.host
  end
  #binding.pry
  hosts.values.each do |host|
    host.flavour.ipsec.header(host) if host.flavour.ipsec.respond_to?(:header)
  end
  @ipsecs.each do |name, ipsec|
    ipsec.build_config()
  end
end

.connection(name, cfg) ⇒ Object



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
# File 'lib/construqt/ipsecs.rb', line 32

def self.connection(name, cfg)
  #    binding.pry
  add_connection(cfg, 'left', 'right', Util.add_gre_prefix(cfg['right']['host'].name))
  add_connection(cfg, 'right', 'left', Util.add_gre_prefix(cfg['left'].host.name))
  cfg['name'] = name
  cfg = @ipsecs[name] = Ipsec.new(cfg)
  cfg.left.other = cfg.right
  cfg.left.cfg = cfg
  cfg.right.other = cfg.left
  cfg.right.cfg = cfg

  cfg.left.host.add_ipsec(cfg)
  cfg.right.host.add_ipsec(cfg)

  #puts "-------- #{cfg.left.my.host.name} - #{cfg.right.my.host.name}"
  cfg.left.interface = cfg.left.my.host.region.interfaces.add_gre(cfg.left.my.host, cfg.left.other.host.name,
                                                                  "address" => cfg.left.my,
                                                                  "local" => cfg.left.remote,
                                                                  "remote" => cfg.right.remote
                                                                 )
  cfg.right.interface = cfg.left.my.host.region.interfaces.add_gre(cfg.right.my.host, cfg.right.other.host.name,
                                                                   "address" => cfg.right.my,
                                                                   "local" => cfg.right.remote,
                                                                   "remote" => cfg.left.remote
                                                                  )
  #binding.pry
  cfg
end