File tree Expand file tree Collapse file tree 5 files changed +63
-11
lines changed Expand file tree Collapse file tree 5 files changed +63
-11
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 3333# Copyright 2014 CoverMyMeds, unless otherwise noted
3434#
3535define gluster::volume::option (
36- $value = undef ,
37- $ensure = true ,
36+ Optional $value = undef ,
37+ Variant[Boolean, Enum['absent']] $ensure = true ,
3838) {
3939
40- $arr = split( $title , ' :' )
41- $count = count($arr )
40+ $arr = $title .split(' :' )
4241 # do we have more than one array element?
43- if $ count != 2 {
42+ if count( $arr ) != 2 {
4443 fail(" ${title} does not parse as volume:option" )
4544 }
46- $vol = $arr [0]
47- $opt = $arr [1]
45+ [$vol , $opt ] = $arr
4846
49- if $ensure == ' absent' {
50- $cmd = " reset ${vol} ${opt} "
47+ $_value = $value ? {
48+ Boolean => gluster::onoff($value ),
49+ default => String($value ),
50+ }
51+
52+ $cmd = if $ensure == ' absent' {
53+ " reset ${vol} ${opt} "
5154 } else {
52- $cmd = " set ${vol} ${opt} ${value } "
55+ " set ${vol} ${opt} ${_value }"
5356 }
5457
55- exec { "gluster option ${vol} ${opt} ${value}" :
58+ exec { "gluster option ${vol} ${opt} ${_value}" :
59+ path => ' /usr/bin:/usr/sbin:/bin' ,
5660 command => " ${::gluster_binary} volume ${cmd} " ,
61+ unless => unless $ensure == ' absent' {
62+ gluster::cmd_volume_get_option($vol , $opt , $_value)
63+ },
5764 }
5865}
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