Commit 5864c5c5 authored by DELABROYE Dimitri's avatar DELABROYE Dimitri

[lib/refrepo/gen/puppet/kavlan] make kavlang5k use data instead if input

parent 3d5e6b50
......@@ -25,3 +25,4 @@ end
# load sub-parts that are used by many scripts anyway
require 'refrepo/utils'
require 'refrepo/input_loader'
require 'refrepo/data_loader'
require 'refrepo/hash/hash'
def kavlan_switch_port_lookup(switch, node_uid, interface='')
switch["linecards"].each_with_index do |lc, lc_uid|
next if not lc["ports"]
lc["ports"].each_with_index do |port, port_uid|
if port.is_a?(Hash)
switch_remote_port = port["port"] || lc["port"] || ""
switch_remote_uid = port["uid"]
else
switch_remote_port = lc["port"] || ""
switch_remote_uid = port
end
#warn "#{node_uid}, #{switch_uid}, #{lc_uid}, #{port_uid}, #{switch_remote_uid}, #{switch_remote_port}, #{interface}"
if switch_remote_uid == node_uid and switch_remote_port == interface
# Build port name from snmp_naming_pattern
# Example: '3 2 GigabitEthernet%LINECARD%/%PORT%' -> 'GigabitEthernet3/2'
pattern = lc.has_key?("kavlan_pattern") ? lc["kavlan_pattern"] : lc["snmp_pattern"]
port_name = pattern.sub("%LINECARD%",lc_uid.to_s).sub("%PORT%",port_uid.to_s)
return port_name
end
end
end
return nil
end
def generate_puppet_kavlang5k(options)
if not options[:conf_dir]
......@@ -12,7 +36,7 @@ def generate_puppet_kavlang5k(options)
puts "Using configuration directory: #{options[:conf_dir]}"
puts "For site(s): #{options[:sites].join(', ')}"
refapi = load_yaml_file_hierarchy
refapi = load_data_hierarchy
refapi['sites'].each { |site_uid, site_refapi|
......@@ -41,7 +65,8 @@ def generate_puppet_kavlang5k(options)
end
# Look for site's global kavlan
kavlan_id = refapi['sites'][site_uid]['kavlans'].each_key.select {|k| k.is_a?(Numeric) and k>9}.pop()
# 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)
......
......@@ -3,32 +3,6 @@
# GENERATED by kavlang5k.rb
#
<%
def net_switch_port_lookup(site, node_uid, interface='')
site["networks"].each do |switch_uid, switch|
#pp switch_uid
switch["linecards"].each do |lc_uid,lc|
lc["ports"].each do |port_uid,port|
if port.is_a?(Hash)
switch_remote_port = port["port"] || lc["port"] || ""
switch_remote_uid = port["uid"]
else
switch_remote_port = lc["port"] || ""
switch_remote_uid = port
end
#warn "#{node_uid}, #{switch_uid}, #{lc_uid}, #{port_uid}, #{switch_remote_uid}, #{switch_remote_port}, #{interface}"
if switch_remote_uid == node_uid and switch_remote_port == interface
# Build port name from snmp_naming_pattern
# Example: '3 2 GigabitEthernet%LINECARD%/%PORT%' -> 'GigabitEthernet3/2'
pattern = lc.has_key?("kavlan_pattern") ? lc["kavlan_pattern"] : lc["snmp_pattern"]
port_name = pattern.sub("%LINECARD%",lc_uid.to_s).sub("%PORT%",port_uid.to_s)
return switch_uid, port_name
end
end
end
end
return nil
end
refapi['sites'][site_uid]['clusters'].sort.to_h.each do |cluster_uid, cluster|
-%>
<% if cluster['kavlan'] -%>
......@@ -36,15 +10,17 @@ refapi['sites'][site_uid]['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|
interface_has_kavlan = interface.has_key?('kavlan') ? interface['kavlan'] : node['kavlan'].has_key?(interface_uid)
node['network_adapters'].each do |interface|
# puts interface.class
# pp interface
#nil.crash
interface_has_kavlan = interface['kavlan']
if interface_has_kavlan
switch_uid, kavlan_port_name = net_switch_port_lookup(refapi['sites'][site_uid], node_uid, interface_uid)
if switch_uid and kavlan_port_name
switch_uid = interface['switch']
kavlan_port_name = kavlan_switch_port_lookup(refapi['sites'][site_uid]["network_equipments"][switch_uid], node_uid, interface['device'])
-%>
<%= node_uid %><%= interface['mounted']? "" : "-"+interface_uid %>.<%= site_uid %>.grid5000.fr <%= kavlan_port_name %> <%= switch_uid %>
<%= node_uid %><%= interface['mounted']? "" : "-"+interface['device'] %>.<%= site_uid %>.grid5000.fr <%= kavlan_port_name %> <%= switch_uid %>
<%
end
end
end
end
......
......@@ -11,7 +11,7 @@ option pxelinux.reboottime code 211 = unsigned integer 32;
option vendorinfo code 43 = string;
<%
kavlan = refapi['sites'][site_uid]['kavlans'][kavlan_id]
kavlan = refapi['sites'][site_uid]['kavlans'][kavlan_id.to_s] # TODO fix needed conversion
kavlan_ip = IPAddress::IPv4::new(kavlan['network'])
-%>
......@@ -32,21 +32,24 @@ refapi['sites'].sort.to_h.each_key do |site|
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|
if (interface['mountable'] or site == "rennes") and node['kavlan'] and node['kavlan'].has_key?(interface_uid) # TODO: use interface['kavlan']
if not interface['mac'] or not node['kavlan'].has_key?(interface_uid) or not node['kavlan'][interface_uid]["kavlan-#{kavlan_id}"]
warn "WARN: Cannot fill dhcpd entry for #{node_uid}, interface #{interface_uid} in vlan #{kavlan_id}: " \
"Missing mac (#{interface['mac']}) or IP (#{node['kavlan'][interface_uid] and node['kavlan'][interface_uid]["kavlan-#{kavlan_id}"]})"
next
end
node['network_adapters'].each do |interface|
if interface['mountable'] and
interface['kavlan']
if not interface['mac'] or
not node['kavlan'][interface['device']]["kavlan-#{kavlan_id}"]
warn "WARN: Cannot fill dhcpd entry for #{node_uid}, interface #{interface_uid} in vlan #{kavlan_id}: " \
"Missing mac (#{interface['mac']}) or IP (#{node['kavlan'][interface['device']] and node['kavlan'][interface['device']]["kavlan-#{kavlan_id}"]})"
next
end
-%>
host <%= node_uid %><%= interface['mounted']? "" : "-"+interface_uid %>-kavlan-<%= kavlan_id %>.<%= site %>.grid5000.fr {
host <%= node_uid %><%= interface['mounted']? "" : "-"+interface['device'] %>-kavlan-<%= kavlan_id %>.<%= site %>.grid5000.fr {
hardware ethernet <%= interface['mac'].downcase() %>;
option host-name "<%= node_uid %><%= interface['mounted']? "" : "-"+interface_uid %>-kavlan-<%= kavlan_id %>";
option host-name "<%= node_uid %><%= interface['mounted']? "" : "-"+interface['device'] %>-kavlan-<%= kavlan_id %>";
option domain-name "<%= site %>.grid5000.fr";
option domain-search "<%= site %>.grid5000.fr", "grid5000.fr";
fixed-address <%= node['kavlan'][interface_uid]["kavlan-#{kavlan_id}"] %>;
<% if kavlan_id > 9 -%>
fixed-address <%= node['kavlan'][interface['device']]["kavlan-#{kavlan_id}"] %>;
<% if kavlan_id.to_i > 9 -%>
next-server kadeploy.<%= site %>.grid5000.fr;
<% end -%>
}
......
......@@ -21,7 +21,7 @@
"vlan": [
{"value": 100, "name": "PRODUCTION", "type": "NULL"},
<%
site_refapi['kavlans'].each do |kavlan_id, kavlan|
site_refapi['kavlans'].sort_by{ |k,v| k.to_i }.each do |kavlan_id, kavlan|
if kavlan_id.to_i.between?(1, 3)
-%>
{"value": 70<%= kavlan_id %>, "name": "KAVLAN-<%= kavlan_id %>", "type": "kavlan-local", "dhcpd": "ssh kavlan-<%= kavlan_id %> sudo /etc/init.d/isc-dhcp-server"},
......@@ -32,15 +32,15 @@
<%
end
end
(10..21).each.reject{ |kavlan_id| site_refapi['kavlans'].include?(kavlan_id) }.each do |kavlan_id|
# TODO Fix dirty conversion
(10..21).each.reject{ |kavlan_id| site_refapi['kavlans'].keys.map(&:to_i).include?(kavlan_id) }.each do |kavlan_id|
-%>
{"value": 7<%= kavlan_id %>, "name": "KAVLAN-<%= kavlan_id %>", "type": "kavlan-remote"},
<%
end
if site_refapi.has_key?('kavlan_topo')
Range.new(*site_refapi['kavlan_topo'].split("..").map{|d| Integer(d)}).each do |kavlan_topo_id| -%>
if site_refapi['kavlans'].has_key?('topo')
Range.new(*site_refapi['kavlans']['topo'].split("..").map{|d| Integer(d)}).each do |kavlan_topo_id| -%>
{"value": <%= kavlan_topo_id %>, "name": "KAVLAN-<%= kavlan_topo_id %>", "type": "kavlan-topo"},
<%
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