diff --git a/Rakefile b/Rakefile index c15c74ecdcf4ba2499186b70b3285db38b72acc3..cddc364eb8c5e9c30e0f2a9f7dc7bf7b44e9f5a3 100644 --- a/Rakefile +++ b/Rakefile @@ -207,7 +207,7 @@ 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' diff --git a/lib/refrepo/gen/puppet/stitcherg5k.rb b/lib/refrepo/gen/puppet/stitcherg5k.rb new file mode 100644 index 0000000000000000000000000000000000000000..a7c98155f76dd6193c4963a41aaddbe222d71081 --- /dev/null +++ b/lib/refrepo/gen/puppet/stitcherg5k.rb @@ -0,0 +1,28 @@ + +VLANS_FILE = "input/grid5000/vlans.yaml" +HIERA_STITCHER_TEMPLATE = "platforms/production/generators/stitcher/stitcher.yaml" +HIERA_STITCHER_OUTPUT_PATH = "platforms/production/modules/generated/files/grid5000/stitcher/stitcher.yml" +# 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 + + global_kavlans_hash = build_stitcher_kavlans_hash(refapi) + + output_hash = YAML.load_file("#{$options[:output_dir]}/#{HIERA_STITCHER_TEMPLATE}") + output_hash['defaults']['kavlans'] = global_kavlans_hash + 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