Puppet Function: lvm::bytes_to_size

Defined in:
vendor_modules/lvm/functions/bytes_to_size.pp
Function type:
Puppet Language

Overview

lvm::bytes_to_size(Numeric $size)Any

Parameters:

  • size (Numeric)

Returns:

  • (Any)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'vendor_modules/lvm/functions/bytes_to_size.pp', line 1

function lvm::bytes_to_size (
  Numeric $size,
) {
  $units = {
    'k' => 1024,
    'm' => 1048576,
    'g' => 1073741824,
    't' => 1099511627776,
    'p' => 1.12589991e15,
    'e' => 1.1529215e18,
  }
  $remaining_units = $units.filter |$name, $number| {
    # Run all the calculation and return only units that are greater than one
    $size_as_unit = $size / $number
    $size_as_unit >= 1
  }

  # Use the last unit
  $largest_unit = $remaining_units.keys[-1]

  $value = ($size / $units[$largest_unit])

  # # Return the string
  "${value}${largest_unit}"
}