|
3 | 3 | # @param title |
4 | 4 | # the name of the volume, a colon, and the name of the option |
5 | 5 | # @param value |
6 | | -# the value to set for this option |
| 6 | +# the value to set for this option. Boolean values will be coerced to |
| 7 | +# 'on'/'off'. |
7 | 8 | # @param ensure |
8 | 9 | # whether to set or remove an option |
9 | 10 | # |
|
26 | 27 | # @note Copyright 2014 CoverMyMeds, unless otherwise noted |
27 | 28 | # |
28 | 29 | define gluster::volume::option ( |
29 | | - Optional[String] $value = undef, |
| 30 | + Optional[Boolean, String] $value = undef, |
30 | 31 | Enum['present', 'absent'] $ensure = 'present', |
31 | 32 | ) { |
32 | 33 |
|
33 | | - $arr = split( $title, ':' ) |
34 | | - $count = count($arr) |
| 34 | + $arr = $title.split(':') |
35 | 35 | # do we have more than one array element? |
36 | | - if $count != 2 { |
| 36 | + if count($arr) != 2 { |
37 | 37 | fail("${title} does not parse as volume:option") |
38 | 38 | } |
39 | | - $vol = $arr[0] |
40 | | - $opt = $arr[1] |
| 39 | + [$vol, $opt] = $arr |
41 | 40 |
|
42 | | - if $ensure == 'absent' { |
43 | | - $cmd = "reset ${vol} ${opt}" |
| 41 | + $_value = $value ? { |
| 42 | + Boolean => gluster::onoff($value), |
| 43 | + default => String($value), |
| 44 | + } |
| 45 | + |
| 46 | + $cmd = if $ensure == 'absent' { |
| 47 | + "reset ${vol} ${opt}" |
44 | 48 | } else { |
45 | | - $cmd = "set ${vol} ${opt} ${value}" |
| 49 | + "set ${vol} ${opt} ${_value}" |
46 | 50 | } |
47 | 51 |
|
48 | | - exec { "gluster option ${vol} ${opt} ${value}": |
| 52 | + exec { "gluster option ${vol} ${opt} ${_value}": |
| 53 | + path => '/usr/bin:/usr/sbin:/bin', |
49 | 54 | command => "${::gluster_binary} volume ${cmd}", |
| 55 | + unless => unless $ensure == 'absent' { |
| 56 | + gluster::cmd_volume_get_option($vol, $opt, $_value) |
| 57 | + }, |
50 | 58 | } |
51 | 59 | } |
0 commit comments