Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Add per brick defaults to gluster::simple for easier [physical] clust…
Browse files Browse the repository at this point in the history
…ers.

I've had most of this patch in my head for at least a week, and I
finally got the time to implement it! If you are building a symmetrical
cluster, that has consistent device naming across all of the hosts, then
this patch is the magic that should make your life _significantly_
easier. (*cough, cough*: Ben England...)

In the corner case that some of your device have different names, you
can still use this feature in conjunction with the other parameters to
first set global defaults, and then override as needed.

If you don't specify an overriding parameter (such as $count) then the
number of elements in this array will be used as the brick count!

Please note that this patch provides the $brick_params_defaults option
which is different from the $brick_param_defaults option which will
still work, and is useful in conjunction with this option as the way to
set brick defaults across the whole cluster.

For more questions you'll be happy to see that this patch comes with
documentation and example updates.
  • Loading branch information
purpleidea committed Mar 24, 2014
1 parent 7c423fa commit cc6db62
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 20 deletions.
23 changes: 23 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,29 @@ $brick_param_defaults = {
}
```
####`brick_params_defaults`
This parameter lets you specify a list of defaults to use when creating each
brick. Each element in the list represents a different brick. The value of each
element is a hash with the actual defaults that you'd like to use for creating
that brick. If you do not specify a brick count by any other method, then the
number of elements in this array will be used as the brick count. This is very
useful if you have consistent device naming across your entire cluster, because
you can very easily specify the devices and brick counts once for all hosts. If
for some reason a particular device requires unique values, then it can be set
manually with the _brick_params_ parameter. Please note the spelling of this
parameter. It is not the same as the _brick_param_defaults_ parameter which is
a global defaults parameter which will apply to all bricks.
The format of this parameter might look like:
```bash
$brick_params_defaults = [
{'dev' => '/dev/sdb'},
{'dev' => '/dev/sdc'},
{'dev' => '/dev/sdd'},
{'dev' => '/dev/sde'},
]
```
####`setgroup`
Set a volume property group. The two most common or well-known groups are the
_virt_ group, and the _small-file-perf_ group. This functionality is emulated
Expand Down
28 changes: 28 additions & 0 deletions examples/gluster-simple-physical-example-best.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# really simple gluster setup for physical provisioning.
# (yeah, that's it-- for iron!)
#

node /^annex\d+$/ { # annex{1,2,..N}

class { '::gluster::simple':
replica => 2,
vip = '192.168.1.42',
vrrp = true,
# NOTE: _each_ host will have four bricks with these devices...
brick_params_defaults = [ # note the spelling and type...
{'dev' => '/dev/sdb'},
{'dev' => '/dev/sdc'},
{'dev' => '/dev/sdd'},
{'dev' => '/dev/sde'},
],
brick_param_defaults => { # every brick will use these...
lvm => false,
xfs_inode64 => true,
force => true,
},
#brick_params => {}, # NOTE: you can also use this option to
# override a particular fqdn with the options that you need to!
}
}

56 changes: 36 additions & 20 deletions manifests/simple.pp
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,8 @@
$repo = true,
$count = 0, # 0 means build 1 brick, unless $brick_params exists...
$brick_params = {}, # this sets the brick count when $count is 0...
# usage notes: the $brick_params parameter might look like:
# {
# fqdn1 => [
# {dev => '/dev/disk/by-uuid/505e0286-8e21-49b4-a9b2-894777c69962'},
# {dev => '/dev/sde', partition => false},
# ],
# fqdn2 => [{dev => '/dev/disk/by-path/pci-0000:02:00.0-scsi-0:1:0:0', raid_su => 256, raid_sw => 10}],
# fqdnN => [...],
# }
$brick_param_defaults = {}, # these always get used to build bricks
# usage notes: the $brick_param_defaults might look like:
# {
# lvm => false,
# xfs_inode64 => true,
# force => true,
# }
$brick_params_defaults = [], # array of hashes to use as brick count
$setgroup = '', # pick a volume property group to set, eg: virt
$ping = true, # use fping or not?
$baseport = '', # specify base port option as used in glusterd.vol file
Expand Down Expand Up @@ -78,6 +64,7 @@
default => ["${volume}"],
}

# if this is a hash, then it's used as the defaults for all the bricks!
validate_hash($brick_param_defaults)
# in someone explicitly added this value, then don't overwrite it...
if has_key($brick_param_defaults, 'areyousure') {
Expand All @@ -87,6 +74,12 @@
$valid_brick_param_defaults = merge($brick_param_defaults, $areyousure)
}

# if this is an array, then each element is the default for each brick!
# if this is an array, then the number of elements is the brick count!!
validate_array($brick_params_defaults)
# TODO: check that each element of array is a valid hash!
$valid_brick_params_defaults = $brick_params_defaults

notify { 'gluster::simple':
message => 'You are using gluster::simple !',
}
Expand Down Expand Up @@ -129,24 +122,47 @@
if has_key($brick_params, "${::fqdn}") {
# here some wizardry happens...
$brick_params_list = $brick_params["${::fqdn}"]
$brick_params_list_length = inline_template('<%= @brick_params_list.length %>')
$brick_params_defaults_length = inline_template('<%= @valid_brick_params_defaults.length %>')

$valid_count = "${count}" ? {
'0' => inline_template('<%= @brick_params_list.length %>'),
'0' => "${brick_params_list_length}" ? {
'0' => "${brick_params_defaults_length}" ? {
'0' => 1, # if all are empty...
default => "${brick_params_defaults_length}",
},
default => "${brick_params_list_length}",
},
default => $count,
}
validate_array($brick_params_list)
$yaml = inline_template("<%= (0..@valid_count.to_i-1).inject(Hash.new) { |h,i| {'${::fqdn}:${valid_path}brick' + (i+1).to_s.rjust(7, '0') + '/' => ((i < @brick_params_list.length) ? @brick_params_list[i] : {})}.merge(h) }.to_yaml %>")

# NOTE: I've kept this template split as two comment chunks for
# readability. Puppet needs to fix this issue somehow. Creating
# a separate template removes the logic from the code, but as a
# large inline template, it's hard to read/write the logic!
#DEFAULTS = (((i < @valid_brick_params_defaults.length) and @valid_brick_params_defaults[i].is_a?(Hash)) ? @valid_brick_params_defaults[i] : {})
#$yaml = inline_template("<%= (0..@valid_count.to_i-1).inject(Hash.new) { |h,i| {'${::fqdn}:${valid_path}brick' + (i+1).to_s.rjust(7, '0') + '/' => DEFAULTS.merge((i < @brick_params_list.length) ? @brick_params_list[i] : {})}.merge(h) }.to_yaml %>")
$yaml = inline_template("<%= (0..@valid_count.to_i-1).inject(Hash.new) { |h,i| {'${::fqdn}:${valid_path}brick' + (i+1).to_s.rjust(7, '0') + '/' => (((i < @valid_brick_params_defaults.length) and @valid_brick_params_defaults[i].is_a?(Hash)) ? @valid_brick_params_defaults[i] : {}).merge((i < @brick_params_list.length) ? @brick_params_list[i] : {})}.merge(h) }.to_yaml %>")
} else {
# here we base our brick list on the $count variable alone...
# TODO: this second branch is really just a special case of the
# above branch and can probably be merged without much incident
$brick_params_defaults_length = inline_template('<%= @valid_brick_params_defaults.length %>')
# here we base our brick list on the $count variable or the
# brick_params_defaults length if it is available...
$valid_count = "${count}" ? {
'0' => 1, # 0 means undefined, so use the default
'0' => "${brick_params_defaults_length}" ? {
'0' => 1, # 0 means undefined, so use the default
default => "${brick_params_defaults_length}",
},
default => $count,
}
$brick_params_list = "${valid_count}" ? {
# TODO: should we use the same pattern for 1 or many ?
'1' => ["${::fqdn}:${valid_path}"],
default => split(inline_template("<%= (1..@valid_count.to_i).collect{|i| '${::fqdn}:${valid_path}brick' + i.to_s.rjust(7, '0') + '/' }.join(',') %>"), ','),
}
$yaml = inline_template("<%= (0..@valid_count.to_i-1).inject(Hash.new) { |h,i| {@brick_params_list[i] => {}}.merge(h) }.to_yaml %>")
$yaml = inline_template("<%= (0..@valid_count.to_i-1).inject(Hash.new) { |h,i| {@brick_params_list[i] => (((i < @valid_brick_params_defaults.length) and @valid_brick_params_defaults[i].is_a?(Hash)) ? @valid_brick_params_defaults[i] : {})}.merge(h) }.to_yaml %>")
}

$hash = parseyaml($yaml)
Expand Down
Binary file modified puppet-gluster-documentation.pdf
Binary file not shown.

0 comments on commit cc6db62

Please sign in to comment.