Module: ForemanRhCloud::RegistrationManagerExtensions

Includes:
CertAuth
Defined in:
app/controllers/concerns/foreman_rh_cloud/registration_manager_extensions.rb

Instance Method Summary collapse

Methods included from CertAuth

#cert_auth_available?, #execute_cloud_request, #foreman_certificate

Methods included from InsightsCloud::CandlepinCache

#candlepin_id_cert, #cp_owner_id, #upstream_owner

Methods included from CloudRequest

#execute_cloud_request

Instance Method Details

#hbi_host_destroy(host) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/concerns/foreman_rh_cloud/registration_manager_extensions.rb', line 21

def hbi_host_destroy(host)
  uuid = host.insights_facet.uuid
  logger.debug "Unregistering host #{uuid} from HBI"
  execute_cloud_request(
    organization: host.organization,
    method: :delete,
    url: ForemanInventoryUpload.host_by_id_url(uuid),
    headers: {
      content_type: :json,
    }
  )
rescue RestClient::NotFound
  Rails.logger.warn(_("Attempted to destroy HBI host %s, but host does not exist in HBI") % uuid)
rescue StandardError => e
  # TODO: Improve error handling - don't break registration if HBI delete fails
  Rails.logger.error(format(_("Failed to destroy HBI host %s: %s"), uuid, e.message))
end

#loggerObject



5
6
7
# File 'app/controllers/concerns/foreman_rh_cloud/registration_manager_extensions.rb', line 5

def logger
  Rails.logger
end

#unregister_host(host, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/concerns/foreman_rh_cloud/registration_manager_extensions.rb', line 9

def unregister_host(host, options = {})
  organization_destroy = options.fetch(:organization_destroy, false)

  # Reload to ensure we have fresh association data
  host.reload

  # Only delete from HBI in IoP mode (hosted mode uses async job for cleanup)
  hbi_host_destroy(host) if ForemanRhCloud.with_iop_smart_proxy? && !organization_destroy && host.insights_facet&.uuid&.presence
  host.insights&.destroy!
  super(host, options)
end