diff options
author | James Shubin <james@shubin.ca> | 2012-08-23 15:20:43 -0400 |
---|---|---|
committer | James Shubin <james@shubin.ca> | 2012-08-23 15:20:43 -0400 |
commit | 78c92073c99fabd237e553bb7d9f47da98fc04fa (patch) | |
tree | 82a922f7109e56f16179b8a0aaafbeb0e62a1b3d | |
parent | 293f0ced9b3735796ff9cea5a6cd444ac99f83cc (diff) | |
download | puppet-gluster-78c92073c99fabd237e553bb7d9f47da98fc04fa.tar.gz puppet-gluster-78c92073c99fabd237e553bb7d9f47da98fc04fa.tar.xz puppet-gluster-78c92073c99fabd237e553bb7d9f47da98fc04fa.zip |
Autotyping support for ::property
-rw-r--r-- | manifests/volume/property.pp | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/manifests/volume/property.pp b/manifests/volume/property.pp index f9131df..1479b06 100644 --- a/manifests/volume/property.pp +++ b/manifests/volume/property.pp @@ -18,7 +18,8 @@ # NOTE: thanks to Joe Julian for: http://community.gluster.org/q/what-is-the-command-that-someone-can-run-to-get-the-value-of-a-given-property/ define gluster::volume::property( - $value + $value, + $autotype = true # set to false to disable autotyping ) { include gluster::volume::property::base @@ -30,7 +31,47 @@ define gluster::volume::property( fail('The property $name must match a $volume#$key pattern.') } - $safe_value = shellquote($value) # TODO: is this the safe thing? + # TODO: can we split out $etype lookup into a separate file, like? + # also do the same for jchar + #$etype = gluster::volume::property::etype # pull in etype hash + + # expected type # XXX: add more variables + $etype = $key ? { + 'auth.allow' => 'array', + 'auth.reject' => 'array', + #'XXX' => 'string', # XXX + #'XXXX' => 'array', # XXX + default => 'undefined', + } + + if (! $autotype) { + if type($value) != 'string' { + fail('Expecting type(string) if autotype is disabled.') + } + $safe_value = shellquote($value) # TODO: is this the safe thing? + + # if it's not a string and it's not the expected type, fail + } elsif ( type($value) != $etype ) { # type() is from puppet-common + fail("Gluster::Volume::Property[${key}] must be type: ${etype}.") + + # convert to correct type + } else { + + if $etype == 'string' { + $safe_value = shellquote($value) # TODO: is this the safe thing? + } elsif $etype == 'array' { + $jchar = $key ? { + 'auth.allow' => ',', + 'auth.deny' => ',', + default => '', + } + $safe_value = inline_template('<%= value.join(jchar) %>') + #} elsif ... { # TODO: add more conversions here if needed + + } else { + fail("Unknown type: ${etype}.") + } + } # volume set <VOLNAME> <KEY> <VALUE> # set a volume property only if value doesn't match what is available |