Skip to content

Commit e5d7001

Browse files
committed
Generate single-host reports without shell commands or rake task
1 parent e081829 commit e5d7001

File tree

4 files changed

+65
-4
lines changed

4 files changed

+65
-4
lines changed

app/controllers/concerns/insights_cloud/package_profile_upload_extensions.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ def generate_host_report
1515
logger.debug("Generating host-specific report for host #{@host.name}")
1616

1717
ForemanTasks.async_task(
18-
ForemanInventoryUpload::Async::GenerateReportJob,
18+
ForemanInventoryUpload::Async::SingleHostReportJob,
1919
ForemanInventoryUpload.generated_reports_folder,
2020
@host.organization_id,
21-
false,
22-
"id=#{@host.id}"
21+
@host.id
2322
)
2423

2524
# in IoP case, the hosts are identified by the sub-man ID, and we can assume they already
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module ForemanInventoryUpload
2+
module Async
3+
class GenerateSingleHostReport < ::Actions::EntryAction
4+
def plan(base_folder, organization_id, filter)
5+
plan_self(
6+
base_folder: base_folder,
7+
organization_id: organization_id,
8+
filter: filter,
9+
)
10+
input[:target] = File.join(base_folder, ForemanInventoryUpload.facts_archive_name(input[:organization_id], input[:filter]))
11+
archived_report_generator = ForemanInventoryUpload::Generators::ArchivedReport.new(input[:target])
12+
archived_report_generator.render(organization: input[:organization_id], filter: input[:filter])
13+
end
14+
15+
def finalize
16+
output[:result] = "Generated #{input[:target]} for organization id #{input[:organization_id]}"
17+
end
18+
end
19+
end
20+
end
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
module ForemanInventoryUpload
2+
module Async
3+
class SingleHostReportJob < ::Actions::EntryAction
4+
def plan(base_folder, organization_id, host_id)
5+
input[:host_id] = host_id
6+
sequence do
7+
plan_action(
8+
GenerateSingleHostReport,
9+
base_folder,
10+
organization_id,
11+
hosts_filter,
12+
)
13+
14+
plan_action(
15+
QueueForUploadJob,
16+
base_folder,
17+
ForemanInventoryUpload.facts_archive_name(organization_id, hosts_filter),
18+
organization_id
19+
)
20+
end
21+
end
22+
23+
def hostname(host_id)
24+
host = ::Host.find_by(id: host_id)
25+
host&.name
26+
end
27+
28+
def humanized_name
29+
hostname_result = hostname(input[:host_id])
30+
hostname_result.present? ? _("Single-host report job for host %s" % hostname_result) : _("Single-host report job")
31+
end
32+
33+
def organization_id
34+
input[:organization_id]
35+
end
36+
37+
def hosts_filter
38+
"id=#{input[:host_id]}"
39+
end
40+
end
41+
end
42+
end

lib/foreman_inventory_upload/generators/slice.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def report_yum_repos(host)
256256

257257
@stream.array_field('yum_repos') do
258258
host.content_facet.bound_repositories.each_with_index do |repo, index|
259-
report_yum_repo(host.content_source.load_balancer_pulp_content_url, repo)
259+
report_yum_repo(host.content_source&.load_balancer_pulp_content_url || ::SmartProxy.pulp_primary.pulp_content_url, repo)
260260
@stream.comma unless index == host.content_facet.bound_repositories.count - 1
261261
end
262262
end

0 commit comments

Comments
 (0)