Commit aa7a642f authored by Jérémie Gaidamour's avatar Jérémie Gaidamour
Browse files

[dev] bind.rb: renamed some variables, simplifying stuffs for code readability

parent 70ac0872
......@@ -2,24 +2,19 @@
require 'pp'
require 'erb'
require 'fileutils'
require 'pathname'
require '../lib/input_loader'
global_hash = load_yaml_file_hierarchy("../input/grid5000/")
refapi = load_yaml_file_hierarchy("../input/grid5000/")
$output_dir = ENV['puppet_repo'] || 'output'
def write_bind_file(data)
erb = ERB.new(File.read("templates/bind.erb"))
filename = data.fetch("site_uid") + ".db"
output_file = "output/puppet-repo/modules/bindg5k/files/zones/" + data.fetch("site_uid") + "/" + filename
output = ERB.new(File.read("templates/bind.erb")).result(binding)
# Create directory hierarchy
dirname = File.dirname(output_file)
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
output_file = Pathname("#{$output_dir}/modules/bindg5k/files/zones/#{data.fetch('site_uid')}/#{data.fetch('site_uid')}.db")
output_file.dirname.mkpath()
# Apply ERB template and save
File.open(output_file, "w+") { |f|
f.write(erb.result(binding))
}
File.write(output_file, output)
end
# Loop over Grid'5000 sites
......@@ -30,26 +25,29 @@ end
# "ib0"=>[{"start"=>1, "end"=>25, "ip"=>"172.18.98", "shift"=>0}],
# "bmc"=>[{"start"=>1, "end"=>25, "ip"=>"172.17.98", "shift"=>0}]}}
global_hash["sites"].each { |site_uid, site_hash|
refapi["sites"].each { |site_uid, site|
entries = {}
site_hash.fetch("clusters").sort.each { |cluster_uid, cluster_hash|
site.fetch("clusters").sort.each { |cluster_uid, cluster|
next if site_uid != 'nancy'
cluster_hash.fetch('nodes').each_sort_by_node_uid { |node_uid, node_hash|
cluster.fetch('nodes').each_sort_by_node_uid { |node_uid, node|
network_adapters = {}
node_hash.fetch('network_adapters').each { |net_uid, net_hash|
node.fetch('network_adapters').each { |net_uid, net_hash|
network_adapters[net_uid] = {"ip"=>net_hash["ip"], "mounted"=>net_hash["mounted"]}
}
node_hash.fetch('kavlan').each { |net_uid, ip|
node.fetch('kavlan').each { |net_uid, ip|
network_adapters[net_uid] = {"ip"=>ip, "mounted"=>nil}
} if node_hash['kavlan']
} if node['kavlan']
network_adapters.each { |net_uid, net_hash|
entries[cluster_uid] = {} unless entries[cluster_uid]
entries[cluster_uid][net_uid] = [] unless entries[cluster_uid][net_uid]
entries[cluster_uid] ||= {}
entries[cluster_uid][net_uid] ||= []
last_entry = entries[cluster_uid][net_uid].last
next unless net_hash["ip"]
......@@ -81,6 +79,5 @@ global_hash["sites"].each { |site_uid, site_hash|
"site_uid" => site_uid,
"entries" => entries,
})
}
......@@ -4,16 +4,18 @@
#
<% data.fetch('entries').each { |cluster_uid, data| %>
; Cluster <%= cluster_uid %>
<% data.each { |net_uid, entries| %>
<% entries.each { |entry| %>
<% if entry["start"] == entry["end"] %>
<%= cluster_uid %>-<%= entry["start"] %>-<%= net_uid %> IN A <%= entry["ip"] %>.<%= entry["start"]+entry["shift"] %>
<% else %>
<% if entry["mounted"] %>
$GENERATE <%= entry["start"] %>-<%= entry["end"] %> <%= cluster_uid %>-$ IN A <%= entry["ip"] %>.$<%= '{+' + entry["shift"].to_s + '}' if entry["shift"] > 0 %>
$GENERATE <%= entry["start"] %>-<%= entry["end"] %> <%= cluster_uid %>-$-<%= net_uid %> IN CNAME <%= cluster_uid %>-$<%= '{+' + entry["shift"].to_s + '}' if entry["shift"] > 0 %>
<% data.each { |net_uid, entries|
entries.each { |entry|
if entry["start"] == entry["end"] %>
<%= "#{cluster_uid}-#{entry['start']}-#{net_uid} IN A #{entry['ip']}.#{entry['start']+entry['shift']}" %>
<% else
shift = (entry["shift"] > 0 ? '{+' + entry["shift"].to_s + '}' : '')
if false # entry["mounted"]
%>
<%= "$GENERATE #{entry["start"]}-#{entry["end"]} #{cluster_uid}-$ IN A #{entry["ip"]}.$#{shift}" %>
<% else %>
$GENERATE <%= entry["start"] %>-<%= entry["end"] %> <%= cluster_uid %>-$-<%= net_uid %> IN A <%= entry["ip"] %>.$<%= '{+' + entry["shift"].to_s + '}' if entry["shift"] > 0 %>
<%= "$GENERATE #{entry["start"]}-#{entry["end"]} #{cluster_uid}-$-#{net_uid} IN A #{entry["ip"]}.$#{shift}" %>
<% end %>
<% end %>
<% } %>
......
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