File tree Expand file tree Collapse file tree 5 files changed +63
-10
lines changed Expand file tree Collapse file tree 5 files changed +63
-10
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 $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+ Boolean $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+ $cmd = if $ensure == ' absent' {
48+ " reset ${vol} ${opt} "
5149 } else {
52- $cmd = " set ${vol} ${opt} ${value} "
50+ " set ${vol} ${opt} ${value} "
51+ }
52+
53+ $_value = if $value =~ Boolean {
54+ gluster::onoff($value )
55+ } else {
56+ String($value )
5357 }
5458
5559 exec { "gluster option ${vol} ${opt} ${value}" :
60+ path => ' /usr/bin:/usr/sbin:/bin' ,
5661 command => " ${::gluster_binary} volume ${cmd} " ,
62+ unless => unless $ensure == ' absent' {
63+ gluster::cmd_volume_get_option($vol , $opt , $_value)
64+ },
5765 }
5866}
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-zA-Z0-9 ]+\.[a-zA-Z0-9 -]+$/]
You can’t perform that action at this time.
0 commit comments