Class: Actions::Katello::Repository::Destroy
- Inherits:
-
EntryAction
- Object
- EntryAction
- Actions::Katello::Repository::Destroy
- Defined in:
- app/lib/actions/katello/repository/destroy.rb
Instance Method Summary collapse
- #check_destroyable!(repository, remove_from_content_view_versions) ⇒ Object
- #delete_empty_repo_filters(repository) ⇒ Object
- #delete_record(repository, options = {}) ⇒ Object
- #finalize ⇒ Object
- #handle_acs_product_removal(repository) ⇒ Object
- #handle_alternate_content_sources(repository) ⇒ Object
- #handle_custom_content(repository, remove_from_content_view_versions) ⇒ Object
- #handle_redhat_content(repository) ⇒ Object
- #humanized_name ⇒ Object
-
#plan(repository, options = {}) ⇒ Object
options: skip_environment_update - defaults to false.
- #remove_generated_content_views(repository) ⇒ Object
- #remove_versions(repository, content_views, affected_cvv_ids) ⇒ Object
Instance Method Details
#check_destroyable!(repository, remove_from_content_view_versions) ⇒ Object
133 134 135 136 137 138 139 |
# File 'app/lib/actions/katello/repository/destroy.rb', line 133 def check_destroyable!(repository, remove_from_content_view_versions) unless repository.destroyable?(remove_from_content_view_versions) # The repository is going to be deleted in finalize, but it cannot be deleted. # Stop now and inform the user. fail repository.errors..values.join("\n") end end |
#delete_empty_repo_filters(repository) ⇒ Object
83 84 85 86 |
# File 'app/lib/actions/katello/repository/destroy.rb', line 83 def delete_empty_repo_filters(repository) filters_to_delete = repository.filters.select { |filter| filter.repositories.size == 1 } ::Katello::ContentViewFilter.where(id: filters_to_delete).destroy_all end |
#delete_record(repository, options = {}) ⇒ Object
105 106 107 108 109 110 |
# File 'app/lib/actions/katello/repository/destroy.rb', line 105 def delete_record(repository, = {}) ::Katello::SyncPlan.remove_disabled_product(repository) if repository.redhat? repository.destroy! repository.root.destroy! if repository.root.repositories.empty? ::Katello::DockerMetaTag. if [:docker_cleanup] end |
#finalize ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/lib/actions/katello/repository/destroy.rb', line 48 def finalize repository = ::Katello::Repository.find_by(id: input[:repository][:id]) if repository docker_cleanup = repository.docker? && input[:docker_cleanup] delete_record(repository, {docker_cleanup: docker_cleanup}) if (affected_cvv_ids = input[:affected_cvv_ids]).any? cvvs = ::Katello::ContentViewVersion.where(id: affected_cvv_ids) cvvs.each do |cvv| cvv.update_content_counts! end end end end |
#handle_acs_product_removal(repository) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/lib/actions/katello/repository/destroy.rb', line 69 def handle_acs_product_removal(repository) # Remove products from ACS's that contain no repositories which both # match the ACS content type and have a non-nil URL product = repository.product repo_content_types = ::Katello::RootRepository.where(:id => product.repositories.where.not(:id => repository.id).select(:root_id)).where.not(:url => [nil, '']).distinct.pluck(:content_type) ::Katello::AlternateContentSource.with_products(product).each do |acs| unless repo_content_types.include?(acs.content_type) acs.products = acs.products - [product] Rails.logger.info _('Removing product %{prod_name} with ID %{prod_id} from ACS %{acs_name} with ID %{acs_id}') % { prod_name: product.name, prod_id: product.id, acs_name: acs.name, acs_id: acs.id } end end end |
#handle_alternate_content_sources(repository) ⇒ Object
63 64 65 66 67 |
# File 'app/lib/actions/katello/repository/destroy.rb', line 63 def handle_alternate_content_sources(repository) repository.smart_proxy_alternate_content_sources.each do |smart_proxy_acs| plan_action(Pulp3::Orchestration::AlternateContentSource::Delete, smart_proxy_acs) end end |
#handle_custom_content(repository, remove_from_content_view_versions) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'app/lib/actions/katello/repository/destroy.rb', line 88 def handle_custom_content(repository, remove_from_content_view_versions) #if this is the last instance of a custom repo or a deb repo using structured APT, destroy the content if remove_from_content_view_versions || repository.root.repositories.where.not(id: repository.id).empty? || repository.deb_using_structured_apt? # Never destroy content for structured apt rolling repo clones, because it belongs to the library instance return if repository.deb_using_structured_apt? && repository.content_view.rolling? plan_action(::Actions::Katello::Product::ContentDestroy, repository) end end |
#handle_redhat_content(repository) ⇒ Object
98 99 100 101 102 103 |
# File 'app/lib/actions/katello/repository/destroy.rb', line 98 def handle_redhat_content(repository) content_view_environment = repository.content_view.content_view_environment(repository.environment) if content_view_environment && !repository.content_view.rolling? plan_action(Candlepin::Environment::SetContent, repository.content_view, repository.environment, content_view_environment) end end |
#humanized_name ⇒ Object
141 142 143 |
# File 'app/lib/actions/katello/repository/destroy.rb', line 141 def humanized_name _("Delete") end |
#plan(repository, options = {}) ⇒ Object
options:
skip_environment_update - defaults to false. skips updating the CP environment
destroy_content - can be disabled to skip Candlepin remove_content
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/lib/actions/katello/repository/destroy.rb', line 12 def plan(repository, = {}) affected_cvv_ids = [] skip_environment_update = .fetch(:skip_environment_update, false) || .fetch(:organization_destroy, false) destroy_content = .fetch(:destroy_content, true) remove_from_content_view_versions = .fetch(:remove_from_content_view_versions, false) delete_empty_repo_filters = .fetch(:delete_empty_repo_filters, true) docker_cleanup = .fetch(:docker_cleanup, true) action_subject(repository) check_destroyable!(repository, remove_from_content_view_versions) remove_generated_content_views(repository) remove_versions(repository, repository.content_views.generated_for_library, affected_cvv_ids) plan_action(Actions::Pulp3::Orchestration::Repository::Delete, repository, SmartProxy.pulp_primary) remove_versions(repository, repository.content_views_all(include_composite: true)&.generated_for_none, affected_cvv_ids) if remove_from_content_view_versions handle_acs_product_removal(repository) handle_alternate_content_sources(repository) delete_empty_repo_filters(repository) if delete_empty_repo_filters plan_self(:user_id => ::User.current.id, :affected_cvv_ids => affected_cvv_ids, :docker_cleanup => docker_cleanup) sequence do if repository.redhat? handle_redhat_content(repository) unless skip_environment_update else if destroy_content && !skip_environment_update handle_custom_content(repository, remove_from_content_view_versions) end end end end |
#remove_generated_content_views(repository) ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'app/lib/actions/katello/repository/destroy.rb', line 112 def remove_generated_content_views(repository) # remove the content views generated for this repository (since we are deleting the repo) content_views = repository.content_views.generated_for_repository return if content_views.blank? plan_action(::Actions::BulkAction, ::Actions::Katello::ContentView::Remove, content_views, skip_repo_destroy: true, destroy_content_view: true) end |
#remove_versions(repository, content_views, affected_cvv_ids) ⇒ Object
122 123 124 125 126 127 128 129 130 131 |
# File 'app/lib/actions/katello/repository/destroy.rb', line 122 def remove_versions(repository, content_views, affected_cvv_ids) return if content_views.blank? interested_inverses = repository. library_instances_inverse. joins(:content_view_version => :content_view). merge(content_views) return if interested_inverses.blank? affected_cvv_ids.concat(interested_inverses.pluck(:content_view_version_id)&.uniq) plan_action(::Actions::BulkAction, ::Actions::Katello::Repository::Destroy, interested_inverses) end |