Last change
on this file since 30960 was 30960, checked in by davidb, 8 years ago |
Switch to using Puppet to provision machine. Strongly based on files developed for spark-hdfs cluster
|
File size:
1.1 KB
|
Line | |
---|
1 | #
|
---|
2 | # size.rb
|
---|
3 | #
|
---|
4 |
|
---|
5 | module Puppet::Parser::Functions
|
---|
6 | newfunction(:size, :type => :rvalue, :doc => <<-EOS
|
---|
7 | Returns the number of elements in a string, an array or a hash
|
---|
8 | EOS
|
---|
9 | ) do |arguments|
|
---|
10 |
|
---|
11 | raise(Puppet::ParseError, "size(): Wrong number of arguments " +
|
---|
12 | "given (#{arguments.size} for 1)") if arguments.size < 1
|
---|
13 |
|
---|
14 | item = arguments[0]
|
---|
15 |
|
---|
16 | if item.is_a?(String)
|
---|
17 |
|
---|
18 | begin
|
---|
19 | #
|
---|
20 | # Check whether your item is a numeric value or not ...
|
---|
21 | # This will take care about positive and/or negative numbers
|
---|
22 | # for both integer and floating-point values ...
|
---|
23 | #
|
---|
24 | # Please note that Puppet has no notion of hexadecimal
|
---|
25 | # nor octal numbers for its DSL at this point in time ...
|
---|
26 | #
|
---|
27 | Float(item)
|
---|
28 |
|
---|
29 | raise(Puppet::ParseError, 'size(): Requires either ' +
|
---|
30 | 'string, array or hash to work with')
|
---|
31 |
|
---|
32 | rescue ArgumentError
|
---|
33 | result = item.size
|
---|
34 | end
|
---|
35 |
|
---|
36 | elsif item.is_a?(Array) || item.is_a?(Hash)
|
---|
37 | result = item.size
|
---|
38 | else
|
---|
39 | raise(Puppet::ParseError, 'size(): Unknown type given')
|
---|
40 | end
|
---|
41 |
|
---|
42 | return result
|
---|
43 | end
|
---|
44 | end
|
---|
45 |
|
---|
46 | # vim: set ts=2 sw=2 et :
|
---|
Note:
See
TracBrowser
for help on using the repository browser.