Class: Actions::Katello::Environment::Destroy

Inherits:
EntryAction
  • Object
show all
Defined in:
app/lib/actions/katello/environment/destroy.rb

Instance Method Summary collapse

Instance Method Details

#delete_host_and_hostgroup_associations(environment:) ⇒ Object



34
35
36
37
38
39
# File 'app/lib/actions/katello/environment/destroy.rb', line 34

def delete_host_and_hostgroup_associations(environment:)
  environment.hostgroups.delete_all
  host_ids = environment.hosts.ids
  ::Katello::Host::ContentFacet.where(:host_id => host_ids).delete_all
  ::Katello::Host::SubscriptionFacet.where(:host_id => host_ids).delete_all
end

#finalizeObject



49
50
51
52
53
54
55
56
# File 'app/lib/actions/katello/environment/destroy.rb', line 49

def finalize
  environment = ::Katello::KTEnvironment.find(input['kt_environment']['id'])

  # CapsuleLifecycleEnvironment can cause issues when auditing, it will try to associate the audit to the deleted taxonomy
  ::Katello::CapsuleLifecycleEnvironment.without_auditing do
    environment.destroy!
  end
end

#humanized_inputObject



45
46
47
# File 'app/lib/actions/katello/environment/destroy.rb', line 45

def humanized_input
  ["'#{input['kt_environment']['name']}'"] + super
end

#humanized_nameObject



41
42
43
# File 'app/lib/actions/katello/environment/destroy.rb', line 41

def humanized_name
  _("Delete Lifecycle Environment")
end

#plan(env, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/lib/actions/katello/environment/destroy.rb', line 12

def plan(env, options = {})
  fail env.errors.full_messages.join(" ") unless env.deletable?

  skip_repo_destroy = options.fetch(:skip_repo_destroy, false)
  organization_destroy = options.fetch(:organization_destroy, false)
  sequence do
    action_subject(env)

    concurrence do
      env.content_view_environments.each do |cve|
        plan_action(ContentView::Remove, cve.content_view, :content_view_environments => [cve], :skip_repo_destroy => skip_repo_destroy, :organization_destroy => organization_destroy)
      end
    end

    if organization_destroy
      delete_host_and_hostgroup_associations(environment: env)
    end

    plan_self
  end
end