Revision 6d97be8e
Added by Rob Sanders about 8 years ago
lib/core_extensions.rb | ||
---|---|---|
|
||
def to_gb
|
||
begin
|
||
value, _, unit=self.match(/(\d+(\.\d+)?) ?(([KMGT]B?|B))$/i)[1..3]
|
||
value, _, unit=self.match(/(\d+(\.\d+)?) ?(([KMGT]i?B?|B))$/i)[1..3]
|
||
case unit.to_sym
|
||
when nil, :B, :byte then (value.to_f / Foreman::SIZE[:giga])
|
||
when :TB, :T, :terabyte then (value.to_f * Foreman::SIZE[:kilo])
|
||
when :GB, :G, :gigabyte then value.to_f
|
||
when :MB, :M, :megabyte then (value.to_f / Foreman::SIZE[:kilo])
|
||
when :KB, :K, :kilobyte, :kB then (value.to_f / Foreman::SIZE[:mega])
|
||
when :TB, :TiB, :T, :terabyte then (value.to_f * Foreman::SIZE[:kilo])
|
||
when :GB, :GiB, :G, :gigabyte then value.to_f
|
||
when :MB, :MiB, :M, :megabyte then (value.to_f / Foreman::SIZE[:kilo])
|
||
when :KB, :KiB, :K, :kilobyte, :kB then (value.to_f / Foreman::SIZE[:mega])
|
||
else raise "Unknown unit: #{unit.inspect}!"
|
||
end
|
||
rescue
|
Also available in: Unified diff
fixes #14096 - handle MiB style memory units on statistics page
(cherry picked from commit b24feca26d2f7b3f9bfb6a40680446ccebb3d44b)