From 97e15ea5a84bf414529e110a4215d9fe7f9f20e0 Mon Sep 17 00:00:00 2001 From: mh Date: Sat, 31 Oct 2009 15:16:37 +0100 Subject: move plugin directory to fit new 0.25 style --- lib/puppet/parser/functions/basename.rb | 16 ++++++++++ lib/puppet/parser/functions/dirname.rb | 16 ++++++++++ lib/puppet/parser/functions/gsub.rb | 17 +++++++++++ lib/puppet/parser/functions/hostname.rb | 13 +++++++++ lib/puppet/parser/functions/prefix_with.rb | 9 ++++++ lib/puppet/parser/functions/re_escape.rb | 7 +++++ lib/puppet/parser/functions/sha1.rb | 9 ++++++ lib/puppet/parser/functions/slash_escape.rb | 7 +++++ lib/puppet/parser/functions/split.rb | 17 +++++++++++ lib/puppet/parser/functions/strlength.rb | 6 ++++ lib/puppet/parser/functions/substitute.rb | 20 +++++++++++++ manifests/classes/lsb_release.pp | 39 ------------------------- plugins/puppet/parser/functions/basename.rb | 16 ---------- plugins/puppet/parser/functions/dirname.rb | 16 ---------- plugins/puppet/parser/functions/gsub.rb | 17 ----------- plugins/puppet/parser/functions/prefix_with.rb | 9 ------ plugins/puppet/parser/functions/re_escape.rb | 7 ----- plugins/puppet/parser/functions/sha1.rb | 9 ------ plugins/puppet/parser/functions/slash_escape.rb | 7 ----- plugins/puppet/parser/functions/split.rb | 17 ----------- plugins/puppet/parser/functions/strlength.rb | 6 ---- plugins/puppet/parser/functions/substitute.rb | 20 ------------- 22 files changed, 137 insertions(+), 163 deletions(-) create mode 100644 lib/puppet/parser/functions/basename.rb create mode 100644 lib/puppet/parser/functions/dirname.rb create mode 100644 lib/puppet/parser/functions/gsub.rb create mode 100644 lib/puppet/parser/functions/hostname.rb create mode 100644 lib/puppet/parser/functions/prefix_with.rb create mode 100644 lib/puppet/parser/functions/re_escape.rb create mode 100644 lib/puppet/parser/functions/sha1.rb create mode 100644 lib/puppet/parser/functions/slash_escape.rb create mode 100644 lib/puppet/parser/functions/split.rb create mode 100644 lib/puppet/parser/functions/strlength.rb create mode 100644 lib/puppet/parser/functions/substitute.rb delete mode 100644 manifests/classes/lsb_release.pp delete mode 100644 plugins/puppet/parser/functions/basename.rb delete mode 100644 plugins/puppet/parser/functions/dirname.rb delete mode 100644 plugins/puppet/parser/functions/gsub.rb delete mode 100644 plugins/puppet/parser/functions/prefix_with.rb delete mode 100644 plugins/puppet/parser/functions/re_escape.rb delete mode 100644 plugins/puppet/parser/functions/sha1.rb delete mode 100644 plugins/puppet/parser/functions/slash_escape.rb delete mode 100644 plugins/puppet/parser/functions/split.rb delete mode 100644 plugins/puppet/parser/functions/strlength.rb delete mode 100644 plugins/puppet/parser/functions/substitute.rb diff --git a/lib/puppet/parser/functions/basename.rb b/lib/puppet/parser/functions/basename.rb new file mode 100644 index 0000000..226d6e5 --- /dev/null +++ b/lib/puppet/parser/functions/basename.rb @@ -0,0 +1,16 @@ +# basename(string) : string +# basename(string[]) : string[] +# +# Returns the last component of the filename given as argument, which must be +# formed using forward slashes (``/..) regardless of the separator used on the +# local file system. +module Puppet::Parser::Functions + newfunction(:basename, :type => :rvalue) do |args| + if args[0].is_a?(Array) + args.collect do |a| File.basename(a) end + else + File.basename(args[0]) + end + end +end + diff --git a/lib/puppet/parser/functions/dirname.rb b/lib/puppet/parser/functions/dirname.rb new file mode 100644 index 0000000..44b4a00 --- /dev/null +++ b/lib/puppet/parser/functions/dirname.rb @@ -0,0 +1,16 @@ +# dirname(string) : string +# dirname(string[]) : string[] +# +# Returns all components of the filename given as argument except the last +# one. The filename must be formed using forward slashes (``/..) regardless of +# the separator used on the local file system. +module Puppet::Parser::Functions + newfunction(:dirname, :type => :rvalue) do |args| + if args[0].is_a?(Array) + args.collect do |a| File.dirname(a) end + else + File.dirname(args[0]) + end + end +end + diff --git a/lib/puppet/parser/functions/gsub.rb b/lib/puppet/parser/functions/gsub.rb new file mode 100644 index 0000000..e2410ff --- /dev/null +++ b/lib/puppet/parser/functions/gsub.rb @@ -0,0 +1,17 @@ +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| + val.gsub(/#{args[1]}/, args[2]) + end + else + args[0].gsub(/#{args[1]}/, args[2]) + end + end +end + 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 new file mode 100644 index 0000000..6e64a4a --- /dev/null +++ b/lib/puppet/parser/functions/prefix_with.rb @@ -0,0 +1,9 @@ +# prefix arguments 2..n with first argument + +module Puppet::Parser::Functions + newfunction(:prefix_with, :type => :rvalue) do |args| + prefix = args.shift + args.collect {|v| "%s%s" % [prefix, v] } + end +end + diff --git a/lib/puppet/parser/functions/re_escape.rb b/lib/puppet/parser/functions/re_escape.rb new file mode 100644 index 0000000..6e5904b --- /dev/null +++ b/lib/puppet/parser/functions/re_escape.rb @@ -0,0 +1,7 @@ +# apply regexp escaping to a string +module Puppet::Parser::Functions + newfunction(:re_escape, :type => :rvalue) do |args| + Regexp.escape(args[0]) + end +end + 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/split.rb b/lib/puppet/parser/functions/split.rb new file mode 100644 index 0000000..5237c92 --- /dev/null +++ b/lib/puppet/parser/functions/split.rb @@ -0,0 +1,17 @@ +# split($string, $delimiter) : $string +# split($string[], $delimiter) : $string[][] +# +# Split the first argument(s) on every $delimiter. $delimiter 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(:split, :type => :rvalue) do |args| + if args[0].is_a?(Array) + args.collect do |a| a.split(/#{args[1]}/) end + else + args[0].split(/#{args[1]}/) + end + 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 + diff --git a/manifests/classes/lsb_release.pp b/manifests/classes/lsb_release.pp deleted file mode 100644 index 73a9114..0000000 --- a/manifests/classes/lsb_release.pp +++ /dev/null @@ -1,39 +0,0 @@ -# common/manifests/classes/lsb_release.pp -- request the installation of -# lsb_release to get to lsbdistcodename, which is used throughout the manifests -# -# Copyright (C) 2007 David Schmitt -# See LICENSE for the full license granted to you. - -# Changelog: -# 2007-08-26: micah reported, that lsb_release can report -# nonsensical values for lsbdistcodename; assert_lsbdistcodename now -# recognises "n/a" and acts accordingly - -# This lightweight class only asserts that $lsbdistcodename is set. -# If the assertion fails, an error is printed on the server -# -# To fail individual resources on a missing lsbdistcodename, require -# Exec[assert_lsbdistcodename] on the specific resource -class assert_lsbdistcodename { - - case $lsbdistcodename { - '': { - err("Please install lsb_release or set facter_lsbdistcodename in the environment of $fqdn") - } - 'n/a': { - case $operatingsystem { - "Debian": { - err("lsb_release was unable to report your distcodename; This seems to indicate a broken apt/sources.list on $fqdn") - } - default: { - err("lsb_release was unable to report your distcodename; please set facter_lsbdistcodename in the environment of $fqdn") - } - } - exec { "false # assert_lsbdistcodename": alias => assert_lsbdistcodename } - } - } - -} - -# To fail the complete compilation, include this class -class require_lsbdistcodename inherits assert_lsbdistcodename {} diff --git a/plugins/puppet/parser/functions/basename.rb b/plugins/puppet/parser/functions/basename.rb deleted file mode 100644 index 226d6e5..0000000 --- a/plugins/puppet/parser/functions/basename.rb +++ /dev/null @@ -1,16 +0,0 @@ -# basename(string) : string -# basename(string[]) : string[] -# -# Returns the last component of the filename given as argument, which must be -# formed using forward slashes (``/..) regardless of the separator used on the -# local file system. -module Puppet::Parser::Functions - newfunction(:basename, :type => :rvalue) do |args| - if args[0].is_a?(Array) - args.collect do |a| File.basename(a) end - else - File.basename(args[0]) - end - end -end - diff --git a/plugins/puppet/parser/functions/dirname.rb b/plugins/puppet/parser/functions/dirname.rb deleted file mode 100644 index 44b4a00..0000000 --- a/plugins/puppet/parser/functions/dirname.rb +++ /dev/null @@ -1,16 +0,0 @@ -# dirname(string) : string -# dirname(string[]) : string[] -# -# Returns all components of the filename given as argument except the last -# one. The filename must be formed using forward slashes (``/..) regardless of -# the separator used on the local file system. -module Puppet::Parser::Functions - newfunction(:dirname, :type => :rvalue) do |args| - if args[0].is_a?(Array) - args.collect do |a| File.dirname(a) end - else - File.dirname(args[0]) - end - end -end - diff --git a/plugins/puppet/parser/functions/gsub.rb b/plugins/puppet/parser/functions/gsub.rb deleted file mode 100644 index e2410ff..0000000 --- a/plugins/puppet/parser/functions/gsub.rb +++ /dev/null @@ -1,17 +0,0 @@ -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| - val.gsub(/#{args[1]}/, args[2]) - end - else - args[0].gsub(/#{args[1]}/, args[2]) - end - end -end - diff --git a/plugins/puppet/parser/functions/prefix_with.rb b/plugins/puppet/parser/functions/prefix_with.rb deleted file mode 100644 index 6e64a4a..0000000 --- a/plugins/puppet/parser/functions/prefix_with.rb +++ /dev/null @@ -1,9 +0,0 @@ -# prefix arguments 2..n with first argument - -module Puppet::Parser::Functions - newfunction(:prefix_with, :type => :rvalue) do |args| - prefix = args.shift - args.collect {|v| "%s%s" % [prefix, v] } - end -end - diff --git a/plugins/puppet/parser/functions/re_escape.rb b/plugins/puppet/parser/functions/re_escape.rb deleted file mode 100644 index 6e5904b..0000000 --- a/plugins/puppet/parser/functions/re_escape.rb +++ /dev/null @@ -1,7 +0,0 @@ -# apply regexp escaping to a string -module Puppet::Parser::Functions - newfunction(:re_escape, :type => :rvalue) do |args| - Regexp.escape(args[0]) - end -end - diff --git a/plugins/puppet/parser/functions/sha1.rb b/plugins/puppet/parser/functions/sha1.rb deleted file mode 100644 index b5aa813..0000000 --- a/plugins/puppet/parser/functions/sha1.rb +++ /dev/null @@ -1,9 +0,0 @@ -# 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/plugins/puppet/parser/functions/slash_escape.rb b/plugins/puppet/parser/functions/slash_escape.rb deleted file mode 100644 index 04d3b95..0000000 --- a/plugins/puppet/parser/functions/slash_escape.rb +++ /dev/null @@ -1,7 +0,0 @@ -# escape slashes in a String -module Puppet::Parser::Functions - newfunction(:slash_escape, :type => :rvalue) do |args| - args[0].gsub(/\//, '\\/') - end -end - diff --git a/plugins/puppet/parser/functions/split.rb b/plugins/puppet/parser/functions/split.rb deleted file mode 100644 index 5237c92..0000000 --- a/plugins/puppet/parser/functions/split.rb +++ /dev/null @@ -1,17 +0,0 @@ -# split($string, $delimiter) : $string -# split($string[], $delimiter) : $string[][] -# -# Split the first argument(s) on every $delimiter. $delimiter 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(:split, :type => :rvalue) do |args| - if args[0].is_a?(Array) - args.collect do |a| a.split(/#{args[1]}/) end - else - args[0].split(/#{args[1]}/) - end - end -end diff --git a/plugins/puppet/parser/functions/strlength.rb b/plugins/puppet/parser/functions/strlength.rb deleted file mode 100644 index 147b24a..0000000 --- a/plugins/puppet/parser/functions/strlength.rb +++ /dev/null @@ -1,6 +0,0 @@ -module Puppet::Parser::Functions - newfunction(:strlength, :type => :rvalue) do |args| - args[0].to_s.length - end -end - diff --git a/plugins/puppet/parser/functions/substitute.rb b/plugins/puppet/parser/functions/substitute.rb deleted file mode 100644 index 4c97def..0000000 --- a/plugins/puppet/parser/functions/substitute.rb +++ /dev/null @@ -1,20 +0,0 @@ -# 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 - -- cgit v1.2.3