Permalink
Browse files

Added fancy volume creation.

This moves the command into a separate file. This also adds temporary
saving of stdout and stderr to /tmp for easy debugging of command
output.
  • Loading branch information...
1 parent d1a2fb7 commit fa3fd2eb4bab499031274e0918a40e7a99fe0086 @purpleidea committed Sep 18, 2013
Showing with 52 additions and 1 deletion.
  1. +20 −1 manifests/volume.pp
  2. +32 −0 manifests/volume/base.pp
View
@@ -26,6 +26,7 @@
) {
include gluster::xml
include gluster::vardir
+ include gluster::volume::base
if $ping {
include gluster::volume::ping
}
@@ -78,6 +79,8 @@
# will error if they see that volume directory already present, so when
# we error we should rmdir any empty volume dirs to keep it pristine...
# TODO: this should be a gluster bug... we must hope it doesn't happen!
+ # maybe related to: https://bugzilla.redhat.com/show_bug.cgi?id=835494
+ $rmdir_volume_dirs = sprintf("/bin/rmdir '%s'", inline_template("<%= bricks.find_all{|x| x.split(':')[0] == '${fqdn}' }.collect {|y| y.split(':')[1].chomp('/')+'/${name}/' }.join('\' \'') %>"))
# get the list of bricks fqdn's that don't have our fqdn
$others = inline_template("<%= bricks.find_all{|x| x.split(':')[0] != '${fqdn}' }.collect {|y| y.split(':')[0] }.join(' ') %>")
@@ -96,11 +99,13 @@
$require = $ping ? {
false => [
Service['glusterd'],
+ File["${vardir}/volume/create-${name}.sh"],
File["${vardir}/xml.py"], # status check
Gluster::Brick[$bricks],
],
default => [
Service['glusterd'],
+ File["${vardir}/volume/create-${name}.sh"],
Package['fping'],
File["${vardir}/xml.py"], # status check
Gluster::Brick[$bricks],
@@ -109,6 +114,17 @@
# run if vip not defined (bypass mode) or if vip exists on this machine
if ($vip == '' or $vipif != '') {
+
+ # store command in a separate file to run as bash...
+ file { "${vardir}/volume/create-${name}.sh":
+ content => inline_template("#!/bin/bash\n/usr/sbin/gluster volume create ${name} ${valid_replica}${valid_stripe}transport ${valid_transport} ${brick_spec} > >(/usr/bin/tee '/tmp/gluster-volume-${name}.stdout') 2> >(/usr/bin/tee '/tmp/gluster-volume-${name}.stderr' >&2) || (${rmdir_volume_dirs} && /bin/false)\nexit \$?\n"),
+ owner => root,
+ group => root,
+ mode => 755,
+ ensure => present,
+ require => File["${vardir}/volume/"],
+ }
+
# NOTE: This should only happen on one host!
# NOTE: There's maybe a theoretical race condition if this runs
# at exactly the same time on more than one host. That's why it
@@ -119,8 +135,11 @@
# which per node will happen right before this runs.
# fping all the other nodes to ensure they're up for creation
# TODO: consider piping in a /usr/bin/yes to avoid warnings...
+ # NOTE: in this command, we save the std{out,err} and pass them
+ # on too for puppet to consume. we save in /tmp for fast access
# EXAMPLE: gluster volume create test replica 2 transport tcp annex1.example.com:/storage1a/test annex2.example.com:/storage2a/test annex3.example.com:/storage3b/test annex4.example.com:/storage4b/test annex1.example.com:/storage1c/test annex2.example.com:/storage2c/test annex3.example.com:/storage3d/test annex4.example.com:/storage4d/test
- exec { "/usr/sbin/gluster volume create ${name} ${valid_replica}${valid_stripe}transport ${valid_transport} ${brick_spec}":
+ exec { "gluster-volume-create-${name}":
+ command => "${vardir}/volume/create-${name}.sh",
logoutput => on_failure,
unless => "/usr/sbin/gluster volume list | /bin/grep -qxF '${name}' -", # add volume if it doesn't exist
onlyif => $onlyif,
View
@@ -0,0 +1,32 @@
+# Simple? gluster module by James
+# Copyright (C) 2010-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/>.
+
+class gluster::volume::base {
+
+ include gluster::vardir
+ #$vardir = $::gluster::vardir::module_vardir # with trailing slash
+ $vardir = regsubst($::gluster::vardir::module_vardir, '\/$', '')
+
+ file { "${vardir}/volume/":
+ ensure => directory, # make sure this is a directory
+ recurse => true, # don't recurse into directory
+ purge => true, # don't purge unmanaged files
+ force => true, # don't purge subdirs and links
+ require => File["${vardir}/"],
+ }
+}
+# vim: ts=8

0 comments on commit fa3fd2e

Please sign in to comment.