Commit a6f262de authored by IMBERT Matthieu's avatar IMBERT Matthieu Committed by LOUP David
Browse files

[kavlan6] generate dhcpd6 configs

parent 2c3aa7e4
......@@ -58,18 +58,21 @@ def generate_puppet_kavlang5k(options)
File.write(output_file, output)
(1..9).each do |kavlan_id|
output = ERB.new(File.read(File.expand_path('templates/kavlan-dhcp.conf.erb', File.dirname(__FILE__))), nil, '-').result(binding)
output_file = Pathname("#{options[:output_dir]}//platforms/production/modules/generated/files/grid5000/kavlan/#{site_uid}/dhcp/dhcpd-#{kavlan_id}.conf")
output_file.dirname.mkpath()
File.write(output_file, output)
["dhcpd", "dhcpd6"].each { |dhcpkind|
output = ERB.new(File.read(File.expand_path('templates/kavlan-dhcp.conf.erb', File.dirname(__FILE__))), nil, '-').result(binding)
output_file = Pathname("#{options[:output_dir]}//platforms/production/modules/generated/files/grid5000/kavlan/#{site_uid}/dhcp/#{dhcpkind}-#{kavlan_id}.conf")
output_file.dirname.mkpath()
File.write(output_file, output)
}
end
# Look for site's global kavlan
# TODO fix dirty convertion to_i below
kavlan_id = refapi['sites'][site_uid]['kavlans'].each_key.select {|k| k.to_i > 9}.pop()
output = ERB.new(File.read(File.expand_path('templates/kavlan-dhcp.conf.erb', File.dirname(__FILE__))), nil, '-').result(binding)
output_file = Pathname("#{options[:output_dir]}//platforms/production/modules/generated/files/grid5000/kavlan/#{site_uid}/dhcp/dhcpd-0.conf")
File.write(output_file, output)
kavlan_id = refapi['sites'][site_uid]['kavlans'].each_key.select {|k| k.to_i > 9}.pop().to_i
["dhcpd", "dhcpd6"].each { |dhcpkind|
output = ERB.new(File.read(File.expand_path('templates/kavlan-dhcp.conf.erb', File.dirname(__FILE__))), nil, '-').result(binding)
output_file = Pathname("#{options[:output_dir]}//platforms/production/modules/generated/files/grid5000/kavlan/#{site_uid}/dhcp/#{dhcpkind}-0.conf")
File.write(output_file, output)
}
}
end
......@@ -2,6 +2,7 @@
# Module : kavlang5k
# GENERATED by kavlang5k.rb
<% if dhcpkind == 'dhcpd'-%>
ddns-update-style none;
option space pxelinux;
option pxelinux.magic code 208 = string;
......@@ -52,15 +53,34 @@ kavlan = refapi['sites'][site_uid]['kavlans'][kavlan_id.to_s] # TODO fix needed
kavlan_ip = IPAddress::IPv4::new(kavlan['network'])
-%>
<% end -%>
<% kavlan = refapi['sites'][site_uid]['kavlans'][kavlan_id.to_s] # TODO fix needed conversion
if dhcpkind == 'dhcpd'
kavlan_ip = IPAddress::IPv4::new(kavlan['network']) -%>
subnet <%= kavlan_ip.network %> netmask <%= kavlan_ip.netmask %> {
<% elsif dhcpkind == 'dhcpd6'
case kavlan_id
when 1..3 # local non routed vlan
kavlan6_net = kavlan_id + 0x80 - 1
when 4..9 # local routed vlan
kavlan6_net = kavlan_id + 0x90 - 4
else # global vlan
kavlan6_net = kavlan_id + 0xa0 - 10
end
refapi['sites'][site_uid]
kavlan6_ip = "#{refapi['sites'][site_uid]['ipv6']['prefix']}#{sprintf('%02x', kavlan6_net)}::/64" -%>
subnet6 <%= kavlan6_ip %> {
<% end -%>
default-lease-time 86400;
max-lease-time 604800;
option domain-name-servers <%= kavlan_id.to_i.between?(1, 3)? kavlan['gateway'] : "dns.#{site_uid}.grid5000.fr" %>;
option ntp-servers <%= kavlan_id.to_i.between?(1, 3)? kavlan['gateway'] : "ntp.#{site_uid}.grid5000.fr" %>;
option routers <%= kavlan['gateway'] %>;
<% if dhcpkind == 'dhcpd' -%>
option subnet-mask <%= kavlan_ip.netmask %>;
option broadcast-address <%= kavlan_ip.broadcast %>;
next-server <%= "kadeploy.#{site_uid}.grid5000.fr" %>;
<% end -%>
}
<%
......@@ -79,6 +99,8 @@ refapi['sites'].sort.to_h.each_key do |site|
"Missing mac (#{interface['mac']}) or IP (#{node['kavlan'][interface['device']] and node['kavlan'][interface['device']]["kavlan-#{kavlan_id}"]})"
next
end
if dhcpkind == 'dhcpd'
-%>
host <%= node_uid %><%= interface['mounted']? "" : "-"+interface['device'] %>-kavlan-<%= kavlan_id %>.<%= site %>.grid5000.fr {
hardware ethernet <%= interface['mac'].downcase() %>;
......@@ -91,6 +113,17 @@ host <%= node_uid %><%= interface['mounted']? "" : "-"+interface['device'] %>-ka
<% end -%>
}
<%
elsif dhcpkind == 'dhcpd6'
-%>
host <%= node_uid %><%= interface['mounted']? "" : "-"+interface['device'] %>-kavlan-<%= kavlan_id %>-ipv6.<%= site %>.grid5000.fr {
hardware ethernet <%= interface['mac'].downcase() %>;
option host-name "<%= node_uid %><%= interface['mounted']? "" : "-"+interface['device'] %>-kavlan-<%= kavlan_id %>-ipv6";
option domain-name "<%= site %>.grid5000.fr";
option domain-search "<%= site %>.grid5000.fr", "grid5000.fr";
fixed-address <%= node['kavlan6'][interface['device']]["kavlan-#{kavlan_id}"] %>;
}
<%
end
end
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