Class: Katello::Util::ContentOverridesMigrator
- Inherits:
-
Object
- Object
- Katello::Util::ContentOverridesMigrator
- Includes:
- ActionView::Helpers::TextHelper
- Defined in:
- app/lib/katello/util/content_overrides_migrator.rb
Overview
used in Actions::Katello::Organization::SimpleContentAccess::PrepareContentOverrides
Instance Method Summary collapse
- #create_disabled_overrides_for_non_sca(consumable:) ⇒ Object
- #create_disabled_overrides_for_non_sca_org_activation_keys(organization:) ⇒ Object
- #create_disabled_overrides_for_non_sca_org_hosts(organization:) ⇒ Object
- #execute_non_sca_overrides! ⇒ Object
-
#initialize(organization:) ⇒ ContentOverridesMigrator
constructor
A new instance of ContentOverridesMigrator.
Constructor Details
#initialize(organization:) ⇒ ContentOverridesMigrator
Returns a new instance of ContentOverridesMigrator.
6 7 8 |
# File 'app/lib/katello/util/content_overrides_migrator.rb', line 6 def initialize(organization:) @organization = organization end |
Instance Method Details
#create_disabled_overrides_for_non_sca(consumable:) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/lib/katello/util/content_overrides_migrator.rb', line 27 def create_disabled_overrides_for_non_sca(consumable:) content_finder = ::Katello::ProductContentFinder.new( match_subscription: false, match_environment: false, consumable: consumable ) subscribed_content_finder = ::Katello::ProductContentFinder.new( match_subscription: true, match_environment: false, consumable: consumable ) candlepin_resource = consumable.is_a?(::Katello::Host::SubscriptionFacet) ? ::Katello::Resources::Candlepin::Consumer : ::Katello::Resources::Candlepin::ActivationKey consumable_id = consumable.is_a?(::Katello::Host::SubscriptionFacet) ? consumable.uuid : consumable.cp_id repos_with_existing_overrides = candlepin_resource.content_overrides(consumable_id).map do |override| override[:contentLabel] end unsubscribed_content = content_finder.custom_content_labels - subscribed_content_finder.custom_content_labels - repos_with_existing_overrides new_overrides = unsubscribed_content.map do |repo_label| ::Katello::ContentOverride.new( repo_label, { name: "enabled", value: "0" } # Override to disabled ) end return if new_overrides.blank? if consumable.is_a? ::Katello::Host::SubscriptionFacet ::Katello::Resources::Candlepin::Consumer.update_content_overrides( consumable.uuid, new_overrides.map(&:to_entitlement_hash) ) else ::Katello::Resources::Candlepin::ActivationKey.update_content_overrides( consumable.cp_id, new_overrides.map(&:to_entitlement_hash) ) end end |
#create_disabled_overrides_for_non_sca_org_activation_keys(organization:) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/lib/katello/util/content_overrides_migrator.rb', line 81 def create_disabled_overrides_for_non_sca_org_activation_keys(organization:) errors = 0 fail _("Organization must be specified") if organization.blank? return 0 if organization.simple_content_access? # subscription attachment is meaningless with SCA Rails.logger.info("Activation keys - Creating disabled overrides for unsubscribed content in organization #{organization.name}") aks_to_update = organization.activation_keys aks_to_update.each do |ak| create_disabled_overrides_for_non_sca(consumable: ak) rescue => e errors += 1 Rails.logger.error("Failed to update activation key #{ak.name}: #{e.}") Rails.logger.debug e.backtrace.join("\n") end errors end |
#create_disabled_overrides_for_non_sca_org_hosts(organization:) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/lib/katello/util/content_overrides_migrator.rb', line 64 def create_disabled_overrides_for_non_sca_org_hosts(organization:) errors = 0 fail _("Organization must be specified") if organization.blank? return 0 if organization.simple_content_access? # subscription attachment is meaningless with SCA Rails.logger.info("Hosts - Creating disabled overrides for unsubscribed content in organization #{organization.name}") # only registered hosts with content! hosts_to_update = organization.hosts.joins(:subscription_facet).where.not("#{Katello::Host::SubscriptionFacet.table_name}.host_id" => nil) hosts_to_update.each do |host| create_disabled_overrides_for_non_sca(consumable: host.subscription_facet) rescue => e errors += 1 Rails.logger.error("Failed to update host #{host.name}: #{e.}") Rails.logger.debug e.backtrace.join("\n") end errors end |
#execute_non_sca_overrides! ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/lib/katello/util/content_overrides_migrator.rb', line 10 def execute_non_sca_overrides! host_errors = create_disabled_overrides_for_non_sca_org_hosts(organization: @organization) ak_errors = create_disabled_overrides_for_non_sca_org_activation_keys(organization: @organization) total_errors = host_errors + ak_errors = "Finished creating overrides in non-SCA org; #{total_errors == 0 ? "no errors" : "#{pluralize(total_errors, "error")}"}" = { result: , errors: total_errors } [:host_errors] = "Hosts - #{pluralize(host_errors, "error")} creating disabled overrides for unsubscribed content; see log messages above" if host_errors > 0 [:ak_errors] = "Activation keys - #{pluralize(ak_errors, "error")} creating disabled overrides for unsubscribed content; see log messages above" if ak_errors > 0 [:success_message] = "Organization may now be switched to Simple Content Access mode without any change in access to content." if total_errors == 0 Rails.logger.info Rails.logger.info [:host_errors] if [:host_errors] Rails.logger.info [:ak_errors] if [:ak_errors] Rails.logger.info [:success_message] if [:success_message] end |