Commit ffdd4dcf authored by Pierre Neyron's avatar Pierre Neyron 🚴

Add option unit to get_size: IEC or metric

e.g.:
IEC for disks
metric for RAM
parent 0026e36e
Pipeline #52851 passed with stages
in 1 minute and 33 seconds
......@@ -274,19 +274,19 @@ class G5KHardwareGenerator < WikiGenerator
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'))
......
......@@ -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 + '&nbsp;x&nbsp;') + G5K.get_size(e[0]['size']) + '&nbsp;' + e[0]['tech'] }.join(' +&nbsp;')
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 + '&nbsp;x&nbsp;') + G5K.get_size(e[0]['size'],'metric') + '&nbsp;' + e[0]['tech'] }.join(' +&nbsp;')
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 &&
......
......@@ -77,12 +77,21 @@ module G5K
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
......
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