diff --git a/lib/task_helpers/exports/schedules.rb b/lib/task_helpers/exports/schedules.rb new file mode 100644 index 00000000000..d0405d7fed3 --- /dev/null +++ b/lib/task_helpers/exports/schedules.rb @@ -0,0 +1,16 @@ +module TaskHelpers + class Exports + class Schedules + def export(options = {}) + export_dir = options[:directory] + + schedules = options[:all] ? MiqSchedule.all : MiqSchedule.where(:userid => 'system', :prod_default => 'system') + + schedules.each do |schedule| + filename = Exports.safe_filename(schedule.name, options[:keep_spaces]) + File.write("#{export_dir}/#{filename}.yaml", MiqSchedule.export_to_yaml([schedule], MiqSchedule)) + end + end + end + end +end diff --git a/lib/task_helpers/imports/schedules.rb b/lib/task_helpers/imports/schedules.rb new file mode 100644 index 00000000000..eb1c08c414a --- /dev/null +++ b/lib/task_helpers/imports/schedules.rb @@ -0,0 +1,20 @@ +module TaskHelpers + class Imports + class Schedules + def import(options = {}) + return unless options[:source] + + glob = File.file?(options[:source]) ? options[:source] : "#{options[:source]}/*.yaml" + Dir.glob(glob) do |filename| + $log.info("Importing Schedules from: #{filename}") + + begin + MiqSchedule.import(File.open(filename, 'r')) + rescue StandardError => err + warn("Error importing #{filename} : #{err.message}") + end + end + end + end + end +end diff --git a/lib/tasks/evm_export_import.rake b/lib/tasks/evm_export_import.rake index e1a1d62555c..ffda7cfa252 100644 --- a/lib/tasks/evm_export_import.rake +++ b/lib/tasks/evm_export_import.rake @@ -123,6 +123,14 @@ namespace :evm do exit # exit so that parameters to the first rake task are not run as rake tasks end + + desc 'Exports all schedules to individual YAML files' + task :schedules => :environment do + options = TaskHelpers::Exports.parse_options + TaskHelpers::Exports::Schedules.new.export(options) + + exit # exit so that parameters to the first rake task are not run as rake tasks + end end namespace :import do @@ -235,5 +243,13 @@ namespace :evm do exit # exit so that parameters to the first rake task are not run as rake tasks end + + desc 'Import all schedule definitions from individual YAML files' + task :schedules => :environment do + options = TaskHelpers::Imports.parse_options + TaskHelpers::Imports::Schedules.new.import(options) + + exit # exit so that parameters to the first rake task are not run as rake tasks + end end end