Class: ForemanExpireHosts::SafeDestroy
- Inherits:
-
Object
- Object
- ForemanExpireHosts::SafeDestroy
- Defined in:
- app/services/foreman_expire_hosts/safe_destroy.rb
Instance Attribute Summary collapse
-
#subject ⇒ Object
See projects.theforeman.org/issues/14702 for reasoning.
Instance Method Summary collapse
- #destroy! ⇒ Object
-
#initialize(subject) ⇒ SafeDestroy
constructor
A new instance of SafeDestroy.
Constructor Details
#initialize(subject) ⇒ SafeDestroy
Returns a new instance of SafeDestroy.
8 9 10 |
# File 'app/services/foreman_expire_hosts/safe_destroy.rb', line 8 def initialize(subject) self.subject = subject end |
Instance Attribute Details
#subject ⇒ Object
See projects.theforeman.org/issues/14702 for reasoning.
6 7 8 |
# File 'app/services/foreman_expire_hosts/safe_destroy.rb', line 6 def subject @subject end |
Instance Method Details
#destroy! ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/services/foreman_expire_hosts/safe_destroy.rb', line 12 def destroy! # If Katello is installed, we can't just destroy the host # but have to delete it the Katello way. # See https://community.theforeman.org/t/how-to-properly-destroy-a-content-host/8621 # for reasoning. if subject.is_a?(Host::Base) && with_katello? Katello::RegistrationManager.unregister_host(subject) else subject.destroy! end rescue ActiveRecord::RecordNotDestroyed => e = _('Failed to delete %{class_name} %{subject}: %{message} - Errors: %{errors}') % { :class_name => subject.class.name, :subject => subject, :message => e., :errors => e.record.errors..to_sentence } Foreman::Logging.exception(, e) false end |