Commit f3b00c2d authored by IMBERT Matthieu's avatar IMBERT Matthieu

[ipv6, dhcp] add generation of dhcpv6 records

parent f65b8615
# Get the mac and ip of a node. Throw exception if error. # Get the mac, ipv4, ipv6 of a node. Throw exception if error.
def get_network_info(node_hash, network_interface) def get_network_info(node_hash, network_interface)
# Get node_hash["network_adapters"][network_interface]["ip"] and node_hash["network_adapters"][network_interface]["mac"] # Get node_hash["network_adapters"][network_interface]["ip"], node_hash["network_adapters"][network_interface]["ip6"] and node_hash["network_adapters"][network_interface]["mac"]
node_network_adapters = node_hash.fetch("network_adapters") node_network_adapters = node_hash.fetch("network_adapters")
# For the production network, find the mounted interface (either eth0 or eth1) # For the production network, find the mounted interface (either eth0 or eth1)
...@@ -21,24 +21,28 @@ def get_network_info(node_hash, network_interface) ...@@ -21,24 +21,28 @@ def get_network_info(node_hash, network_interface)
end end
node_mac = node_network_interface.fetch('mac') node_mac = node_network_interface.fetch('mac')
node_ip = node_network_interface.fetch('ip') node_ipv4 = node_network_interface.fetch('ip')
node_ipv6 = node_network_interface.fetch('ip6', nil)
raise '"mac" is nil' unless node_mac raise '"mac" is nil' unless node_mac
raise '"ip" is nil' unless node_ip raise '"ip" is nil' unless node_ipv4
#raise '"ipv6" is nil' unless node_ipv6 # commented right now, we don't yet impose ipv6 for everything
return [node_ip, node_mac] return [node_ipv4, node_ipv6, node_mac]
end end
def write_dhcp_file(data, options) def write_dhcp_files(data, options)
if data["nodes"].nil? if data["nodes"].nil?
puts "Error in #{__method__}: no entry for \"#{data['filename']}\" at #{data['site_uid']} (#{data['network_adapters']})." puts "Error in #{__method__}: no entry for \"#{data['filename']}\" at #{data['site_uid']} (#{data['network_adapters']})."
return "" return ""
end end
output = ERB.new(File.read(File.expand_path('templates/dhcp.erb', File.dirname(__FILE__)))).result(binding) ["dhcp", "dhcpv6"].each { |dhcpkind|
output_file = Pathname("#{options[:output_dir]}/platforms/production/modules/generated/files/grid5000/dhcp/#{data.fetch("site_uid")}/#{data.fetch('filename')}") output = ERB.new(File.read(File.expand_path("templates/dhcp.erb", File.dirname(__FILE__)))).result(binding)
output_file.dirname.mkpath() output_file = Pathname("#{options[:output_dir]}/platforms/production/modules/generated/files/grid5000/#{dhcpkind}/#{data.fetch("site_uid")}/#{data.fetch('filename')}")
File.write(output_file, output) output_file.dirname.mkpath()
File.write(output_file, output)
}
end end
def generate_puppet_dhcpg5k(options) def generate_puppet_dhcpg5k(options)
...@@ -79,7 +83,7 @@ def generate_puppet_dhcpg5k(options) ...@@ -79,7 +83,7 @@ def generate_puppet_dhcpg5k(options)
site_hash.fetch("clusters").each { |cluster_uid, cluster_hash| site_hash.fetch("clusters").each { |cluster_uid, cluster_hash|
# networks = ["eth", "bmc"] # networks = ["eth", "bmc"]
# networks << 'mic0' if cluster_hash['nodes'].values.any? {|x| x['network_adapters']['mic0'] } # networks << 'mic0' if cluster_hash['nodes'].values.any? {|x| x['network_adapters']['mic0'] }
write_dhcp_file({ write_dhcp_files({
"filename" => "cluster-" + cluster_uid + ".conf", "filename" => "cluster-" + cluster_uid + ".conf",
"site_uid" => site_uid, "site_uid" => site_uid,
"nodes" => cluster_hash.fetch('nodes'), "nodes" => cluster_hash.fetch('nodes'),
...@@ -91,7 +95,7 @@ def generate_puppet_dhcpg5k(options) ...@@ -91,7 +95,7 @@ def generate_puppet_dhcpg5k(options)
# Other dhcp files # Other dhcp files
["networks", "laptops", "servers"].each { |key| ["networks", "laptops", "servers"].each { |key|
write_dhcp_file({ write_dhcp_files({
"filename" => key + ".conf", "filename" => key + ".conf",
"site_uid" => site_uid, "site_uid" => site_uid,
"nodes" => site_hash[key], "nodes" => site_hash[key],
...@@ -116,7 +120,7 @@ def generate_puppet_dhcpg5k(options) ...@@ -116,7 +120,7 @@ def generate_puppet_dhcpg5k(options)
} }
key = 'pdus' key = 'pdus'
write_dhcp_file({ write_dhcp_files({
"filename" => key + ".conf", "filename" => key + ".conf",
"site_uid" => site_uid, "site_uid" => site_uid,
"nodes" => site_hash['pdus'], "nodes" => site_hash['pdus'],
......
...@@ -18,10 +18,11 @@ ...@@ -18,10 +18,11 @@
uid_net = node_uid uid_net = node_uid
end end
# Get ip and mac addresses # Get ipv4, ipv6 and mac addresses
begin begin
ip, mac = get_network_info(node, network_interface) ipv4, ipv6, mac = get_network_info(node, network_interface)
dhcp_entries.push({ 'uid_net' => uid_net, 'ip' => ip, 'mac' => mac }) next if dhcpkind == 'dhcpv6' && ipv6 == nil
dhcp_entries.push({ 'uid_net' => uid_net, 'ipv4' => ipv4, 'ipv6' => ipv6, 'mac' => mac })
rescue => e rescue => e
next if data.fetch('optional_network_adapters').include?(network_interface) next if data.fetch('optional_network_adapters').include?(network_interface)
...@@ -36,7 +37,7 @@ group { ...@@ -36,7 +37,7 @@ group {
<% dhcp_entries.each {|node| %> <% dhcp_entries.each {|node| %>
host <%= node['uid_net'] %> { host <%= node['uid_net'] %> {
hardware ethernet <%= node['mac'].upcase %>; hardware ethernet <%= node['mac'].upcase %>;
fixed-address <%= node['ip'] %>; fixed-address <%= dhcpkind == 'dhcpv6' ? node['ipv6'] : node['ipv4'] %>;
} }
<% } %> <% } %>
} }
......
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