summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Shubin <james@shubin.ca>2014-10-21 15:37:10 -0400
committerJames Shubin <james@shubin.ca>2014-10-21 15:37:10 -0400
commit6dfaa8446e4287cf6f7f540158cde700fb95b830 (patch)
tree7579970ae7b41760eeb81b684027c1f6d12a14a7
parent06af205a562d543bbeb7c4d5c55143ade3bdb4e6 (diff)
downloadpuppet-gluster-6dfaa8446e4287cf6f7f540158cde700fb95b830.tar.gz
puppet-gluster-6dfaa8446e4287cf6f7f540158cde700fb95b830.tar.xz
puppet-gluster-6dfaa8446e4287cf6f7f540158cde700fb95b830.zip
Update brick_layout_chained to work around regression.
See the previous commit for more informatio on the regression.
-rw-r--r--lib/puppet/parser/functions/brick_layout_chained.rb42
-rw-r--r--lib/puppet/parser/functions/get_brickstacks.rb64
-rw-r--r--lib/puppet/parser/functions/get_hostlist.rb48
3 files changed, 116 insertions, 38 deletions
diff --git a/lib/puppet/parser/functions/brick_layout_chained.rb b/lib/puppet/parser/functions/brick_layout_chained.rb
index ce27230..938a151 100644
--- a/lib/puppet/parser/functions/brick_layout_chained.rb
+++ b/lib/puppet/parser/functions/brick_layout_chained.rb
@@ -30,6 +30,8 @@ module Puppet::Parser::Functions
Puppet::Parser::Functions.function('warning') # load function
Puppet::Parser::Functions.function('brick_str_to_hash') # load function
+ Puppet::Parser::Functions.function('get_hostlist') # load function
+ Puppet::Parser::Functions.function('get_brickstacks') # load function
# signature: replica, bricks -> bricks
unless args.length == 2
raise Puppet::ParseError, "brick_layout_chained(): wrong number of arguments (#{args.length}; must be 2)"
@@ -45,49 +47,13 @@ module Puppet::Parser::Functions
replica = args[0].to_i # convert from string if needed
bricks = args[1]
- def get_hostlist(bricks)
- hosts = []
- bricks.each do |x|
- key = x['host']
- val = x['path']
-
- if not hosts.include?(key)
- hosts.push(key)
- end
- end
- return hosts
- end
-
- def get_brickstacks(bricks, sort=false)
- stacks = {}
- hosts = get_hostlist(bricks)
- bricks.each do |x|
- key = x['host']
- val = x['path']
- if not stacks.include?(key); stacks[key] = []; end # initialize
- stacks[key].push(val)
- end
-
- # optionally sort the paths in each individual host stack...
- if sort
- sorted_stacks = {}
- stacks.each do |k, v|
- # TODO: there should probably be a proper 'sorted' function for
- # paths, in case they aren't numbered sanely _WITH_ padding.
- sorted_stacks[k] = v.sort
- end
- return sorted_stacks
- end
- return stacks
- end
-
final = []
pointer = 0
parsed = function_brick_str_to_hash([bricks])
# TODO: there should probably be a proper 'sorted' function for
# hostnames, in case they aren't numbered sanely _WITH_ padding.
- hosts = get_hostlist(parsed).sort
- brickstack = get_brickstacks(parsed, sort=true)
+ hosts = function_get_hostlist([parsed]).sort
+ brickstack = function_get_brickstacks([parsed, true])
if bricks.length == 0; return []; end
diff --git a/lib/puppet/parser/functions/get_brickstacks.rb b/lib/puppet/parser/functions/get_brickstacks.rb
new file mode 100644
index 0000000..2cef52e
--- /dev/null
+++ b/lib/puppet/parser/functions/get_brickstacks.rb
@@ -0,0 +1,64 @@
+# GlusterFS 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/>.
+
+module Puppet::Parser::Functions
+ newfunction(:get_brickstacks, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
+ Helper function for the brick layout algorithms.
+
+ ENDHEREDOC
+
+ Puppet::Parser::Functions.function('get_hostlist') # load function
+
+ # signature: replica, bricks -> bricks
+ unless args.length == 2
+ raise Puppet::ParseError, "get_brickstacks(): wrong number of arguments (#{args.length}; must be 2)"
+ end
+ unless args[0].is_a?(Array)
+ raise Puppet::ParseError, "get_brickstacks(): expects the first argument to be an array, got #{args[0].inspect} which is of type #{args[0].class}"
+ end
+ unless args[1].is_a?(TrueClass) or args[1].is_a?(FalseClass)
+ raise Puppet::ParseError, "get_brickstacks(): expects the second argument to be a boolean, got #{args[1].inspect} which is of type #{args[1].class}"
+ end
+
+ bricks = args[0]
+ sort = args[1]
+
+ stacks = {}
+ hosts = function_get_hostlist([bricks])
+ bricks.each do |x|
+ key = x['host']
+ val = x['path']
+ if not stacks.include?(key); stacks[key] = []; end # initialize
+ stacks[key].push(val)
+ end
+
+ # optionally sort the paths in each individual host stack...
+ if sort
+ sorted_stacks = {}
+ stacks.each do |k, v|
+ # TODO: there should probably be a proper 'sorted' function for
+ # paths, in case they aren't numbered sanely _WITH_ padding.
+ sorted_stacks[k] = v.sort
+ end
+ stacks = sorted_stacks
+ end
+
+ stacks # return
+ end
+end
+
+# vim: ts=8
diff --git a/lib/puppet/parser/functions/get_hostlist.rb b/lib/puppet/parser/functions/get_hostlist.rb
new file mode 100644
index 0000000..2905aa9
--- /dev/null
+++ b/lib/puppet/parser/functions/get_hostlist.rb
@@ -0,0 +1,48 @@
+# GlusterFS 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/>.
+
+module Puppet::Parser::Functions
+ newfunction(:get_hostlist, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
+ Helper function for the brick layout algorithms.
+
+ ENDHEREDOC
+
+ # signature: replica, bricks -> bricks
+ unless args.length == 1
+ raise Puppet::ParseError, "get_hostlist(): wrong number of arguments (#{args.length}; must be 1)"
+ end
+ unless args[0].is_a?(Array)
+ raise Puppet::ParseError, "get_hostlist(): expects the first argument to be an array, got #{args[0].inspect} which is of type #{args[0].class}"
+ end
+
+ bricks = args[0]
+
+ hosts = []
+ bricks.each do |x|
+ key = x['host']
+ val = x['path']
+
+ if not hosts.include?(key)
+ hosts.push(key)
+ end
+ end
+
+ hosts # return
+ end
+end
+
+# vim: ts=8