Class: ForemanInventoryUpload::Async::DestroyOrganizationHbiHostsJob

Inherits:
Actions::EntryAction
  • Object
show all
Includes:
ForemanRhCloud::CertAuth
Defined in:
lib/foreman_inventory_upload/async/destroy_organization_hbi_hosts_job.rb

Instance Method Summary collapse

Methods included from ForemanRhCloud::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 ForemanRhCloud::CloudRequest

#execute_cloud_request

Instance Method Details

#humanized_nameObject



44
45
46
# File 'lib/foreman_inventory_upload/async/destroy_organization_hbi_hosts_job.rb', line 44

def humanized_name
  _("Destroy HBI hosts for organization")
end

#loggerObject



36
37
38
# File 'lib/foreman_inventory_upload/async/destroy_organization_hbi_hosts_job.rb', line 36

def logger
  Foreman::Logging.logger('background')
end

#plan(organization_id) ⇒ Object



6
7
8
# File 'lib/foreman_inventory_upload/async/destroy_organization_hbi_hosts_job.rb', line 6

def plan(organization_id)
  plan_self(organization_id: organization_id)
end

#rescue_strategyObject



40
41
42
# File 'lib/foreman_inventory_upload/async/destroy_organization_hbi_hosts_job.rb', line 40

def rescue_strategy
  Dynflow::Action::Rescue::Skip
end

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/foreman_inventory_upload/async/destroy_organization_hbi_hosts_job.rb', line 10

def run
  org = Organization.find_by(id: input[:organization_id])
  unless org
    output[:result] = _("Organization not found")
    return
  end

  logger.info("Destroying all HBI hosts for organization #{org.label} (id: #{org.id})")

  execute_cloud_request(
    organization: org,
    method: :delete,
    url: ForemanInventoryUpload.hosts_delete_all_url,
    headers: {
      content_type: :json,
    }
  )

  output[:result] = format(_("Successfully deleted all HBI hosts for organization %s"), org.label)
rescue RestClient::NotFound
  output[:result] = format(_("No HBI hosts found for organization %s"), org&.label)
rescue StandardError => e
  logger.error(format(_("Failed to destroy HBI hosts for organization %s: %s"), org&.label, e.message))
  raise
end