Class: Actions::Katello::ContentView::Remove
- Inherits:
-
EntryAction
- Object
- EntryAction
- Actions::Katello::ContentView::Remove
- Defined in:
- app/lib/actions/katello/content_view/remove.rb
Instance Method Summary collapse
- #activation_key_cve(options) ⇒ Object
- #check_version_deletion(versions, cv_envs) ⇒ Object
- #combined_cv_envs(cv_envs, versions) ⇒ Object
- #destroy_host_and_hostgroup_associations(content_view:) ⇒ Object
- #finalize ⇒ Object
- #humanized_name ⇒ Object
-
#plan(content_view, options) ⇒ Object
Options: (note that all are optional) content_view_environments - content view environments to delete content_view_versions - view versions to delete system_content_view_id - content view to reassociate systems with system_environment_id - environment to reassociate systems with key_content_view_id - content view to reassociate actvation keys with key_environment_id - environment to reassociate activation keys with’ destroy_content_view - delete the CV completely along with all cv versions and environments organization_destroy rubocop:disable Metrics/MethodLength rubocop:disable Metrics/CyclomaticComplexity.
- #system_cve(options) ⇒ Object
- #validate_options(_content_view, cv_envs, versions, options) ⇒ Object
Instance Method Details
#activation_key_cve(options) ⇒ Object
141 142 143 144 145 |
# File 'app/lib/actions/katello/content_view/remove.rb', line 141 def activation_key_cve() ::Katello::ContentViewEnvironment.where(:environment_id => [:key_environment_id], :content_view_id => [:key_content_view_id] ).first end |
#check_version_deletion(versions, cv_envs) ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'app/lib/actions/katello/content_view/remove.rb', line 86 def check_version_deletion(versions, cv_envs) versions.each do |version| version.environments.each do |env| if cv_envs.none? { |cv_env| cv_env.content_view_version == version && cv_env.environment == env } fail _("Cannot delete version while it is in environment %s") % env.name end end end end |
#combined_cv_envs(cv_envs, versions) ⇒ Object
131 132 133 |
# File 'app/lib/actions/katello/content_view/remove.rb', line 131 def combined_cv_envs(cv_envs, versions) (cv_envs + versions.flat_map(&:content_view_environments)).uniq end |
#destroy_host_and_hostgroup_associations(content_view:) ⇒ Object
79 80 81 82 83 84 |
# File 'app/lib/actions/katello/content_view/remove.rb', line 79 def destroy_host_and_hostgroup_associations(content_view:) content_view.hostgroups.destroy_all host_ids = content_view.hosts.ids ::Katello::Host::ContentFacet.where(:host_id => host_ids).destroy_all ::Katello::Host::SubscriptionFacet.where(:host_id => host_ids).destroy_all end |
#finalize ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'app/lib/actions/katello/content_view/remove.rb', line 100 def finalize if input[:destroy_content_view] content_view = ::Katello::ContentView.find(input[:content_view_id]) content_view.content_view_repositories.each(&:destroy) content_view.destroy! else input[:content_view_history_ids].each do |history_id| history = ::Katello::ContentViewHistory.find_by(:id => history_id) if history history.status = ::Katello::ContentViewHistory::SUCCESSFUL history.save! end end end end |
#humanized_name ⇒ Object
96 97 98 |
# File 'app/lib/actions/katello/content_view/remove.rb', line 96 def humanized_name _("Remove Versions and Associations") end |
#plan(content_view, options) ⇒ Object
Options: (note that all are optional) content_view_environments - content view environments to delete content_view_versions - view versions to delete system_content_view_id - content view to reassociate systems with system_environment_id - environment to reassociate systems with key_content_view_id - content view to reassociate actvation keys with key_environment_id - environment to reassociate activation keys with’ destroy_content_view - delete the CV completely along with all cv versions and environments organization_destroy rubocop:disable Metrics/MethodLength rubocop:disable Metrics/CyclomaticComplexity
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/lib/actions/katello/content_view/remove.rb', line 18 def plan(content_view, ) cv_envs = .fetch(:content_view_environments, []) versions = .fetch(:content_view_versions, []) organization_destroy = .fetch(:organization_destroy, false) skip_repo_destroy = .fetch(:skip_repo_destroy, false) action_subject(content_view) (content_view, cv_envs, versions, ) unless organization_destroy all_cv_envs = combined_cv_envs(cv_envs, versions) check_version_deletion(versions, cv_envs) sequence do unless organization_destroy concurrence do all_cv_envs.each do |cv_env| if cv_env.hosts.any? || cv_env.activation_keys.any? plan_action(ContentViewEnvironment::ReassignObjects, cv_env, ) end end end end cv_histories = [] all_cv_envs.each do |cve| cv_histories << ::Katello::ContentViewHistory.create!(:content_view_version => cve.content_view_version, :user => ::User.current.login, :environment => cve.environment, :status => ::Katello::ContentViewHistory::IN_PROGRESS, :action => ::Katello::ContentViewHistory.actions[:removal], :task => self.task) plan_action(ContentViewEnvironment::Destroy, cve, :skip_repo_destroy => skip_repo_destroy, :organization_destroy => organization_destroy) end versions.each do |version| ::Katello::ContentViewHistory.create!(:content_view_version => version, :user => ::User.current.login, :action => ::Katello::ContentViewHistory.actions[:removal], :status => ::Katello::ContentViewHistory::IN_PROGRESS, :task => self.task) plan_action(ContentViewVersion::Destroy, version, :skip_environment_check => true, :skip_destroy_env_content => true) end if [:destroy_content_view] && SmartProxy.pulp_primary&.pulp3_enabled? plan_action(Actions::Pulp3::ContentView::DeleteRepositoryReferences, content_view, SmartProxy.pulp_primary) end plan_self(content_view_id: content_view.id, destroy_content_view: [:destroy_content_view], environment_ids: cv_envs.map(&:environment_id), environment_names: cv_envs.map { |cve| cve.environment.name }, version_ids: versions.map(&:id), content_view_history_ids: cv_histories.map { |history| history.id }) if organization_destroy destroy_host_and_hostgroup_associations(content_view: content_view) end end end |
#system_cve(options) ⇒ Object
135 136 137 138 139 |
# File 'app/lib/actions/katello/content_view/remove.rb', line 135 def system_cve() ::Katello::ContentViewEnvironment.where(:environment_id => [:system_environment_id], :content_view_id => [:system_content_view_id] ).first end |
#validate_options(_content_view, cv_envs, versions, options) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'app/lib/actions/katello/content_view/remove.rb', line 116 def (_content_view, cv_envs, versions, ) if ![:destroy_content_view] && cv_envs.empty? && versions.empty? fail _("Either environments or versions must be specified.") end all_cv_envs = combined_cv_envs(cv_envs, versions) if all_cv_envs.flat_map(&:hosts).any? && system_cve().nil? fail _("Unable to reassign systems. Please check system_content_view_id and system_environment_id.") end if all_cv_envs.flat_map(&:activation_keys).any? && activation_key_cve().nil? fail _("Unable to reassign activation_keys. Please check activation_key_content_view_id and activation_key_environment_id.") end end |