File tree Expand file tree Collapse file tree 5 files changed +61
-17
lines changed Expand file tree Collapse file tree 5 files changed +61
-17
lines changed Original file line number Diff line number Diff line change 1+ # Create a command string to get option `$opt` from gluster volume `$vol`, and
2+ # optionally compare it against `$comparison`.
3+ #
4+ # @param vol [Gluster::VolumeName] Gluster volume name
5+ # @param opt [Gluster::OptionName] Gluster volume option name
6+ # @param comparison [Optional[String]] Optional string to compare the existing
7+ # value against
8+ # @return [String]
9+ #
10+ # @example Usage
11+ #
12+ # ```puppet
13+ # gluster::cmd_volume_get_option('data', 'nfs.disable', String(true))
14+ # ```
15+ #
16+ function gluster::cmd_volume_get_option(
17+ Gluster::VolumeName $vol ,
18+ Gluster::VolumeOption $opt ,
19+ Optional[Any] $comparison = undef ,
20+ ) {
21+ $_cmd = " ${::gluster_binary} volume get ${vol} ${opt} "
22+
23+ unless $comparison {
24+ return $_cmd
25+ }
26+
27+ $_comparison = $comparison ? {
28+ Undef => ' \( null\) ' ,
29+ Boolean => gluster::onoff($comparison ),
30+ default => $comparison ,
31+ }
32+
33+ " ${_cmd} | tail -n1 | grep -E '^${opt} +${_comparison} *\$ '"
34+ }
Original file line number Diff line number Diff line change 1+ function gluster::onoff (
2+ Boolean $value ,
3+ ) {
4+ if $value {
5+ ' on'
6+ } else {
7+ ' off'
8+ }
9+ }
Original file line number Diff line number Diff line change 33# @param title
44# the name of the volume, a colon, and the name of the option
55# @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'.
78# @param ensure
89# whether to set or remove an option
910#
3031 Enum['present', 'absent'] $ensure = ' present' ,
3132) {
3233
33- $arr = split( $title , ' :' )
34- $count = count($arr )
34+ $arr = $title .split(' :' )
3535 # do we have more than one array element?
36- if $ count != 2 {
36+ if count( $arr ) != 2 {
3737 fail(" ${title} does not parse as volume:option" )
3838 }
39- $vol = $arr [0]
40- $opt = $arr [1]
39+ [$vol , $opt ] = $arr
40+
41+ $_value = $value ? {
42+ Boolean => gluster::onoff($value ),
43+ default => String($value ),
44+ }
4145
4246 $cmd = if $ensure == ' absent' {
4347 " reset ${vol} ${opt} "
4448 } else {
45- " set ${vol} ${opt} ${value} "
46- }
47-
48- $_value = $value ? {
49- Boolean => if $value {
50- ' on'
51- } else {
52- ' off'
53- },
54- default => $value ,
49+ " set ${vol} ${opt} ${_value}"
5550 }
5651
5752 exec { "gluster option ${vol} ${opt} ${_value}" :
58- command => " ${facts['gluster_binary']} volume ${cmd} " ,
53+ path => ' /usr/bin:/usr/sbin:/bin' ,
54+ command => " ${::gluster_binary} volume ${cmd} " ,
55+ unless => unless $ensure == ' absent' {
56+ gluster::cmd_volume_get_option($vol , $opt , $_value)
57+ },
5958 }
6059}
Original file line number Diff line number Diff line change 1+ type Gluster::VolumeName = Pattern[/^[a-zA-Z0-9_-]+$/]
Original file line number Diff line number Diff line change 1+ type Gluster::VolumeOption = Pattern[/^[a-z0-9 ]+\.[a-z0-9 -]+$/]
You can’t perform that action at this time.
0 commit comments