diff options
author | Micah Anderson <micah@riseup.net> | 2010-09-02 19:04:29 -0400 |
---|---|---|
committer | Micah Anderson <micah@riseup.net> | 2010-09-02 19:04:29 -0400 |
commit | 63a16ad8c07e880e68cb7c0a895f7e26ca1434f8 (patch) | |
tree | 1ca7da340aef82e8fe87f44c680cedc93795ecbf /lib | |
parent | 76b0a31a76b8ab7509da3389379daa24b0610f73 (diff) | |
parent | 51e06fd0d2fa1c8999f328051e5e717bc18e77e7 (diff) | |
download | puppet-common-63a16ad8c07e880e68cb7c0a895f7e26ca1434f8.tar.gz puppet-common-63a16ad8c07e880e68cb7c0a895f7e26ca1434f8.tar.bz2 |
Merge remote branch 'immerda/master'
Conflicts:
lib/puppet/parser/functions/gsub.rb
lib/puppet/parser/functions/prefix_with.rb
lib/puppet/parser/functions/sha1.rb
lib/puppet/parser/functions/slash_escape.rb
lib/puppet/parser/functions/substitute.rb
manifests/classes/lsb_release.pp
manifests/defines/concatenated_file.pp
manifests/defines/config_file.pp
manifests/defines/line.pp
manifests/defines/module_dir.pp
manifests/defines/module_file.pp
manifests/defines/replace.pp
manifests/init.pp
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/parser/functions/gsub.rb | 14 | ||||
-rw-r--r-- | lib/puppet/parser/functions/hostname.rb | 13 | ||||
-rw-r--r-- | lib/puppet/parser/functions/prefix_with.rb | 14 | ||||
-rw-r--r-- | lib/puppet/parser/functions/sha1.rb | 9 | ||||
-rw-r--r-- | lib/puppet/parser/functions/slash_escape.rb | 7 | ||||
-rw-r--r-- | lib/puppet/parser/functions/strlength.rb | 6 | ||||
-rw-r--r-- | lib/puppet/parser/functions/substitute.rb | 20 |
7 files changed, 62 insertions, 21 deletions
diff --git a/lib/puppet/parser/functions/gsub.rb b/lib/puppet/parser/functions/gsub.rb index 27e6192..e2410ff 100644 --- a/lib/puppet/parser/functions/gsub.rb +++ b/lib/puppet/parser/functions/gsub.rb @@ -1,13 +1,9 @@ -# -# A thin wrapper around the ruby gsub function. -# -# gsub($string, $pattern, $replacement) -# -# will replace all occurrences of $pattern in $string with $replacement. -# $string can be either a single value or an array. In the latter case, each -# element of the array will be processed in turn. -# module Puppet::Parser::Functions + # thin wrapper around the ruby gsub function + # gsub($string, $pattern, $replacement) will replace all occurrences of + # $pattern in $string with $replacement. $string can be either a singel + # value or an array. In the latter case, each element of the array will + # be processed in turn. newfunction(:gsub, :type => :rvalue) do |args| if args[0].is_a?(Array) args[0].collect do |val| diff --git a/lib/puppet/parser/functions/hostname.rb b/lib/puppet/parser/functions/hostname.rb new file mode 100644 index 0000000..7bc477f --- /dev/null +++ b/lib/puppet/parser/functions/hostname.rb @@ -0,0 +1,13 @@ +# get an uniq array of ipaddresses for a hostname +require 'resolv' + +module Puppet::Parser::Functions + newfunction(:hostname, :type => :rvalue) do |args| + res = Array.new + Resolv::DNS.new.each_address(args[0]){ |addr| + res << addr + } + res.uniq + end +end + diff --git a/lib/puppet/parser/functions/prefix_with.rb b/lib/puppet/parser/functions/prefix_with.rb index 5a12986..6e64a4a 100644 --- a/lib/puppet/parser/functions/prefix_with.rb +++ b/lib/puppet/parser/functions/prefix_with.rb @@ -1,15 +1,5 @@ -# Prefixes arguments 2..n with first argument. -# -# prefix_with(string prefix, string[] arguments) : string[] -# -# Example: -# -# prefix_with("php-", [ "blah", "foo" ]) -# -# will result in this array: -# -# [ "php-blah", "php-foo" ] -# +# prefix arguments 2..n with first argument + module Puppet::Parser::Functions newfunction(:prefix_with, :type => :rvalue) do |args| prefix = args.shift diff --git a/lib/puppet/parser/functions/sha1.rb b/lib/puppet/parser/functions/sha1.rb new file mode 100644 index 0000000..b5aa813 --- /dev/null +++ b/lib/puppet/parser/functions/sha1.rb @@ -0,0 +1,9 @@ +# return the sha1 hash +require 'digest/sha1' + +module Puppet::Parser::Functions + newfunction(:sha1, :type => :rvalue) do |args| + Digest::SHA1.hexdigest(args[0]) + end +end + diff --git a/lib/puppet/parser/functions/slash_escape.rb b/lib/puppet/parser/functions/slash_escape.rb new file mode 100644 index 0000000..04d3b95 --- /dev/null +++ b/lib/puppet/parser/functions/slash_escape.rb @@ -0,0 +1,7 @@ +# escape slashes in a String +module Puppet::Parser::Functions + newfunction(:slash_escape, :type => :rvalue) do |args| + args[0].gsub(/\//, '\\/') + end +end + diff --git a/lib/puppet/parser/functions/strlength.rb b/lib/puppet/parser/functions/strlength.rb new file mode 100644 index 0000000..147b24a --- /dev/null +++ b/lib/puppet/parser/functions/strlength.rb @@ -0,0 +1,6 @@ +module Puppet::Parser::Functions + newfunction(:strlength, :type => :rvalue) do |args| + args[0].to_s.length + end +end + diff --git a/lib/puppet/parser/functions/substitute.rb b/lib/puppet/parser/functions/substitute.rb new file mode 100644 index 0000000..4c97def --- /dev/null +++ b/lib/puppet/parser/functions/substitute.rb @@ -0,0 +1,20 @@ +# subsititute($string, $regex, $replacement) : $string +# subsititute($string[], $regex, $replacement) : $string[] +# +# Replace all ocurrences of $regex in $string by $replacement. +# $regex is interpreted as Ruby regular expression. +# +# For long-term portability it is recommended to refrain from using Ruby's +# extended RE features. +module Puppet::Parser::Functions + newfunction(:substitute, :type => :rvalue) do |args| + if args[0].is_a?(Array) + args[0].collect do |val| + val.gsub(/#{args[1]}/, args[2]) + end + else + args[0].gsub(/#{args[1]}/, args[2]) + end + end +end + |