Module: Vcloud::Converter

Defined in:
lib/vcloud/converter.rb,
lib/vcloud/converter/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.convert(conversion_type, file_path) ⇒ Object



7
8
9
10
11
# File 'lib/vcloud/converter.rb', line 7

def self.convert(conversion_type, file_path)
  if conversion_type == "vcloud-net_launcher"
    convert_vcloud_net_launcher(file_path)
  end
end

.convert_vcloud_net_launcher(file_path) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/vcloud/converter.rb', line 13

def self.convert_vcloud_net_launcher(file_path)
  begin
    vcloud_config = YAML.load_file(file_path)
  rescue Psych::SyntaxError
    puts "Your YAML file had a syntax error!"
    exit
  else
    name = vcloud_config.first.first

    vcloud_config[name].each do |machine|
      vdc_name = machine["vdc_name"]
      edge_gateway = machine["edge_gateway"]
      gateway = machine["gateway"]
      netmask = machine["netmask"]
      dns1 = machine["dns1"]
      dns2 = machine["dns2"]
      dns_suffix = machine["dns_suffix"]

      start_address = machine["ip_ranges"][0]["start_address"]
      end_address = machine["ip_ranges"][0]["end_address"]

      puts ERB.new(File.read("./templates/vcd_networks.tf.erb")).result(binding)
    end
  end
end