Created
September 8, 2013 23:29
-
-
Save dalen/6489506 to your computer and use it in GitHub Desktop.
function to gradually deploy using puppet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Puppet::Parser::Functions | |
newfunction(:gradual_deploy, :type => :rvalue, :arity => 4, :doc => "\ | |
Gradually deploy something | |
Arguments are from, to, start and finish. Will gradually move from returning <from> | |
to returning <to> over the duration between <start> and <finish>. | |
start and finish are specified as ruby datetime strings, supports all formats that ruby | |
can parse. | |
") do |args| | |
from, to, start, finish = *args | |
require 'date' | |
start = DateTime.parse(start) | |
finish = DateTime.parse(finish) | |
# Duration of deploy in seconds | |
duration = ((finish-start)*86400).to_i | |
Puppet::Parser::Functions.function('fqdnrand') | |
if start+(function_fqdnrand(duration).to_r/86400) > DateTime.now then | |
return to | |
else | |
return from | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment