Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add export/import of schedules to rake task #19192

Merged
merged 1 commit into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/task_helpers/exports/schedules.rb
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions lib/task_helpers/imports/schedules.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions lib/tasks/evm_export_import.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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