diff --git a/lib/refrepo/gen/puppet/clusters.rb b/lib/refrepo/gen/puppet/clusters.rb index d75dfcf55f1732315c3580fbcdb591725eca6489..692f3240011eb3b0278e18683651f7f9b7426999 100644 --- a/lib/refrepo/gen/puppet/clusters.rb +++ b/lib/refrepo/gen/puppet/clusters.rb @@ -17,7 +17,7 @@ def generate_puppet_clusters(options) puts "Add #{s_uid}" hiera[s_uid] = {} end - s_hash['clusters'].sort_by{|c_uid, _c_hash| [c_uid[/(\D+)/, 1], c_uid[/(\d+)/, 1].to_i]}.each do |c_uid, c_hash| + s_hash['clusters'].sort_by{|c_uid, _c_hash| split_cluster_node(c_uid) }.each do |c_uid, c_hash| if ! hiera[s_uid].key? c_uid puts " Add #{s_uid}" hiera[s_uid][c_uid] = {} @@ -46,4 +46,4 @@ def generate_puppet_clusters(options) outfile = File.open("#{options[:conf_dir]}clusters.yaml", "w") outfile.write({'grid5000::clusters' => hiera}.to_yaml) -end \ No newline at end of file +end diff --git a/lib/refrepo/gen/puppet/oarsub-simplifier-aliases.rb b/lib/refrepo/gen/puppet/oarsub-simplifier-aliases.rb index 29a6d27be0612a2e71ebbecb6a20324cfd7caadb..c50c8fe6faa85da3e416a9383de70018f332e32d 100644 --- a/lib/refrepo/gen/puppet/oarsub-simplifier-aliases.rb +++ b/lib/refrepo/gen/puppet/oarsub-simplifier-aliases.rb @@ -61,7 +61,7 @@ def generate_all_sites_aliases aliases[site][cluster] = "cluster='#{cluster}'" aliases[site]["#{cluster}-%d"] = "host='#{cluster}-%d.#{site}.grid5000.fr'" end - aliases[site] = aliases[site].sort_by { |cluster, _| [cluster[/(\D+)/, 1], cluster[/(\d+)/, 1].to_i] }.to_h + aliases[site] = aliases[site].sort_by { |cluster, _| split_cluster_node(cluster) }.to_h end aliases = aliases.sort_by { |site, _| site }.to_h diff --git a/lib/refrepo/gen/puppet/webfish.rb b/lib/refrepo/gen/puppet/webfish.rb index ad234f0295abff4f188122b4c5ec06c88be1c392..7fdf0ed813d3244a39fed1c6b674938540f9683d 100644 --- a/lib/refrepo/gen/puppet/webfish.rb +++ b/lib/refrepo/gen/puppet/webfish.rb @@ -101,7 +101,7 @@ def gen_json_files(allBmc, options) dir = "#{options[:output_dir]}/platforms/production/modules/generated/files/grid5000/webfish" checks_dir_creation(dir) allBmc.sort_by{ |s_site, _d_site| s_site}.each do |s_site, _d_array| - actualFile = allBmc[s_site].sort_by{|k, _| [k[/(\D+)/, 1], k[/(\d+)/, 1].to_i, k[/-(\d+)/, 1].to_i]}.to_h + actualFile = allBmc[s_site].sort_by{|k, _| split_cluster_node(k) }.to_h siteLocation = dir + "/" + s_site checks_dir_creation(siteLocation) fileLocation = siteLocation + "/webfish.json" @@ -109,4 +109,4 @@ def gen_json_files(allBmc, options) f.write(JSON.pretty_generate(actualFile)) end end -end \ No newline at end of file +end diff --git a/lib/refrepo/gen/reference-api.rb b/lib/refrepo/gen/reference-api.rb index 52b4077495ca5ae8b4d22aa02725cfce6118130c..e6361053cf14d0984eaccb91dc2c38f1017daf78 100644 --- a/lib/refrepo/gen/reference-api.rb +++ b/lib/refrepo/gen/reference-api.rb @@ -210,7 +210,8 @@ def generate_reference_api # Add nodes details to cluster description cluster['nodes_count'] = cluster['nodes'].length - cluster['nodes_description'] = gen_node_description(cluster['nodes'].values.first) + first_node = cluster['nodes'].values.select { |x| not x['status'] == 'retired' }.sort_by { |x| split_cluster_node(x['uid']) }.first # use first non-retired node + cluster['nodes_description'] = gen_node_description(first_node) # Write cluster info w/o nodes entries write_json(cluster_path.join("#{cluster_uid}.json"), diff --git a/lib/refrepo/gen/wiki/generators/site_hardware.rb b/lib/refrepo/gen/wiki/generators/site_hardware.rb index b921ac24a708b9c0d1856bcd77f36728f213cb91..12ec69699e921ee65f101f0b82f064089efa867e 100644 --- a/lib/refrepo/gen/wiki/generators/site_hardware.rb +++ b/lib/refrepo/gen/wiki/generators/site_hardware.rb @@ -189,7 +189,7 @@ class SiteHardwareGenerator < WikiGenerator site_accelerators += cluster_hash.select { |_k, v| v['accelerators'] != '' }.count } - hardware[site].sort_by{|cluster_uid, _cluster_hash| [cluster_uid[/(\D+)/, 1], cluster_uid[/(\d+)/, 1].to_i]}.to_h.each { |cluster_uid, cluster_hash| + hardware[site].sort_by{|cluster_uid, _cluster_hash| split_cluster_node(cluster_uid) }.to_h.each { |cluster_uid, cluster_hash| cluster_nodes = cluster_hash.keys.flatten.count queue = cluster_hash.map { |_k, v| v['queue']}.first access_conditions = [] @@ -253,7 +253,7 @@ class SiteHardwareGenerator < WikiGenerator else text_data << "\n= Clusters in the #{queue} queue =" end - clusters.sort_by{|cluster_uid, _cluster_hash| [cluster_uid[/(\D+)/, 1], cluster_uid[/(\d+)/, 1].to_i]}.to_h.each { |cluster_uid, cluster_hash| + clusters.sort_by{|cluster_uid, _cluster_hash| split_cluster_node(cluster_uid) }.to_h.each { |cluster_uid, cluster_hash| subclusters = cluster_hash.keys.count != 1 cluster_nodes = cluster_hash.keys.flatten.count cluster_cpus = cluster_hash.map { |k, v| k.count * v['cpus_per_node'] }.reduce(:+) diff --git a/lib/refrepo/utils.rb b/lib/refrepo/utils.rb index aa7c1f5e2fce0d09e644f89bd553eed8abb839af..772ed3b3f398bcd90f5a9f891726849b9e884f45 100644 --- a/lib/refrepo/utils.rb +++ b/lib/refrepo/utils.rb @@ -52,3 +52,7 @@ class Hash h2 end end + +def split_cluster_node(k) + [k[/([a-z]+)/, 1], k[/[a-z](\d+)/, 1].to_i, k[/-(\d+)/, 1].to_i] +end