Puppet Function: sap::sysctl_calculated_values
- Defined in:
- functions/sysctl_calculated_values.pp
- Function type:
- Puppet Language
Summary
Recursive function used to compute the value for a sysctl var.Overview
Converts the provided data hash into the corresponding value. This class performs recursive calls to construct a single value when provided with a compound series of values.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'functions/sysctl_calculated_values.pp', line 19
function sap::sysctl_calculated_values(
Array[Hash] $data,
Integer $index
) >> String {
$func_name = 'sap::sysctl_calculated_value'
# Recurse until we reach the base case
if $index < length($data) - 1 {
$previous = sap::sysctl_calculated_values($data, $index + 1)
} else {
$previous = undef
}
$data_entry = $data[$index]
# Determine the calc_type
if 'calc_type' in $data_entry {
$calc_type = $data_entry['calc_type']
} else {
fail("${func_name}: a 'calc_type' must be specified! (Index ${index})")
}
# Valid calc_types are 'value' and 'calculated'
case $calc_type {
'value': {
$value = $data_entry['value']
}
'calculated': {
if 'base' in $data_entry {
$base = $data_entry['base']
} else {
fail("${func_name}: a 'base' value must be set! (Index ${index})")
}
# Multiplier defaults to 1
if 'multiplier' in $data_entry {
$multiplier = $data_entry['multiplier']
} else {
$multiplier = 1
}
# Divisor defaults to 1
if 'divisor' in $data_entry {
$divisor = $data_entry['divisor']
} else {
$divisor = 1
}
$value = $base * $multiplier / $divisor
}
default: {
fail("${func_name}: Unknown 'calc_type' '${calc_type}'! (Index ${index})")
}
}
# Assemble the output
if $previous {
$output = " ${value}${previous}"
} else {
$output = " ${value}"
}
}
|