Commit 1a0a25a7 authored by DELABROYE Dimitri's avatar DELABROYE Dimitri

[dev] add puppet4 compatibility on kadeploy generator

parent 8a623e03
......@@ -32,13 +32,23 @@ OptionParser.new do |opts|
opts.on('-o', '--output-dir dir', String, 'Select the puppet repo path', "Default: " + options[:output_dir]) do |d|
options[:output_dir] = d
options[:conf_dir] = "#{options[:output_dir]}/modules/kadeployg5k/generators/"
options[:conf_dir] = begin
if options[:puppet4]
"#{options[:output_dir]}/platforms/production/generators/kadeploy"
else
"#{options[:output_dir]}/modules/kadeployg5k/generators/"
end
end
end
opts.on('-c', '--conf-dir dir', String, 'Select the conman configuration path', "Default: #{options[:conf_dir]}") do |d|
options[:conf_dir] = d
end
opts.on('--puppet4', 'Puppet 4 version', "Default: " + options[:puppet4].to_s) do |d|
options[:puppet4] = d
end
opts.separator ""
opts.separator "Filters:"
......@@ -66,7 +76,7 @@ def cluster_prefix(cluster_list)
# Shrink cluster names. Start with 3 characters
# prefix_hash = {'gra' => ['graoully', 'graphene', ...], 'gri' => ['griffon']}
prefix_hash = cluster_list.group_by { |x| x[0, 3] }
prefix_hash = cluster_list.group_by { |x| x[0, 3] }
# Add characters until each prefix is unique
loop do
......@@ -102,7 +112,7 @@ end
#
# Generate site/<site_uid>/servers_conf[_dev]/clusters.conf
#
clusters_conf = { 'clusters'=> [] } # output clusters.conf
prefix = cluster_prefix(site['clusters'].keys)
......@@ -165,7 +175,13 @@ end
} # site['clusters'].each
output_file = Pathname("#{options[:output_dir]}/modules/kadeployg5k/files/#{site_uid}/server_conf#{suffix.tr('-', '_')}/clusters.conf")
output_file =begin
if options[:puppet4]
Pathname("#{options[:output_dir]}//platforms/production/modules/generated/files/grid5000/kadeploy/server#{suffix.tr('-', '_')}/#{site_uid}/clusters.conf")
else
Pathname("#{options[:output_dir]}/modules/kadeployg5k/files/#{site_uid}/server_conf#{suffix.tr('-', '_')}/clusters.conf")
end
end
output_file.dirname.mkpath()
write_yaml(output_file, clusters_conf)
add_header(output_file)
......@@ -175,7 +191,7 @@ end
#
# Load 'conf/kadeployg5k.yaml' data and fill up the kadeployg5k.conf.erb template for each cluster
conf = YAML::load(ERB.new(File.read("#{options[:conf_dir]}/kadeployg5k#{suffix}.yaml")).result(binding))
site['clusters'].each { |cluster_uid, cluster|
......@@ -186,12 +202,19 @@ end
end
output = ERB.new(File.read(File.expand_path('templates/kadeployg5k.conf.erb', File.dirname(__FILE__)))).result(binding)
output_file = Pathname("#{options[:output_dir]}/modules/kadeployg5k/files/#{site_uid}/server_conf#{suffix.tr('-', '_')}/#{cluster_uid}-cluster.conf")
output_file = begin
if options[:puppet4]
Pathname("#{options[:output_dir]}//platforms/production/modules/generated/files/grid5000/kadeploy/server#{suffix.tr('-', '_')}/#{site_uid}/#{cluster_uid}-cluster.conf")
else
Pathname("#{options[:output_dir]}/modules/kadeployg5k/files/#{site_uid}/server_conf#{suffix.tr('-', '_')}/#{cluster_uid}-cluster.conf")
end
end
output_file.dirname.mkpath()
File.write(output_file, output)
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment