Commit a357e5cb authored by Sebastien Philippot's avatar Sebastien Philippot
Browse files

Merge branch 'master' of github.com:grid5000/reference-repository

parents 1610fd54 c3012fd3
---
clusters: required_hash
networks: required_hash
clusters: optional_hash
networks: optional_hash
servers:
<optional_hash>:
<multi>:
......
......@@ -21,15 +21,15 @@ input_data_dir = "../../input/grid5000/"
refapi = load_yaml_file_hierarchy(File.expand_path(input_data_dir, File.dirname(__FILE__)))
$options = {}
$options[:sites] = %w{grenoble lille luxembourg lyon nancy nantes rennes sophia}
$options[:output_dir] = "/tmp/puppet-repo"
$options[:sites] = %w{grenoble lille luxembourg lyon nancy nantes rennes sophia toulouse}
$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
......@@ -388,7 +388,7 @@ def set_zone_header_records(zone, site)
zone.mx = DNS::Zone::RR::MX.new
zone.mx.priority = 10
zone.mx.exchange = "mail.#{zone.site_uid}.grid5000.fr."
if (File.basename(zone.file_path) == "#{zone.site_uid}.db")
if (File.basename(zone.file_path) == "#{zone.site_uid}.db" && site['frontend_ip'])
zone.at = DNS::Zone::RR::A.new
zone.at.address = site['frontend_ip']
end
......@@ -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 = {}
......@@ -489,7 +494,7 @@ refapi["sites"].each { |site_uid, site|
site_records['networks'] = get_networks_records(site, 'networks') unless site['networks'].nil?
site_records['laptops'] = get_networks_records(site, 'laptops') unless site['laptops'].nil?
site.fetch("clusters").sort.each { |cluster_uid, cluster|
site.fetch("clusters", []).sort.each { |cluster_uid, cluster|
cluster.fetch('nodes').select { |node_uid, node|
node != nil && node["status"] != "retired" && node.has_key?('network_adapters')
......@@ -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; };' : '' %>
};
<% } %>
......@@ -30,7 +30,7 @@ subnet <%= kavlan_ip.network.to_addr %> netmask <%= kavlan_ip.netmask.to_addr %>
<%
refapi['sites'].sort.to_h.each_key do |site|
next if kavlan_id.to_i.between?(1, 9) and site != site_uid
refapi['sites'][site]['clusters'].sort.to_h.each do |cluster_uid, cluster|
refapi['sites'][site].fetch('clusters', []).sort.to_h.each do |cluster_uid, cluster|
cluster['nodes'].sort.to_h.each do |node_uid, node|
next if node['status'] and node['status'] == 'retired'
node['network_adapters'].each do |interface_uid, interface|
......
......@@ -185,11 +185,11 @@ global_hash["sites"].each do |site_uid, site|
# Write network info
#
site["networks"].sort.each do |network_uid, network|
site.fetch("networks", []).sort.each do |network_uid, network|
create_network_equipment(network_uid, network, refapi_path, site_uid)
end
site["clusters"].sort.each do |cluster_uid, cluster|
site.fetch("clusters", []).sort.each do |cluster_uid, cluster|
puts " #{cluster_uid}"
#
......
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