diff options
author | James Shubin <james@shubin.ca> | 2014-03-09 21:23:53 -0400 |
---|---|---|
committer | James Shubin <james@shubin.ca> | 2014-03-16 22:39:07 -0400 |
commit | 70b41db233f28fcb39011b0bd694ba5211ef4989 (patch) | |
tree | a1ed9dab4396dfcd5739a912e64f4523538202a4 | |
parent | 7057c914942eb0fdfd061ad227a5c5ac255d296d (diff) | |
download | puppet-gluster-70b41db233f28fcb39011b0bd694ba5211ef4989.tar.gz puppet-gluster-70b41db233f28fcb39011b0bd694ba5211ef4989.tar.xz puppet-gluster-70b41db233f28fcb39011b0bd694ba5211ef4989.zip |
Add advanced set group support for anyone without stock support.
This adds custom set group support for users that might not have the
feature (I think it might only exist in RHS) and also to users who want
to add their own custom groups! Please ping me if the stock groups gain
or lose parameters, or if their set values change!
-rw-r--r-- | files/groups/small-file-perf | 2 | ||||
-rw-r--r-- | files/groups/virt | 8 | ||||
-rw-r--r-- | lib/facter/gluster_property.rb | 68 | ||||
-rw-r--r-- | manifests/volume/property/group.pp | 35 | ||||
-rw-r--r-- | manifests/volume/property/group/data.pp | 40 |
5 files changed, 124 insertions, 29 deletions
diff --git a/files/groups/small-file-perf b/files/groups/small-file-perf new file mode 100644 index 0000000..a718522 --- /dev/null +++ b/files/groups/small-file-perf @@ -0,0 +1,2 @@ +quick-read=on +open-behind=on diff --git a/files/groups/virt b/files/groups/virt new file mode 100644 index 0000000..0abe9f4 --- /dev/null +++ b/files/groups/virt @@ -0,0 +1,8 @@ +quick-read=off +read-ahead=off +io-cache=off +stat-prefetch=off +eager-lock=enable +remote-dio=enable +quorum-type=auto +server-quorum-type=server diff --git a/lib/facter/gluster_property.rb b/lib/facter/gluster_property.rb index 4c47dd4..17a889d 100644 --- a/lib/facter/gluster_property.rb +++ b/lib/facter/gluster_property.rb @@ -17,29 +17,55 @@ require 'facter' -groupdir = '/var/lib/glusterd/groups/' +groupdir = '/var/lib/glusterd/groups/' # dir from the upstream package + +# find the module_vardir +dir = Facter.value('puppet_vardirtmp') # nil if missing +if dir.nil? # let puppet decide if present! + dir = Facter.value('puppet_vardir') + if dir.nil? + var = nil + else + var = dir.gsub(/\/$/, '')+'/'+'tmp/' # ensure trailing slash + end +else + var = dir.gsub(/\/$/, '')+'/' +end + +if var.nil? + # if we can't get a valid vardirtmp, then we can't continue + valid_setgroupdir = nil +else + module_vardir = var+'gluster/' + valid_setgroupdir = module_vardir.gsub(/\/$/, '')+'/groups/' +end found = {} -if File.directory?(groupdir) - Dir.glob(groupdir+'*.*').each do |f| - b = File.basename(f) +# loop through each directory to avoid code duplication... later dirs override! +[valid_setgroupdir, groupdir].each do |g| - if not found.key?(b) - found[b] = {} # initialize - end + if not(g.nil?) and File.directory?(g) + Dir.glob(g+'*.*').each do |f| + b = File.basename(f) - groups = File.open(f, 'r').read # read into str - groups.each_line do |line| - split = line.split('=') # split key=value pairs - if split.length == 2 - key = split[0] - value = split[1] - if found[b].key?(key) - # NOTE: error found in file... - print "There is a duplicate key in the '#{b}' group." + # a later entry overrides an earlier one... + #if not found.key?(b) + found[b] = {} # initialize (or erase) + #end + + groups = File.open(f, 'r').read # read into str + groups.each_line do |line| + split = line.split('=') # split key=value pairs + if split.length == 2 + key = split[0] + value = split[1] + if found[b].key?(key) + # NOTE: error found in file... + print "There is a duplicate key in the '#{b}' group." + end + found[b][key] = value end - found[b][key] = value end end end @@ -66,4 +92,12 @@ found.keys.each do |x| end end +# has the custom group directory been created yet? +Facter.add('gluster_property_groups_ready') do + #confine :operatingsystem => %w{CentOS, RedHat, Fedora} + setcode { + (File.directory?(valid_setgroupdir) ? 'true':'false') + } +end + # vim: ts=8 diff --git a/manifests/volume/property/group.pp b/manifests/volume/property/group.pp index 8901553..97c03b7 100644 --- a/manifests/volume/property/group.pp +++ b/manifests/volume/property/group.pp @@ -27,6 +27,7 @@ define gluster::volume::property::group( include gluster::xml include gluster::vardir include gluster::volume::property + include gluster::volume::property::group::data #$vardir = $::gluster::vardir::module_vardir # with trailing slash $vardir = regsubst($::gluster::vardir::module_vardir, '\/$', '') @@ -42,19 +43,29 @@ define gluster::volume::property::group( $groups = split($gluster_property_groups, ',') # fact if ! ("${group}" in $groups) { - fail("The group named '${group}' is not available.") - } - # read the fact that comes from the data in: /var/lib/glusterd/groups/* - $group_data_string = getvar("gluster_property_group_${name}") # fact! - # each element in this list is a key=value string - $group_data_list = split("${group_data_string}", ',') - # split into the correct hash to create all the properties - $group_data_yaml = inline_template("<%= @group_data_list.inject(Hash.new) { |h,i| { '${volume}#'+((i.split('=').length == 2) ? i.split('=')[0] : '') => {'value' => ((i.split('=').length == 2) ? i.split('=')[1] : '')} }.merge(h) }.to_yaml %>") - # build into a hash - $group_data_hash = parseyaml($group_data_yaml) - # create the properties - create_resources('gluster::volume::property', $group_data_hash) + # check a fact to see if the directory is built yet... this + # prevents weird corner cases where this module is added to + # a new machine which is already built, except doesn't have + # the custom group data installed yet. if we fail, we won't + # be able to install it, so we don't fail, we warn instead! + if "${gluster_property_groups_ready}" == 'true' { + warning("The group named '${group}' is not available.") + } else { + notice("The group '${group}' might not be built yet.") + } + } else { + # read the fact that comes from the data in: /var/lib/glusterd/groups/* + $group_data_string = getvar("gluster_property_group_${group}") # fact! + # each element in this list is a key=value string + $group_data_list = split("${group_data_string}", ',') + # split into the correct hash to create all the properties + $group_data_yaml = inline_template("<%= @group_data_list.inject(Hash.new) { |h,i| { '${volume}#'+((i.split('=').length == 2) ? i.split('=')[0] : '') => {'value' => ((i.split('=').length == 2) ? i.split('=')[1] : '')} }.merge(h) }.to_yaml %>") + # build into a hash + $group_data_hash = parseyaml($group_data_yaml) + # create the properties + create_resources('gluster::volume::property', $group_data_hash) + } } # vim: ts=8 diff --git a/manifests/volume/property/group/data.pp b/manifests/volume/property/group/data.pp new file mode 100644 index 0000000..c731266 --- /dev/null +++ b/manifests/volume/property/group/data.pp @@ -0,0 +1,40 @@ +# GlusterFS module by James +# Copyright (C) 2012-2013+ James Shubin +# Written by James Shubin <james@shubin.ca> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# NOTE: this provides an internal repository of volume parameter set groups and +# can be useful if the version of glusterfs does not have set group support, or +# if this module wants to distribute some custom groups which are not upstream. + +class gluster::volume::property::group::data() { + + include gluster::vardir + + #$vardir = $::gluster::vardir::module_vardir # with trailing slash + $vardir = regsubst($::gluster::vardir::module_vardir, '\/$', '') + + file { "${vardir}/groups/": + source => 'puppet:///modules/gluster/groups/', + owner => root, + group => nobody, + mode => 644, # u=rwx + backup => false, # don't backup to filebucket + ensure => present, + require => File["${vardir}/"], + } +} + +# vim: ts=8 |