Last change
on this file since 30903 was 30903, checked in by davidb, 8 years ago |
Vagrant provisioning files for a 4-node Hadoop cluster. See README.txt for more details
|
File size:
777 bytes
|
Line | |
---|
1 | #
|
---|
2 | # clamp.rb
|
---|
3 | #
|
---|
4 |
|
---|
5 | module Puppet::Parser::Functions
|
---|
6 | newfunction(:clamp, :type => :rvalue, :arity => -2, :doc => <<-EOS
|
---|
7 | Clamps value to a range.
|
---|
8 | EOS
|
---|
9 | ) do |args|
|
---|
10 |
|
---|
11 | args.flatten!
|
---|
12 |
|
---|
13 | raise(Puppet::ParseError, 'clamp(): Wrong number of arguments, ' +
|
---|
14 | 'need three to clamp') if args.size != 3
|
---|
15 |
|
---|
16 | # check values out
|
---|
17 | args.each do |value|
|
---|
18 | case [value.class]
|
---|
19 | when [String]
|
---|
20 | raise(Puppet::ParseError, "clamp(): Required explicit numeric (#{value}:String)") unless value =~ /^\d+$/
|
---|
21 | when [Hash]
|
---|
22 | raise(Puppet::ParseError, "clamp(): The Hash type is not allowed (#{value})")
|
---|
23 | end
|
---|
24 | end
|
---|
25 |
|
---|
26 | # convert to numeric each element
|
---|
27 | # then sort them and get a middle value
|
---|
28 | args.map{ |n| n.to_i }.sort[1]
|
---|
29 | end
|
---|
30 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.