Permalink
Browse files

Make it easier to use simple filesystem paths for bricks.

The added example should make this obvious. Heed the warning in using
this feature. I find it most useful for rapid prototyping using vm's.
  • Loading branch information...
1 parent 4345cf9 commit 231e4b9ff771d33514d78518e14fe13148e7b431 @purpleidea committed Sep 7, 2013
Showing with 94 additions and 17 deletions.
  1. +51 −0 examples/filesystem-backed-bricks-example.pp
  2. +43 −17 manifests/brick.pp
@@ -0,0 +1,51 @@
+#
+# example of a simple replicate with 2 hosts, and filesystem path bricks
+# NOTE: this should be put on *every* gluster host
+#
+
+class gluster_base {
+
+ class { '::gluster::server':
+ hosts => ['annex1.example.com', 'annex2.example.com'],
+ ips => ['192.168.123.101', '192.168.123.102'],
+ shorewall => true,
+ }
+
+ gluster::host { 'annex1.example.com':
+ # use uuidgen to make these
+ uuid => '1f660ca2-2c78-4aa0-8f4d-21608218c69c',
+ }
+
+ # note that this is using a folder on your existing filesystem...
+ # this can be useful for prototyping gluster using virtual machines
+ # if this isn't a separate partition, remember that your root fs will
+ # run out of space when your gluster volume does!
+ gluster::brick { 'annex1.example.com:/data/gluster-storage1':
+ areyousure => true,
+ }
+
+ gluster::host { 'annex2.example.com':
+ uuid => '2fbe6e2f-f6bc-4c2d-a301-62fa90c459f8',
+ }
+
+ gluster::brick { 'annex2.example.com:/data/gluster-storage2':
+ areyousure => true,
+ }
+
+ $brick_list = [
+ 'annex1.example.com:/data/gluster-storage1',
+ 'annex2.example.com:/data/gluster-storage2',
+ ]
+
+ gluster::volume { 'examplevol':
+ replica => 2,
+ bricks => $brick_list,
+ start => undef, # i'll start this myself
+ }
+
+ # namevar must be: <VOLNAME>#<KEY>
+ gluster::volume::property { 'examplevol#auth.reject':
+ value => ['192.0.2.13', '198.51.100.42', '203.0.113.69'],
+ }
+}
+
View
@@ -16,8 +16,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
define gluster::brick(
- $dev, # /dev/sdc, /dev/disk/by-id/scsi-36003048007e14f0014ca2743150a5471
- $fsuuid, # set a uuid for this fs (uuidgen)
+ # if dev is false, path in $name is used directly after a mkdir -p
+ $dev = false, # /dev/sdc, /dev/disk/by-id/scsi-36003048007e14f0014ca2743150a5471
+ $fsuuid = '', # set a uuid for this fs (uuidgen)
$labeltype = '', # gpt
$fstype = '', # xfs
$xfs_inode64 = false,
@@ -29,14 +30,14 @@
# eg: annex1.example.com:/storage1a
$split = split($name, ':') # do some $name parsing
$host = $split[0] # host fqdn
- # NOTE: technically $mount should be everything BUT split[0]. This
- # lets our $mount include colons if for some reason they're needed.
- #$mount = $split[1] # brick mount
+ # NOTE: technically $path should be everything BUT split[0]. This
+ # lets our $path include colons if for some reason they're needed.
+ #$path = $split[1] # brick mount or storage path
# TODO: create substring function
- $mount = inline_template("<%= '${name}'.slice('${host}'.length+1, '${name}'.length-'${host}'.length-1) %>")
+ $path = inline_template("<%= '${name}'.slice('${host}'.length+1, '${name}'.length-'${host}'.length-1) %>")
- if ! ( "${host}:${mount}" == "${name}" ) {
- fail('The brick $name must match a $host-$mount pattern.')
+ if ! ( "${host}:${path}" == "${name}" ) {
+ fail('The brick $name must match a $host-$path pattern.')
}
Gluster::Host[$host] -> Gluster::Brick[$name] # brick requires host
@@ -51,19 +52,31 @@
default => 'gpt',
}
- $valid_fstype = $fstype ? {
- 'ext4' => 'ext4', # TODO
- default => 'xfs',
+ # if $dev is false, we assume we're using a path backing store on brick
+ $valid_fstype = type($dev) ? {
+ 'boolean' => $dev ? {
+ false => 'path', # no dev, just a path spec
+ default => '', # invalid type
+ },
+ default => $fstype ? {
+ 'ext4' => 'ext4', # TODO
+ default => 'xfs',
+ },
}
$force_flag = $force ? {
true => 'f',
default => '',
}
+ if ( $valid_fstype == 'path' ) {
+
+ # do a mkdir -p in the execution section below...
+ $options_list = [] # n/a
+
# XFS mount options:
# http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/filesystems/xfs.txt;hb=HEAD
- if ( $valid_fstype == 'xfs' ) {
+ } elsif ( $valid_fstype == 'xfs' ) {
# exec requires
include gluster::brick::xfs
$exec_requires = [Package['xfsprogs']]
@@ -111,6 +124,8 @@
# mount options
$options_list = [] # TODO
+ } else {
+ fail('The $fstype is invalid.')
}
# put all the options in an array, remove the empty ones, and join with
@@ -123,8 +138,8 @@
default => true,
}
- # if we're on itself
- if ( "${fqdn}" == "${host}" ) {
+ # if we're on itself, and we have a real device to work with
+ if (type($dev) != 'boolean') and ("${fqdn}" == "${host}") {
# first get the device ready
@@ -152,15 +167,15 @@
}
# make an empty directory for the mount point
- file { "${mount}":
+ file { "${path}":
ensure => directory, # make sure this is a directory
recurse => false, # don't recurse into directory
purge => false, # don't purge unmanaged files
force => false, # don't purge subdirs and links
require => Exec["gluster-brick-make-${name}"],
}
- mount { "${mount}":
+ mount { "${path}":
atboot => true,
ensure => mounted,
device => "UUID=${fsuuid}",
@@ -174,9 +189,20 @@
# xfs uses xfs_check and friends only when suspect.
pass => '2', # fs_passno: 0 to skip fsck on boot
require => [
- File["${mount}"],
+ File["${path}"],
],
}
+
+ } elsif ((type($dev) == 'boolean') and (! $dev)) and ("${fqdn}" == "${host}") {
+
+ $valid_path = sprintf("%s/", regsubst($path, '\/$', ''))
+ # ensure the full path exists!
+ exec { "/bin/mkdir -p '${valid_path}'":
+ creates => "${valid_path}",
+ logoutput => on_failure,
+ noop => $exec_noop,
+ alias => "gluster-brick-mkdir ${name}",
+ }
}
}

0 comments on commit 231e4b9

Please sign in to comment.