Commit 30a31b24 authored by Simon Delamare's avatar Simon Delamare Committed by simfu
Browse files

[generators] Update bind generator for puppet4

parent 2adae387
......@@ -22,14 +22,14 @@ refapi = load_yaml_file_hierarchy(File.expand_path(input_data_dir, File.dirname(
$options = {}
$options[:sites] = %w{grenoble lille luxembourg lyon nancy nantes rennes sophia}
$options[:output_dir] = "/tmp/puppet-repo"
$options[:output_dir] = "/tmp/puppet"
$options[:verbose] = false
OptionParser.new do |opts|
opts.banner = "Usage: bindg5k.rb [options]"
opts.separator ""
opts.separator "Example: ruby bindg5k.rb -s nancy -o /tmp/puppet-repo"
opts.separator "Example: ruby bindg5k.rb -s nancy -o /tmp/puppet"
opts.on('-o', '--output-dir dir', String, 'Select the puppet repo path', "Default: " + $options[:output_dir]) do |d|
$options[:output_dir] = d
......@@ -448,13 +448,18 @@ def get_orphan_reverse_manual_zones(zones_dir, site_uid, site)
return zones
end
def write_global_site_conf(site_uid, dest_dir, zones_dir)
['global', 'site'].each { |dir|
conf_file = File.join(dest_dir, "#{dir}/conf", "global-#{site_uid}.conf")
def write_site_conf(site_uid, dest_dir, zones_dir)
conf_file = File.join(dest_dir, "#{site_uid}-zones.conf")
FileUtils.mkdir_p(File.dirname(conf_file))
conf_content = ERB.new(File.read(File.expand_path('templates/bind-global-site.conf.erb', File.dirname(__FILE__)))).result(binding)
conf_content = ERB.new(File.read(File.expand_path('templates/bind-site.conf.erb', File.dirname(__FILE__)))).result(binding)
File.write(conf_file, conf_content)
end
def write_site_local_conf(site_uid, dest_dir, zones_dir)
conf_file = File.join(dest_dir, "#{site_uid}-localzones.conf")
FileUtils.mkdir_p(File.dirname(conf_file))
conf_content = ERB.new(File.read(File.expand_path('templates/bind-site-local.conf.erb', File.dirname(__FILE__)))).result(binding)
File.write(conf_file, conf_content)
}
end
def write_zone(zone)
......@@ -474,7 +479,7 @@ refapi["sites"].each { |site_uid, site|
next unless $options[:sites].include?(site_uid)
dest_dir = "#{$options[:output_dir]}/modules/bindg5k/files/"
dest_dir = "#{$options[:output_dir]}/platforms/production/modules/generated/files/bind/"
zones_dir = File.join(dest_dir, "zones/#{site_uid}")
site_records = {}
......@@ -590,6 +595,7 @@ refapi["sites"].each { |site_uid, site|
write_zone(zone)
}
write_global_site_conf(site_uid, dest_dir, zones_dir)
write_site_conf(site_uid, dest_dir, zones_dir)
write_site_local_conf(site_uid, dest_dir, zones_dir)
} # each sites
<%
# List file in the directory instead of using the 'reverse' variable as some files might be set manually
Dir.entries(File.join(zones_dir, "local")).sort.each { |file|
next unless /.*.db$/.match(file)
comment = ''
zone = ''
if file == "#{site_uid}.db"
zone = "#{site_uid}.grid5000.fr"
elsif /^reverse-(.*).db$/.match(file)
zone = "#{$1}.in-addr.arpa"
else
puts "Error: unknown zone for '#{file}' in '#{zones_dir}'"
next
end
%>
zone "<%= zone %>" {
type master;
file "/etc/bind/zones/<%= site_uid %>/local/<%= file %>";
};
<% } %>
<%
if dir == 'global'
type = 'master'
elsif dir == 'site'
type = 'slave'
else
raise "'dir' undefined"
end
# List file in the directory instead of using the 'reverse' variable as some files might be set manually
Dir.entries(zones_dir).sort.each { |file|
next unless /.*.db$/.match(file)
......@@ -27,8 +19,7 @@ Dir.entries(zones_dir).sort.each { |file|
end
%>
zone "<%= zone %>" {
type <%= type %>;
type master;
file "/etc/bind/zones/<%= site_uid %>/<%= file %>";
<%= type == 'slave' ? 'masters { master-ns-global; };' : '' %>
};
<% } %>
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