-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix unnecessarily setting gluster volume option repeatedly
Checks Gluster volume options against existing values to avoid repeatedly setting values Also adds these types: + `Gluster::VolumeName` + `Gluster::VolumeOption` And these functions: + `gluster::cmd_volume_get_option` + `gluster::onoff`
- Loading branch information
Showing
5 changed files
with
63 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Create a command string to get option `$opt` from gluster volume `$vol`, and | ||
# optionally compare it against `$comparison`. | ||
# | ||
# @param vol [Gluster::VolumeName] Gluster volume name | ||
# @param opt [Gluster::OptionName] Gluster volume option name | ||
# @param comparison [Optional[String]] Optional string to compare the existing | ||
# value against | ||
# @return [String] | ||
# | ||
# @example Usage | ||
# | ||
# ```puppet | ||
# gluster::cmd_volume_get_option('data', 'nfs.disable', String(true)) | ||
# ``` | ||
# | ||
function gluster::cmd_volume_get_option( | ||
Gluster::VolumeName $vol, | ||
Gluster::VolumeOption $opt, | ||
Optional[Any] $comparison = undef, | ||
) { | ||
$_cmd = "${::gluster_binary} volume get ${vol} ${opt}" | ||
|
||
unless $comparison { | ||
return $_cmd | ||
} | ||
|
||
$_comparison = $comparison ? { | ||
Undef => '\(null\)', | ||
Boolean => gluster::onoff($comparison), | ||
default => $comparison, | ||
} | ||
|
||
"${_cmd} | tail -n1 | grep -E '^${opt} +${_comparison} *\$'" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function gluster::onoff ( | ||
Boolean $value, | ||
) { | ||
if $value { | ||
'on' | ||
} else { | ||
'off' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type Gluster::VolumeName = Pattern[/^[a-zA-Z0-9_-]+$/] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type Gluster::VolumeOption = Pattern[/^[a-z0-9]+\.[a-z0-9-]+$/] |