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

[dev] Modified the format of the dhcp configuration files: one file per cluster

parent c022f7ab
......@@ -8,7 +8,8 @@ require '../lib/input_loader'
global_hash = load_yaml_file_hierarchy("../../input/grid5000/")
#puts JSON.generate(data)
def dhcp_node_entries(site_uid, network_interface, hash_of_nodes, description_string=nil, hostname=true)
# Loop over a node list (hash_of_nodes) and return the corresponding dhcp entries
def dhcp_node_entries(site_uid, hash_of_nodes, network_interface, description_string=nil, hostname=true)
if hash_of_nodes.nil?
puts "Error in #{__method__}: no entry for \"#{description_string}\" at #{site_uid} (#{network_interface})."
return ""
......@@ -24,14 +25,21 @@ def dhcp_node_entries(site_uid, network_interface, hash_of_nodes, description_st
# For each node (sorted by #name, #id)
hash_of_nodes.sort_by { |item| item.to_s.split(/(\d+)/).map { |e| [e.to_i, e] } }.each { |node_uid, node_hash|
s << dhcp_node_entry(site_uid, network_interface, node_uid, node_hash, hostname)
s << dhcp_node_entry(site_uid, node_uid, node_hash, network_interface, hostname)
}
s.string
}
end
def dhcp_node_entry(site_uid, network_interface, node_uid, node_hash, hostname=true)
# Print the DHCP entry of a node :
#
# host node_uid_net.site_uid.grid5000.fr {
# hardware ethernet 00:E0:81:D5:06:B8;
# fixed-address 172.16.64.144;
# option host-name "node_uid_net";
# }
def dhcp_node_entry(site_uid, node_uid, node_hash, network_interface, hostname=true)
node_uid_net = node_uid
node_uid_net = node_uid + "-bmc" if network_interface == "bmc"
......@@ -74,24 +82,36 @@ def dhcp_node_entry(site_uid, network_interface, node_uid, node_hash, hostname=t
end
["bmc", "eth"].each { |network_interface|
global_hash["sites"].each { |site_uid, site_hash|
# next unless site_uid == "nancy"
erb = ERB.new(File.read("templates/dhcp.erb"))
output_file = "output/puppet-repo/modules/dhcpg5k/files/" + site_uid + "/dhcpd.conf.d/" + network_interface #site_hash["network_interfaces"][network_interface]["ip"]
pp output_file
def write_dhcp_file(site_uid, hash_of_nodes, network_interfaces, output_filename, description_string=nil, hostname=true)
erb = ERB.new(File.read("templates/dhcp.erb"))
output_file = "output/puppet-repo/modules/dhcpg5k/files/" + site_uid + "/dhcpd.conf.d/" + output_filename + ".conf"
# Create directory hierarchy
dirname = File.dirname(output_file)
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
# Apply ERB template and save
File.open(output_file, "w+") { |f|
f.write(erb.result(binding))
pp output_file
# Create directory hierarchy
dirname = File.dirname(output_file)
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
# Apply ERB template and save
File.open(output_file, "w+") { |f|
network_interfaces.each { |network_interface|
f << dhcp_node_entries(site_uid, hash_of_nodes, network_interface, description_string, hostname)
}
}
end
# Loop over Grid'5000 sites
global_hash["sites"].each { |site_uid, site_hash|
# On file for each clusters
site_hash.fetch("clusters").each { |cluster_uid, cluster_hash|
write_dhcp_file(site_uid, cluster_hash["nodes"], ["eth", "bmc"], "cluster-" + cluster_uid, description_string=nil, hostname=true)
}
# Other dhcp files
write_dhcp_file(site_uid, site_hash["net-links"], "eth", "switchs", "Switchs", false)
write_dhcp_file(site_uid, site_hash["laptops"], "eth", "laptops", "Admin laptop's")
write_dhcp_file(site_uid, site_hash["dom0"], "eth", "dom0", "Dom0")
}
......@@ -3,18 +3,3 @@
# File:: puppet:///modules/dhcpg5k/nancy/dhcpd.conf.d/
#
<%= dhcp_node_entries(site_uid, network_interface, site_hash["net-links"], "Switchs", false) %>
<%= dhcp_node_entries(site_uid, network_interface, site_hash["laptops"], "Admin laptop's") %>
<%= dhcp_node_entries(site_uid, network_interface, site_hash["dom0"], "Dom0") %>
<%=
StringIO.open { |s|
# For each clusters
site_hash.fetch("clusters").each { |cluster_uid, cluster_hash|
s << dhcp_node_entries(site_uid, network_interface, cluster_hash.fetch("nodes"), "#{cluster_uid} production network")
s << "\n\n"
}
s.string
}
%>
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