Fix typing for erandom function
Change-Id: I5a24ce487ac2b40e5ef1c2d3bae32637b890d207
This commit is contained in:
parent
0d24222b7f
commit
58fb27f4ee
|
@ -1,15 +1,15 @@
|
||||||
# Customm function to generate a random hex string of length arg[0].
|
# Custom function to generate a random hex string of length arg[0].
|
||||||
#
|
#
|
||||||
# This is used to ensure we get unique tenant and user IDs that
|
# This is used to ensure we get unique tenant and user IDs that
|
||||||
# are required for the glance image-cache for cinder
|
# are required for the glance image-cache for cinder
|
||||||
|
|
||||||
module Puppet::Parser::Functions
|
module Puppet::Parser::Functions
|
||||||
newfunction(:get_random_id, :type => :rvalue, :doc => "returns a random 32 character hex string") do |args|
|
newfunction(:get_random_id, :type => :rvalue, :doc => "returns a random hex string of length args[0]") do |args|
|
||||||
raise(Puppet::ParseError, "get_random_id(): Wrong number of arguments " +
|
raise(Puppet::ParseError, "get_random_id(): Wrong number of arguments " +
|
||||||
"given (#{args.size} for 1)") if args.size != 1
|
"given (#{args.size} for 1)") if args.size != 1
|
||||||
numbers = (0..9).to_a
|
numbers = (0..9).to_a
|
||||||
alpha = ('a'..'z').to_a
|
alpha = ('a'..'z').to_a
|
||||||
length = args[0]
|
length = args[0].to_i
|
||||||
CHARS = (alpha + numbers)
|
CHARS = (alpha + numbers)
|
||||||
id = CHARS.sort_by { rand }.join[0...length]
|
id = CHARS.sort_by { rand }.join[0...length]
|
||||||
return id
|
return id
|
||||||
|
|
Loading…
Reference in New Issue