Top Level Namespace
Defined Under Namespace
Modules: KnifeVsphere Classes: Chef
Constant Summary collapse
- PsOn =
'poweredOn'
- PsOff =
'poweredOff'
- PsSuspended =
'suspended'
- PowerStates =
{ PsOn => 'powered on', PsOff => 'powered off', PsSuspended => 'suspended' }
Instance Method Summary collapse
Instance Method Details
#number_to_human_size(number) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/chef/knife/vsphere_datastore_list.rb', line 21 def number_to_human_size(number) number = number.to_f storage_units_fmt = ["byte", "kB", "MB", "GB", "TB"] base = 1024 if number.to_i < base unit = storage_units_fmt[0] else max_exp = storage_units_fmt.size - 1 exponent = (Math.log(number) / Math.log(base)).to_i # Convert to base exponent = max_exp if exponent > max_exp # we need this to avoid overflow for the highest unit number /= base ** exponent unit = storage_units_fmt[exponent] end return sprintf("%0.2f %s", number, unit) end |