Skip to content

Instantly share code, notes, and snippets.

@ehelms
Last active August 29, 2015 14:17
Show Gist options
  • Save ehelms/52405ed3e75ec54ed91f to your computer and use it in GitHub Desktop.
Save ehelms/52405ed3e75ec54ed91f to your computer and use it in GitHub Desktop.
Sync Schedule Removal
task :list_active_sync_schedules => :environment do
User.current = User.first
products = Katello::Product.enabled.all
products.each do |product|
product.repositories.each do |repo|
schedules = Katello.pulp_server.resources.repository_schedule.list(repo.pulp_id, repo.importer_type)
if !schedules.empty?
puts schedules
puts "'#{repo.name}' in Product '#{product.name}' with product ID '#{product.id}' has #{schedules.length} sync plans attached to them"
end
end
end
end
task :cleanup_sync_schedules => :environment do
User.current = User.first
if ENV['product_id']
product = Katello::Product.find(ENV['product_id'])
puts "Removing sync schedules for product: #{product.name}"
product.repositories.each do |repo|
repo.set_sync_schedule(nil)
end
product.sync_plan = nil
product.save!
else
puts "Please specify a product ID to remove sync schedules for (e.g. rake cleanup_sync_schedules product_id=1)"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment