Skip to content

Commit

Permalink
Merge branch 'get_size_IEC_vs_metric' into 'master'
Browse files Browse the repository at this point in the history
Fix size in wiki pages: iec for RAM size vs metric for disks size

See merge request grid5000/reference-repository!1
  • Loading branch information
NEYRON Pierre committed Dec 4, 2018
2 parents 0026e36 + ffdd4dc commit f82e850
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
6 changes: 3 additions & 3 deletions lib/refrepo/gen/wiki/generators/hardware.rb
Expand Up @@ -274,19 +274,19 @@ def generate_storage
sd = node_hash['storage_devices']
reservable_disks = sd.to_a.select{ |v| v[1]['reservation'] == true }.count > 0
maindisk = sd.to_a.select { |v| v[0] == 'sda' }.first[1]
maindisk_t = maindisk['storage'] + ' ' + G5K.get_size(maindisk['size'])
maindisk_t = maindisk['storage'] + ' ' + G5K.get_size(maindisk['size'],'metric')
other = sd.to_a.select { |d| d[0] != 'sda' }
hdds = other.select { |d| d[1]['storage'] == 'HDD' }
if hdds.count == 0
hdd_t = "0"
else
hdd_t = hdds.count.to_s + " (" + hdds.map { |d| G5K.get_size(d[1]['size']) }.join(', ') + ")"
hdd_t = hdds.count.to_s + " (" + hdds.map { |d| G5K.get_size(d[1]['size'],'metric') }.join(', ') + ")"
end
ssds = other.select { |d| d[1]['storage'] == 'SSD' }
if ssds.count == 0
ssd_t = "0"
else
ssd_t = ssds.count.to_s + " (" + ssds.map { |d| G5K.get_size(d[1]['size']) }.join(', ') + ")"
ssd_t = ssds.count.to_s + " (" + ssds.map { |d| G5K.get_size(d[1]['size'],'metric') }.join(', ') + ")"
end
queues = cluster_hash['queues'] - ['admin', 'default']
queue_t = (queues.nil? || (queues.empty? ? '' : "_.28" + queues[0].gsub(' ', '_') + ' queue.29'))
Expand Down
4 changes: 2 additions & 2 deletions lib/refrepo/gen/wiki/generators/site_hardware.rb
Expand Up @@ -201,10 +201,10 @@ def get_hardware(sites)
hard['processor_description'] = "#{hard['processor_model']} (#{hard['microarchitecture']}#{hard['processor_freq'] ? ', ' + hard['processor_freq'] : ''}, #{hard['cpus_per_node_str']}, #{hard['cores_per_cpu_str']})"
hard['ram_size'] = G5K.get_size(node_hash['main_memory']['ram_size'])
storage = node_hash['storage_devices'].map{ |k, v| {'size' => v['size'], 'tech' => v['storage']} }
hard['storage'] = storage.each_with_object(Hash.new(0)) { |data, counts| counts[data] += 1 }.to_a.sort_by { |e| e[0]['size'].to_f }.map{ |e| (e[1] == 1 ? '' : e[1].to_s + ' x ') + G5K.get_size(e[0]['size']) + ' ' + e[0]['tech'] }.join(' + ')
hard['storage'] = storage.each_with_object(Hash.new(0)) { |data, counts| counts[data] += 1 }.to_a.sort_by { |e| e[0]['size'].to_f }.map{ |e| (e[1] == 1 ? '' : e[1].to_s + ' x ') + G5K.get_size(e[0]['size'],'metric') + ' ' + e[0]['tech'] }.join(' + ')
hard['storage_size'] = storage.inject(0){|sum, v| sum + (v['size'].to_f / 2**30).floor }.to_s # round to GB to avoid small differences within a cluster
storage_description = node_hash['storage_devices'].map { |k, v| { 'device' => v['device'], 'size' => v['size'], 'tech' => v['storage'], 'interface' => v['interface'], 'model' => v['model'], 'driver' => v['driver'], 'path' => v['by_path'] || v['by_id'], 'count' => node_hash['storage_devices'].count } }
hard['storage_description'] = storage_description.map { |e| [ e['count'] > 1 ? "\n*" : '', G5K.get_size(e['size']), e['tech'], e['interface'], e['model'], ' (driver: ' + (e['driver'] || 'MISSING') + ', path: ' + (e['path'] || 'MISSING') + ')'].join(' ') }.join('<br />')
hard['storage_description'] = storage_description.map { |e| [ e['count'] > 1 ? "\n*" : '', G5K.get_size(e['size'],'metric'), e['tech'], e['interface'], e['model'], ' (driver: ' + (e['driver'] || 'MISSING') + ', path: ' + (e['path'] || 'MISSING') + ')'].join(' ') }.join('<br />')

network = node_hash['network_adapters'].select { |k, v|
v['management'] == false &&
Expand Down
19 changes: 14 additions & 5 deletions lib/refrepo/gen/wiki/mw_utils.rb
Expand Up @@ -77,12 +77,21 @@ def self.nodeset(a)
s += ']'
end

def self.get_size(x)
gbytes = (x.to_f / 2**30).floor
if gbytes < 2**10
gbytes.to_s + '&nbsp;GB'
def self.get_size(x, unit='IEC')
if unit == 'metric'
giga = (x.to_f / 1000**3).floor
if giga < 1000
giga.to_s + '&nbsp;GB'
else
(x.to_f / 1000**4).round(2).to_s + '&nbsp;TB'
end
else
(x.to_f / 2**40).round(3).to_s + '&nbsp;TB'
giga = (x.to_f / 2**30).floor
if giga < 2**10
giga.to_s + '&nbsp;GiB'
else
(x.to_f / 2**40).round(2).to_s + '&nbsp;TiB'
end
end
end

Expand Down

0 comments on commit f82e850

Please sign in to comment.