Last change
on this file since 30903 was 30903, checked in by davidb, 8 years ago |
Vagrant provisioning files for a 4-node Hadoop cluster. See README.txt for more details
|
File size:
1.1 KB
|
Rev | Line | |
---|
[30903] | 1 | #
|
---|
| 2 | # time.rb
|
---|
| 3 | #
|
---|
| 4 |
|
---|
| 5 | module Puppet::Parser::Functions
|
---|
| 6 | newfunction(:time, :type => :rvalue, :doc => <<-EOS
|
---|
| 7 | This function will return the current time since epoch as an integer.
|
---|
| 8 |
|
---|
| 9 | *Examples:*
|
---|
| 10 |
|
---|
| 11 | time()
|
---|
| 12 |
|
---|
| 13 | Will return something like: 1311972653
|
---|
| 14 | EOS
|
---|
| 15 | ) do |arguments|
|
---|
| 16 |
|
---|
| 17 | # The Time Zone argument is optional ...
|
---|
| 18 | time_zone = arguments[0] if arguments[0]
|
---|
| 19 |
|
---|
| 20 | if (arguments.size != 0) and (arguments.size != 1) then
|
---|
| 21 | raise(Puppet::ParseError, "time(): Wrong number of arguments "+
|
---|
| 22 | "given #{arguments.size} for 0 or 1")
|
---|
| 23 | end
|
---|
| 24 |
|
---|
| 25 | time = Time.new
|
---|
| 26 |
|
---|
| 27 | # There is probably a better way to handle Time Zone ...
|
---|
| 28 | if time_zone and not time_zone.empty?
|
---|
| 29 | original_zone = ENV['TZ']
|
---|
| 30 |
|
---|
| 31 | local_time = time.clone
|
---|
| 32 | local_time = local_time.utc
|
---|
| 33 |
|
---|
| 34 | ENV['TZ'] = time_zone
|
---|
| 35 |
|
---|
| 36 | result = local_time.localtime.strftime('%s')
|
---|
| 37 |
|
---|
| 38 | ENV['TZ'] = original_zone
|
---|
| 39 | else
|
---|
| 40 | result = time.localtime.strftime('%s')
|
---|
| 41 | end
|
---|
| 42 |
|
---|
| 43 | # Calling Time#to_i on a receiver changes it. Trust me I am the Doctor.
|
---|
| 44 | result = result.to_i
|
---|
| 45 |
|
---|
| 46 | return result
|
---|
| 47 | end
|
---|
| 48 | end
|
---|
| 49 |
|
---|
| 50 | # vim: set ts=2 sw=2 et :
|
---|
Note:
See
TracBrowser
for help on using the repository browser.