Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 9ea4c5f3 authored by JACQUOT Pierre's avatar JACQUOT Pierre
Browse files

Merge branch 'stitcher' into 'master'

[stitcherg5k] Generate yaml configuration for G5K stitcher

See merge request !549
parents ebf152ed e154f678
Branches
No related tags found
1 merge request!549[stitcherg5k] Generate yaml configuration for G5K stitcher
Pipeline #891643 passed with warnings
......@@ -207,11 +207,20 @@ namespace :gen do
namespace :puppet do
all_puppet_tasks = [:bindg5k, :conmang5k, :dhcpg5k, :kadeployg5k, :lanpowerg5k, :kavlang5k, :kwollectg5k, :network_monitoring, :'refapi-subset', :oxidizedg5k, :'oarsub-simplifier-aliases', :kavlanngg5k]
all_puppet_tasks = [:bindg5k, :conmang5k, :dhcpg5k, :kadeployg5k, :lanpowerg5k, :kavlang5k, :kwollectg5k, :network_monitoring, :'refapi-subset', :oxidizedg5k, :'oarsub-simplifier-aliases', :kavlanngg5k, :stitcherg5k]
all_puppet_tasks.each { |t|
generated_desc = (t == :'refapi-subset') ? 'description' : 'configuration'
desc "Generate #{t} #{generated_desc} -- parameters: [SITE={grenoble,...}] [OUTPUTDIR=(default: #{PUPPET_ODIR})] [CONFDIR=...] [VERBOSE=1]"
# tasks oxidizedg5k, kavlanng5k and stitcherg5K doesn't use the parameters
# SITE, CLUSTER and VERBOSE. So we don't print them in the 'rake -T' for
# theses tasks.
parameters = "[OUTPUTDIR=(default: #{PUPPET_ODIR})] [CONFDIR=...]"
if not [:oxidizedg5k, :kavlanngg5k, :stitcherg5k].include? t
parameters = "[SITE={grenoble,...}] #{parameters} [VERBOSE=1]"
end
desc "Generate #{t} #{generated_desc} -- parameters: #{parameters}"
task t do
require "refrepo/gen/puppet/#{t}"
options = {}
......
VLANS_FILE = "input/grid5000/vlans.yaml"
PLATFORM = "platforms/production"
HIERA_STITCHER_TEMPLATE = "#{PLATFORM}/generators/stitcher/stitcher.yaml"
HIERA_STITCHER_OUTPUT_PATH = "#{PLATFORM}/modules/generated/files/grid5000/stitcher/stitcher.yml"
STITCHER_MODES = ['production', 'development', 'test']
# main method
def generate_puppet_stitcherg5k(options)
$options = options
output_file_path = "#{$options[:output_dir]}/#{HIERA_STITCHER_OUTPUT_PATH}"
puts "Writing stitcher configuration in #{output_file_path}"
output = File.new(output_file_path, "w+")
refapi = load_data_hierarchy
base_config = YAML.load_file("#{$options[:output_dir]}/#{HIERA_STITCHER_TEMPLATE}")
sorted_kavlans = Hash.new
# Ruby sorting dark magic happening below:
# The goal is to order the vlans entries by vlan id to have an easy to read conf file.
# Since ruby hashes enumerate their values in the order
# that the corresponding keys were inserted, we sort the
# vlan keys and reinsert them back with their values in a
# new hash that is de facto sorted.
build_stitcher_kavlans_hash(refapi)
.sort_by {|key, _value| key}
.each {|a| sorted_kavlans[a[0]] = a[1]}
output_hash = merge_config(base_config, sorted_kavlans)
output.write("# MANAGED BY PUPPET\n")
output.write(output_hash.to_yaml)
end
def build_stitcher_kavlans_hash(refapi)
stitcher_kavlans_hash = {}
refapi['sites'].each do |name, site_hash|
global_kavlan = site_hash['kavlans'].select { | id, _hash | id =~ /\d\d/ }.first
global_kavlan_id = global_kavlan.first.to_i
stitcher_kavlans_hash[global_kavlan_id] = {"vlan" => 700 + global_kavlan_id, "site" => name}
end
return stitcher_kavlans_hash
end
def merge_config(base_config, kavlans)
output_hash = {}
STITCHER_MODES.each do |mode|
output_hash[mode] = {'kavlans' => kavlans}
base_config.each do |key, value|
output_hash[mode][key] = value
end
end
return output_hash
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment