mirror of
https://github.com/zulip/docker-zulip.git
synced 2025-11-06 23:13:14 +00:00
Added modified zulip puppet modules
This commit is contained in:
16
includes/common/lib/puppet/parser/functions/basename.rb
Normal file
16
includes/common/lib/puppet/parser/functions/basename.rb
Normal file
@@ -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
|
||||
|
||||
16
includes/common/lib/puppet/parser/functions/dirname.rb
Normal file
16
includes/common/lib/puppet/parser/functions/dirname.rb
Normal file
@@ -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
|
||||
|
||||
17
includes/common/lib/puppet/parser/functions/gsub.rb
Normal file
17
includes/common/lib/puppet/parser/functions/gsub.rb
Normal file
@@ -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
|
||||
|
||||
13
includes/common/lib/puppet/parser/functions/hostname.rb
Normal file
13
includes/common/lib/puppet/parser/functions/hostname.rb
Normal file
@@ -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
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:network_lookup, :type => :rvalue) do |args|
|
||||
case args[0]
|
||||
when "ip" then
|
||||
IPSocket::getaddress(lookupvar('fqdn'))
|
||||
when "netmask" then
|
||||
"255.255.255.0"
|
||||
when "gateway" then
|
||||
IPSocket::getaddress(lookupvar('fqdn')).gsub(/\.\d+$/, '.1')
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -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
|
||||
|
||||
7
includes/common/lib/puppet/parser/functions/re_escape.rb
Normal file
7
includes/common/lib/puppet/parser/functions/re_escape.rb
Normal file
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
17
includes/common/lib/puppet/parser/functions/split.rb
Normal file
17
includes/common/lib/puppet/parser/functions/split.rb
Normal file
@@ -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
|
||||
20
includes/common/lib/puppet/parser/functions/substitute.rb
Normal file
20
includes/common/lib/puppet/parser/functions/substitute.rb
Normal file
@@ -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
|
||||
|
||||
19
includes/common/lib/puppet/parser/functions/url_get.rb
Normal file
19
includes/common/lib/puppet/parser/functions/url_get.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
# Returns the content at given URL
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:url_get, :type => :rvalue) do |args|
|
||||
require 'open-uri'
|
||||
|
||||
url = args[0]
|
||||
|
||||
begin
|
||||
data = open(url, :proxy => nil)
|
||||
# Ignore header
|
||||
data.readline
|
||||
data.readline.chomp
|
||||
rescue OpenURI::HTTPError => error
|
||||
fail "Fetching URL #{url} failed with status #{error.message}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user