Sha256: 625220bb2d86f946ea41244bf73b8691d74e9d372b7b0113c63ad2e84c2efd50

Contents?: true

Size: 1.75 KB

Versions: 37

Compression:

Stored size: 1.75 KB

Contents

namespace :katello do
  desc "Removes custom products (and their associated pools and subscriptions) from Candlepin that are not in Katello"
  task :clean_candlepin_orphaned_products => ["dynflow:client", "environment"] do
    User.current = User.anonymous_admin #set a user for orchestration

    deleted_products_counts = {}
    Organization.all.each do |org|
      print "Cleaning Candlepin orphaned custom products for organization #{org.name}\n"

      cp_products = Katello::Resources::Candlepin::Product.all(org.label)
      cp_products = cp_products.select { |prod| Katello::Glue::Candlepin::Product.engineering_product_id?(prod['id']) }
      cp_product_ids = cp_products.map { |cp_product| cp_product['id'] }

      katello_product_ids = Katello::Product.where(:organization_id => org.id).pluck(:cp_id)
      orphaned_cp_product_ids = cp_product_ids - katello_product_ids
      orphaned_cp_product_ids.each do |cp_product_id|
        print "Deleting Candlepin orphaned custom product #{cp_product_id} (and its associated pools and subscriptions)\n"
        ForemanTasks.sync_task(
          ::Actions::Candlepin::Product::DeletePools,
          cp_id: cp_product_id, organization_label: org.label)

        ForemanTasks.sync_task(
          ::Actions::Candlepin::Product::DeleteSubscriptions,
          cp_id: cp_product_id, organization_label: org.label)

        ForemanTasks.sync_task(
          ::Actions::Candlepin::Product::Destroy,
          owner: org.label, cp_id: cp_product_id)
      end

      deleted_products_counts[org.name] = orphaned_cp_product_ids.length
    end

    deleted_products_counts.each do |org_name, deleted_products_count|
      print "Deleted #{deleted_products_count} Candlepin orphaned custom products for organization #{org_name}\n"
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
katello-4.14.2 lib/katello/tasks/clean_candlepin_orphaned_products.rake
katello-4.15.0 lib/katello/tasks/clean_candlepin_orphaned_products.rake
katello-4.15.0.rc2 lib/katello/tasks/clean_candlepin_orphaned_products.rake
katello-4.15.0.rc1 lib/katello/tasks/clean_candlepin_orphaned_products.rake
katello-4.14.1 lib/katello/tasks/clean_candlepin_orphaned_products.rake
katello-4.14.0 lib/katello/tasks/clean_candlepin_orphaned_products.rake
katello-4.14.0.rc3 lib/katello/tasks/clean_candlepin_orphaned_products.rake
katello-4.14.0.rc2 lib/katello/tasks/clean_candlepin_orphaned_products.rake
katello-4.14.0.rc1.1 lib/katello/tasks/clean_candlepin_orphaned_products.rake
katello-4.14.0.rc1 lib/katello/tasks/clean_candlepin_orphaned_products.rake
katello-4.13.1 lib/katello/tasks/clean_candlepin_orphaned_products.rake
katello-4.13.0 lib/katello/tasks/clean_candlepin_orphaned_products.rake
katello-4.12.1 lib/katello/tasks/clean_candlepin_orphaned_products.rake
katello-4.13.0.rc1 lib/katello/tasks/clean_candlepin_orphaned_products.rake
katello-4.12.0 lib/katello/tasks/clean_candlepin_orphaned_products.rake
katello-4.12.0.rc3 lib/katello/tasks/clean_candlepin_orphaned_products.rake
katello-4.12.0.rc2 lib/katello/tasks/clean_candlepin_orphaned_products.rake
katello-4.12.0.rc1 lib/katello/tasks/clean_candlepin_orphaned_products.rake
katello-4.11.1 lib/katello/tasks/clean_candlepin_orphaned_products.rake
katello-4.11.0 lib/katello/tasks/clean_candlepin_orphaned_products.rake