summaryrefslogtreecommitdiff
path: root/puppet/modules/site_couchdb/lib
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2015-04-08 13:58:41 -0700
committerelijah <elijah@riseup.net>2015-04-08 13:58:41 -0700
commite3cfc2e1e7055ce2640fcce5bf810d6bd7930d2f (patch)
tree1ebbfdfa024941e04992eb2daecf22fda014f5dc /puppet/modules/site_couchdb/lib
parentdbe413c969a54be0a91fe1de1930eb20d885deb6 (diff)
move rotated db creation to site_couchdb and fix rotated db tests
Diffstat (limited to 'puppet/modules/site_couchdb/lib')
-rw-r--r--puppet/modules/site_couchdb/lib/puppet/parser/functions/rotated_db_name.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/puppet/modules/site_couchdb/lib/puppet/parser/functions/rotated_db_name.rb b/puppet/modules/site_couchdb/lib/puppet/parser/functions/rotated_db_name.rb
new file mode 100644
index 00000000..6458ae81
--- /dev/null
+++ b/puppet/modules/site_couchdb/lib/puppet/parser/functions/rotated_db_name.rb
@@ -0,0 +1,24 @@
+module Puppet::Parser::Functions
+ newfunction(:rotated_db_name, :type => :rvalue, :doc => <<-EOS
+This function takes a database name string and returns a database name with the current rotation stamp appended.
+The first argument is the base name of the database. Subsequent arguments may contain these options:
+ * 'next' -- return the db name for the next rotation, not the current one.
+ * 'monthly' -- rotate monthly (default)
+ * 'weekly' -- rotate weekly
+*Examples:*
+ rotated_db_name('tokens') => 'tokens_551'
+ EOS
+ ) do |arguments|
+ if arguments.include?('weekly')
+ rotation_period = 604800 # 1 week
+ else
+ rotation_period = 2592000 # 1 month
+ end
+ suffix = Time.now.utc.to_i / rotation_period
+ if arguments.include?('next')
+ suffix += 1
+ end
+ "#{arguments.first}_#{suffix}"
+ end
+end
+