foreman_inventory_upload 0.0.1.dev1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Rakefile +1 -1
- data/app/controllers/foreman_inventory_upload/accounts_controller.rb +39 -0
- data/app/controllers/foreman_inventory_upload/reports_controller.rb +13 -6
- data/app/controllers/foreman_inventory_upload/uploads_controller.rb +4 -4
- data/app/helpers/foreman_inventory_upload_helper.rb +1 -1
- data/app/views/scripts/uploader.sh.erb +21 -10
- data/config/routes.rb +5 -5
- data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +19 -0
- data/lib/foreman_inventory_upload/async/generate_report_job.rb +13 -9
- data/lib/foreman_inventory_upload/async/progress_output.rb +1 -1
- data/lib/foreman_inventory_upload/async/queue_for_upload_job.rb +12 -17
- data/lib/foreman_inventory_upload/async/shell_process.rb +2 -1
- data/lib/foreman_inventory_upload/async/upload_report_job.rb +22 -17
- data/lib/foreman_inventory_upload/engine.rb +11 -1
- data/lib/foreman_inventory_upload/generators/archived_report.rb +2 -2
- data/lib/foreman_inventory_upload/generators/queries.rb +20 -11
- data/lib/foreman_inventory_upload/generators/slice.rb +26 -5
- data/lib/foreman_inventory_upload/version.rb +1 -1
- data/lib/foreman_inventory_upload.rb +15 -10
- data/lib/tasks/generator.rake +19 -5
- data/package.json +125 -0
- data/test/controllers/{statuses_controller_test.rb → accounts_controller_test.rb} +6 -7
- data/test/controllers/reports_controller_test.rb +3 -3
- data/test/controllers/uploads_controller_test.rb +3 -3
- data/test/unit/archived_report_generator_test.rb +4 -4
- data/test/unit/slice_generator_test.rb +75 -1
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.fixtures.js +37 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.js +74 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountList.stories.js +18 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js +65 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListConstants.js +9 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListHelper.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListReducer.js +55 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/AccountListSelectors.js +8 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/EmptyState.fixtures.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/EmptyState.js +16 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/EmptyStateHelper.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/__tests__/EmptyState.test.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/__tests__/__snapshots__/EmptyState.test.js.snap +26 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/emptyState.scss +7 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/EmptyState/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/ErrorState.fixtures.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/ErrorState.js +23 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/ErrorStateHelper.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/__tests__/ErrorState.test.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/__tests__/__snapshots__/ErrorState.test.js.snap +20 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/errorState.scss +18 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ErrorState/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/ListItem.fixtures.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/ListItem.js +41 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/ListItemHelper.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/__tests__/ListItem.test.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/__tests__/__snapshots__/ListItem.test.js.snap +50 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItem/listItem.scss +0 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/ListItemStatus.fixtures.js +7 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/ListItemStatus.js +43 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/ListItemStatusHelper.js +29 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/__tests__/ListItemStatus.test.js +14 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/__tests__/__snapshots__/ListItemStatus.test.js.snap +78 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/Components/ListItemStatus/listItemStatus.scss +16 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountList.test.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListActions.test.js +20 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListIntegration.test.js +14 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListReducer.test.js +60 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/AccountListSelectors.test.js +26 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountList.test.js.snap +44 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListActions.test.js.snap +47 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListReducer.test.js.snap +69 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/__tests__/__snapshots__/AccountListSelectors.test.js.snap +46 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/accountList.scss +9 -0
- data/webpack/ForemanInventoryUpload/Components/AccountList/index.js +27 -0
- data/webpack/ForemanInventoryUpload/Components/Dashboard/Dashboard.fixtures.js +50 -0
- data/webpack/ForemanInventoryUpload/Components/Dashboard/Dashboard.js +146 -0
- data/webpack/ForemanInventoryUpload/Components/Dashboard/Dashboard.stories.js +19 -0
- data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardActions.js +87 -0
- data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardConstants.js +9 -0
- data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardHelper.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardReducer.js +68 -0
- data/webpack/ForemanInventoryUpload/Components/Dashboard/DashboardSelectors.js +17 -0
- data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/Dashboard.test.js +25 -0
- data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardActions.test.js +39 -0
- data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardIntegration.test.js +16 -0
- data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardReducer.test.js +64 -0
- data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/DashboardSelectors.test.js +45 -0
- data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/__snapshots__/Dashboard.test.js.snap +36 -0
- data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/__snapshots__/DashboardActions.test.js.snap +76 -0
- data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/__snapshots__/DashboardReducer.test.js.snap +44 -0
- data/webpack/ForemanInventoryUpload/Components/Dashboard/__tests__/__snapshots__/DashboardSelectors.test.js.snap +42 -0
- data/webpack/ForemanInventoryUpload/Components/Dashboard/dashboard.scss +0 -0
- data/webpack/ForemanInventoryUpload/Components/Dashboard/index.js +34 -0
- data/webpack/ForemanInventoryUpload/Components/FileDownload/FileDownload.fixtures.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/FileDownload/FileDownload.js +22 -0
- data/webpack/ForemanInventoryUpload/Components/FileDownload/FileDownloadHelper.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/FileDownload/__tests__/FileDownload.test.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/FileDownload/__tests__/__snapshots__/FileDownload.test.js.snap +25 -0
- data/webpack/ForemanInventoryUpload/Components/FileDownload/fileDownload.scss +3 -0
- data/webpack/ForemanInventoryUpload/Components/FileDownload/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/FullScreenModal/FullScreenModal.fixtures.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/FullScreenModal/FullScreenModal.js +50 -0
- data/webpack/ForemanInventoryUpload/Components/FullScreenModal/FullScreenModalHelper.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/FullScreenModal/__tests__/FullScreenModal.test.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/FullScreenModal/__tests__/__snapshots__/FullScreenModal.test.js.snap +64 -0
- data/webpack/ForemanInventoryUpload/Components/FullScreenModal/fullScreenModal.scss +10 -0
- data/webpack/ForemanInventoryUpload/Components/FullScreenModal/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/NavContainer/NavContainer.fixtures.js +10 -0
- data/webpack/ForemanInventoryUpload/Components/NavContainer/NavContainer.js +83 -0
- data/webpack/ForemanInventoryUpload/Components/NavContainer/NavContainerHelper.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/NavContainer/__tests__/NavContainer.test.js +26 -0
- data/webpack/ForemanInventoryUpload/Components/NavContainer/__tests__/__snapshots__/NavContainer.test.js.snap +89 -0
- data/webpack/ForemanInventoryUpload/Components/NavContainer/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/NavContainer/navContainer.scss +7 -0
- data/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerate.fixtures.js +16 -0
- data/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerate.js +57 -0
- data/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerateHelper.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/ReportGenerate/__tests__/ReportGenerate.test.js +14 -0
- data/webpack/ForemanInventoryUpload/Components/ReportGenerate/__tests__/__snapshots__/ReportGenerate.test.js.snap +45 -0
- data/webpack/ForemanInventoryUpload/Components/ReportGenerate/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/ReportGenerate/reportGenerate.scss +0 -0
- data/webpack/ForemanInventoryUpload/Components/ReportUpload/ReportUpload.fixtures.js +18 -0
- data/webpack/ForemanInventoryUpload/Components/ReportUpload/ReportUpload.js +57 -0
- data/webpack/ForemanInventoryUpload/Components/ReportUpload/ReportUploadHelper.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/ReportUpload/__tests__/ReportUpload.test.js +14 -0
- data/webpack/ForemanInventoryUpload/Components/ReportUpload/__tests__/__snapshots__/ReportUpload.test.js.snap +45 -0
- data/webpack/ForemanInventoryUpload/Components/ReportUpload/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/ReportUpload/reportUpload.scss +0 -0
- data/webpack/ForemanInventoryUpload/Components/ScheduledRun/ScheduledRun.fixtures.js +3 -0
- data/webpack/ForemanInventoryUpload/Components/ScheduledRun/ScheduledRun.js +27 -0
- data/webpack/ForemanInventoryUpload/Components/ScheduledRun/ScheduledRunHelper.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/ScheduledRun.test.js +14 -0
- data/webpack/ForemanInventoryUpload/Components/ScheduledRun/__tests__/__snapshots__/ScheduledRun.test.js.snap +25 -0
- data/webpack/ForemanInventoryUpload/Components/ScheduledRun/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/ScheduledRun/scheduledRun.scss +11 -0
- data/webpack/ForemanInventoryUpload/Components/StatusChart/StatusChart.fixtures.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/StatusChart/StatusChart.js +56 -0
- data/webpack/ForemanInventoryUpload/Components/StatusChart/StatusChartHelper.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/StatusChart/__tests__/StatusChart.test.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/StatusChart/__tests__/__snapshots__/StatusChart.test.js.snap +74 -0
- data/webpack/ForemanInventoryUpload/Components/StatusChart/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/StatusChart/statusChart.scss +8 -0
- data/webpack/ForemanInventoryUpload/Components/TabBody/TabBody.fixtures.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/TabBody/TabBody.js +31 -0
- data/webpack/ForemanInventoryUpload/Components/TabBody/TabBodyHelper.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/TabBody/__tests__/TabBody.test.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/TabBody/__tests__/__snapshots__/TabBody.test.js.snap +19 -0
- data/webpack/ForemanInventoryUpload/Components/TabBody/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/TabBody/tabBody.scss +3 -0
- data/webpack/ForemanInventoryUpload/Components/TabContainer/TabContainer.fixtures.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/TabContainer/TabContainer.js +24 -0
- data/webpack/ForemanInventoryUpload/Components/TabContainer/TabContainerHelper.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/TabContainer/__tests__/TabContainer.test.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/TabContainer/__tests__/__snapshots__/TabContainer.test.js.snap +18 -0
- data/webpack/ForemanInventoryUpload/Components/TabContainer/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/TabContainer/tabContainer.scss +8 -0
- data/webpack/ForemanInventoryUpload/Components/TabFooter/TabFooter.fixtures.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/TabFooter/TabFooter.js +19 -0
- data/webpack/ForemanInventoryUpload/Components/TabFooter/TabFooterHelper.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/TabFooter/__tests__/TabFooter.test.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/TabFooter/__tests__/__snapshots__/TabFooter.test.js.snap +12 -0
- data/webpack/ForemanInventoryUpload/Components/TabFooter/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/TabFooter/tabFooter.scss +0 -0
- data/webpack/ForemanInventoryUpload/Components/TabHeader/TabHeader.fixtures.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/TabHeader/TabHeader.js +45 -0
- data/webpack/ForemanInventoryUpload/Components/TabHeader/TabHeaderHelper.js +0 -0
- data/webpack/ForemanInventoryUpload/Components/TabHeader/__tests__/TabHeader.test.js +13 -0
- data/webpack/ForemanInventoryUpload/Components/TabHeader/__tests__/__snapshots__/TabHeader.test.js.snap +53 -0
- data/webpack/ForemanInventoryUpload/Components/TabHeader/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/TabHeader/tabHeader.scss +21 -0
- data/webpack/ForemanInventoryUpload/Components/Terminal/Terminal.fixtures.js +10 -0
- data/webpack/ForemanInventoryUpload/Components/Terminal/Terminal.js +112 -0
- data/webpack/ForemanInventoryUpload/Components/Terminal/TerminalHelper.js +6 -0
- data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/Terminal.test.js +35 -0
- data/webpack/ForemanInventoryUpload/Components/Terminal/__tests__/__snapshots__/Terminal.test.js.snap +98 -0
- data/webpack/ForemanInventoryUpload/Components/Terminal/index.js +1 -0
- data/webpack/ForemanInventoryUpload/Components/Terminal/terminal.scss +31 -0
- data/webpack/ForemanInventoryUpload/ForemanInventoryUpload.js +15 -0
- data/webpack/ForemanInventoryUpload/ForemanInventoryUpload.test.js +10 -0
- data/webpack/ForemanInventoryUpload/ForemanInventoryUploadReducers.js +12 -0
- data/webpack/ForemanInventoryUpload/ForemanInventoryUploadSelectors.js +4 -0
- data/webpack/ForemanInventoryUpload/__snapshots__/ForemanInventoryUpload.test.js.snap +16 -0
- data/webpack/ForemanInventoryUpload/index.js +1 -0
- data/webpack/__mocks__/foremanReact/API.js +7 -0
- data/webpack/__mocks__/foremanReact/common/I18n.js +5 -0
- data/webpack/__mocks__/foremanReact/common/helpers.js +3 -0
- data/webpack/index.js +18 -0
- data/webpack/stories/ForemanInventoryUploadReducers.js +3 -0
- data/webpack/stories/configureStore.js +15 -0
- data/webpack/stories/decorators/index.js +1 -0
- data/webpack/stories/decorators/withCardsDecorator.js +14 -0
- data/webpack/stories/index.js +10 -0
- data/webpack/stories/index.scss +7 -0
- data/webpack/test_setup.js +6 -0
- metadata +205 -9
- data/app/controllers/foreman_inventory_upload/statuses_controller.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a633e9716013237bbbcce5cba1748fad264cea4b4b965e5f19bb0f0be8d41e4e
|
4
|
+
data.tar.gz: 58de7c1e9666e4373fb44db980bacfb4392131bfddbd31a86123de34b1d456bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 033077e27db0e59ec53895ab8038ff4da2c1cf8e223ebe7296dce00d7961e3d79edf5ac807b438e2eb0c71afb42a93bf9923d6aa1ce647a3df7323190c4dcf3d
|
7
|
+
data.tar.gz: ca759475503697dfe741a92b11d9beb8f8520056cb19aea59745d350103c56dded3f6641087b77448652bdfe06ead35c6916d6d356447bb8da31271699849eca
|
data/Rakefile
CHANGED
@@ -20,7 +20,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
20
20
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
21
|
end
|
22
22
|
|
23
|
-
APP_RAKEFILE = File.expand_path('
|
23
|
+
APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
|
24
24
|
|
25
25
|
Bundler::GemHelper.install_tasks
|
26
26
|
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module ForemanInventoryUpload
|
2
|
+
class AccountsController < ::ApplicationController
|
3
|
+
# override default "welcome screen behavior, since we don't have a model"
|
4
|
+
def welcome
|
5
|
+
true
|
6
|
+
end
|
7
|
+
|
8
|
+
def index
|
9
|
+
labels = Organization.all.pluck(:id, :name)
|
10
|
+
|
11
|
+
accounts = Hash[
|
12
|
+
labels.map do |id, label|
|
13
|
+
generate_report_status = status_for(id, ForemanInventoryUpload::Async::GenerateReportJob)
|
14
|
+
upload_report_status = status_for(id, ForemanInventoryUpload::Async::UploadReportJob)
|
15
|
+
|
16
|
+
[
|
17
|
+
id,
|
18
|
+
{
|
19
|
+
generate_report_status: generate_report_status,
|
20
|
+
upload_report_status: upload_report_status,
|
21
|
+
label: label,
|
22
|
+
},
|
23
|
+
]
|
24
|
+
end
|
25
|
+
]
|
26
|
+
|
27
|
+
render json: {
|
28
|
+
accounts: accounts,
|
29
|
+
}, status: :ok
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def status_for(label, job_class)
|
35
|
+
label = job_class.output_label(label)
|
36
|
+
ForemanInventoryUpload::Async::ProgressOutput.get(label)&.status
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -1,22 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ForemanInventoryUpload
|
2
4
|
class ReportsController < ::ApplicationController
|
3
5
|
def last
|
4
|
-
label = ForemanInventoryUpload::Async::GenerateReportJob.output_label(params[:
|
6
|
+
label = ForemanInventoryUpload::Async::GenerateReportJob.output_label(params[:organization_id])
|
5
7
|
output = ForemanInventoryUpload::Async::ProgressOutput.get(label)&.full_output
|
8
|
+
task_label = ForemanInventoryUpload::Async::GenerateAllReportsJob.singleton_job_name
|
9
|
+
scheduled = ForemanTasks::Task.where(
|
10
|
+
:label => task_label,
|
11
|
+
:state => 'scheduled'
|
12
|
+
).first&.start_at || nil
|
6
13
|
|
7
14
|
render json: {
|
8
|
-
output: output
|
15
|
+
output: output,
|
16
|
+
scheduled: scheduled,
|
9
17
|
}, status: :ok
|
10
18
|
end
|
11
19
|
|
12
20
|
def generate
|
13
|
-
|
21
|
+
organization_id = params[:organization_id]
|
14
22
|
|
15
|
-
|
16
|
-
ForemanInventoryUpload::Async::GenerateReportJob.perform_later(generated_file_name, portal_user)
|
23
|
+
ForemanInventoryUpload::Async::GenerateReportJob.perform_later(ForemanInventoryUpload.generated_reports_folder, organization_id)
|
17
24
|
|
18
25
|
render json: {
|
19
|
-
action_status: 'success'
|
26
|
+
action_status: 'success',
|
20
27
|
}, status: :ok
|
21
28
|
end
|
22
29
|
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
module ForemanInventoryUpload
|
2
2
|
class UploadsController < ::ApplicationController
|
3
3
|
def last
|
4
|
-
label = ForemanInventoryUpload::Async::UploadReportJob.output_label(params[:
|
4
|
+
label = ForemanInventoryUpload::Async::UploadReportJob.output_label(params[:organization_id])
|
5
5
|
output = ForemanInventoryUpload::Async::ProgressOutput.get(label)&.full_output
|
6
6
|
|
7
7
|
render json: {
|
8
|
-
output: output
|
8
|
+
output: output,
|
9
9
|
}, status: :ok
|
10
10
|
end
|
11
11
|
|
12
12
|
def download_file
|
13
|
-
filename =
|
14
|
-
path = Rails.root.join(ForemanInventoryUpload.uploads_folder
|
13
|
+
filename = ForemanInventoryUpload.facts_archive_name(params[:organization_id])
|
14
|
+
path = Rails.root.join(ForemanInventoryUpload.uploads_folder, filename)
|
15
15
|
unless File.exist? path
|
16
16
|
return throw_flash_error(
|
17
17
|
"Path doesn't exist: #{path}"
|
@@ -1,28 +1,39 @@
|
|
1
1
|
#! /bin/sh
|
2
2
|
|
3
3
|
DEST=<%= @upload_url %>
|
4
|
-
RH_USERNAME=<%= @rh_username %>
|
5
4
|
|
6
|
-
if [ -z "$
|
5
|
+
if [ -z "$FILES" ]
|
7
6
|
then
|
8
|
-
|
7
|
+
FILES=./*.tar.gz
|
9
8
|
fi
|
10
9
|
|
11
|
-
if [ -
|
10
|
+
if [ -n "$CER_PATH" ]
|
12
11
|
then
|
13
|
-
|
14
|
-
|
12
|
+
AUTH_KEY="--cert"
|
13
|
+
AUTH_VAL="$CER_PATH"
|
14
|
+
else
|
15
|
+
if [ -z "$RH_USERNAME" ]
|
16
|
+
then
|
17
|
+
IFS= read -rp "Enter username: " RH_USERNAME
|
18
|
+
fi
|
15
19
|
|
16
|
-
if [ -z "$
|
17
|
-
then
|
18
|
-
|
20
|
+
if [ -z "$RH_PASSWORD" ]
|
21
|
+
then
|
22
|
+
IFS= read -rsp "Enter password: " RH_PASSWORD
|
23
|
+
fi
|
24
|
+
|
25
|
+
AUTH_KEY="-u"
|
26
|
+
AUTH_VAL="\"$RH_USERNAME\":\"$RH_PASSWORD\""
|
19
27
|
fi
|
20
28
|
|
29
|
+
# /tmp/a b/x.pem
|
30
|
+
# curl --cert /tmp/a\ b/x.pem
|
31
|
+
|
21
32
|
mkdir -p done
|
22
33
|
|
23
34
|
for f in $FILES
|
24
35
|
do
|
25
|
-
curl -k -vvv -# --fail -F "file=@$f;type=application/vnd.redhat.qpc.tar+tgz" $DEST
|
36
|
+
curl -k -vvv -# --fail -F "file=@$f;type=application/vnd.redhat.qpc.tar+tgz" $DEST "$AUTH_KEY" "$AUTH_VAL"
|
26
37
|
if [ $? -eq 0 ]; then
|
27
38
|
mv $f done/
|
28
39
|
echo "Done: $f"
|
data/config/routes.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
namespace :foreman_inventory_upload do
|
3
3
|
get 'index', to: 'react#index'
|
4
|
-
get ':
|
5
|
-
post ':
|
6
|
-
get ':
|
7
|
-
get ':
|
8
|
-
get '
|
4
|
+
get ':organization_id/reports/last', to: 'reports#last', constraints: { organization_id: %r{[^\/]+} }
|
5
|
+
post ':organization_id/reports', to: 'reports#generate', constraints: { organization_id: %r{[^\/]+} }
|
6
|
+
get ':organization_id/uploads/last', to: 'uploads#last', constraints: { organization_id: %r{[^\/]+} }
|
7
|
+
get ':organization_id/uploads/file', to: 'uploads#download_file', constraints: { organization_id: %r{[^\/]+} }
|
8
|
+
get 'accounts', to: 'accounts#index'
|
9
9
|
end
|
10
10
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ForemanInventoryUpload
|
2
|
+
module Async
|
3
|
+
class GenerateAllReportsJob < ::ApplicationJob
|
4
|
+
def perform
|
5
|
+
organizations = Organization.unscoped.all
|
6
|
+
|
7
|
+
organizations.map do |organization|
|
8
|
+
GenerateReportJob.perform_later(ForemanInventoryUpload.generated_reports_folder, organization.id)
|
9
|
+
end
|
10
|
+
ensure
|
11
|
+
self.class.set(:wait => 24.hours).perform_later
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.singleton_job_name
|
15
|
+
name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,17 +1,21 @@
|
|
1
1
|
module ForemanInventoryUpload
|
2
2
|
module Async
|
3
3
|
class GenerateReportJob < ShellProcess
|
4
|
-
def self.output_label(
|
5
|
-
"report_for_#{
|
4
|
+
def self.output_label(label)
|
5
|
+
"report_for_#{label}"
|
6
6
|
end
|
7
7
|
|
8
|
-
def perform(
|
9
|
-
@
|
10
|
-
@
|
8
|
+
def perform(base_folder, organization)
|
9
|
+
@base_folder = base_folder
|
10
|
+
@organization = organization
|
11
11
|
|
12
|
-
super(GenerateReportJob.output_label(
|
12
|
+
super(GenerateReportJob.output_label(organization))
|
13
13
|
|
14
|
-
QueueForUploadJob.perform_later(
|
14
|
+
QueueForUploadJob.perform_later(
|
15
|
+
base_folder,
|
16
|
+
ForemanInventoryUpload.facts_archive_name(organization),
|
17
|
+
organization
|
18
|
+
)
|
15
19
|
end
|
16
20
|
|
17
21
|
def command
|
@@ -20,8 +24,8 @@ module ForemanInventoryUpload
|
|
20
24
|
|
21
25
|
def env
|
22
26
|
super.merge(
|
23
|
-
'target' => @
|
24
|
-
'
|
27
|
+
'target' => @base_folder,
|
28
|
+
'organization_id' => @organization
|
25
29
|
)
|
26
30
|
end
|
27
31
|
end
|
@@ -1,21 +1,22 @@
|
|
1
1
|
module ForemanInventoryUpload
|
2
2
|
module Async
|
3
3
|
class QueueForUploadJob < ::ApplicationJob
|
4
|
-
def perform(report_file,
|
5
|
-
@
|
4
|
+
def perform(base_folder, report_file, organization_id)
|
5
|
+
@base_folder = base_folder
|
6
|
+
@report_file = report_file
|
6
7
|
logger.debug('Ensuring objects')
|
7
8
|
ensure_ouput_folder
|
8
9
|
ensure_output_script
|
9
10
|
logger.debug("Copying #{report_file} to #{uploads_folder}")
|
10
|
-
enqueued_file_name = File.join(uploads_folder,
|
11
|
-
FileUtils.mv(report_file, enqueued_file_name)
|
11
|
+
enqueued_file_name = File.join(uploads_folder, report_file)
|
12
|
+
FileUtils.mv(File.join(base_folder, report_file), enqueued_file_name)
|
12
13
|
logger.debug("Done copying #{report_file} to #{enqueued_file_name}")
|
13
14
|
|
14
|
-
UploadReportJob.perform_later(enqueued_file_name,
|
15
|
+
UploadReportJob.perform_later(enqueued_file_name, organization_id)
|
15
16
|
end
|
16
17
|
|
17
18
|
def uploads_folder
|
18
|
-
@uploads_folder ||= ForemanInventoryUpload.uploads_folder
|
19
|
+
@uploads_folder ||= ForemanInventoryUpload.uploads_folder
|
19
20
|
end
|
20
21
|
|
21
22
|
def script_file
|
@@ -29,17 +30,11 @@ module ForemanInventoryUpload
|
|
29
30
|
def ensure_output_script
|
30
31
|
return if File.exist?(script_file)
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
variables: {
|
38
|
-
upload_url: ForemanInventoryUpload.upload_url,
|
39
|
-
rh_username: @portal_user
|
40
|
-
}
|
41
|
-
)
|
42
|
-
script_source = Foreman::Renderer.render(template_src, scope)
|
33
|
+
script_source_file = File.join(ForemanInventoryUpload::Engine.root, 'app/views/scripts/uploader.sh.erb')
|
34
|
+
|
35
|
+
script_source = File.read(script_source_file)
|
36
|
+
script_source.gsub!('<%= @upload_url %>', ForemanInventoryUpload.upload_url)
|
37
|
+
|
43
38
|
File.write(script_file, script_source)
|
44
39
|
FileUtils.chmod('+x', script_file)
|
45
40
|
end
|
@@ -1,15 +1,23 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
1
3
|
module ForemanInventoryUpload
|
2
4
|
module Async
|
3
5
|
class UploadReportJob < ShellProcess
|
4
|
-
def self.output_label(
|
5
|
-
"upload_for_#{
|
6
|
+
def self.output_label(label)
|
7
|
+
"upload_for_#{label}"
|
6
8
|
end
|
7
9
|
|
8
|
-
def perform(filename,
|
9
|
-
@portal_user = portal_user
|
10
|
+
def perform(filename, organization_id)
|
10
11
|
@filename = filename
|
12
|
+
@organization = Organization.find(organization_id)
|
11
13
|
|
12
|
-
|
14
|
+
Tempfile.create([@organization.name, '.pem']) do |cer_file|
|
15
|
+
cer_file.write(rh_credentials[:cert])
|
16
|
+
cer_file.write(rh_credentials[:key])
|
17
|
+
cer_file.flush
|
18
|
+
@cer_path = cer_file.path
|
19
|
+
super(UploadReportJob.output_label(organization_id))
|
20
|
+
end
|
13
21
|
end
|
14
22
|
|
15
23
|
def command
|
@@ -18,22 +26,19 @@ module ForemanInventoryUpload
|
|
18
26
|
|
19
27
|
def env
|
20
28
|
super.merge(
|
21
|
-
'
|
22
|
-
'
|
23
|
-
'FILES' => @filename
|
29
|
+
'FILES' => @filename,
|
30
|
+
'CER_PATH' => @cer_path
|
24
31
|
)
|
25
32
|
end
|
26
33
|
|
27
34
|
def rh_credentials
|
28
|
-
@rh_credentials ||=
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
def rh_password
|
36
|
-
rh_credentials.portal_password
|
35
|
+
@rh_credentials ||= begin
|
36
|
+
candlepin_id_certificate = @organization.owner_details['upstreamConsumer']['idCert']
|
37
|
+
{
|
38
|
+
cert: candlepin_id_certificate['cert'],
|
39
|
+
key: candlepin_id_certificate['key'],
|
40
|
+
}
|
41
|
+
end
|
37
42
|
end
|
38
43
|
end
|
39
44
|
end
|
@@ -11,6 +11,8 @@ module ForemanInventoryUpload
|
|
11
11
|
config.autoload_paths += Dir["#{config.root}/app/overrides"]
|
12
12
|
config.autoload_paths += Dir["#{config.root}/lib"]
|
13
13
|
|
14
|
+
config.eager_load_paths += Dir["#{config.root}/lib"]
|
15
|
+
|
14
16
|
# Add any db migrations
|
15
17
|
initializer 'foreman_inventory_upload.load_app_instance_data' do |app|
|
16
18
|
ForemanInventoryUpload::Engine.paths['db/migrate'].existent.each do |path|
|
@@ -32,7 +34,15 @@ module ForemanInventoryUpload
|
|
32
34
|
|
33
35
|
# Adding a sub menu after hosts menu
|
34
36
|
sub_menu :top_menu, :foreman_inventory_upload, :caption => N_('RH Inventory'), :icon => 'fa fa-cloud-upload' do
|
35
|
-
menu :top_menu, :level1, :caption => N_('Manage'), :url_hash => { controller: :'foreman_inventory_upload/react', :action
|
37
|
+
menu :top_menu, :level1, :caption => N_('Manage'), :url_hash => { controller: :'foreman_inventory_upload/react', :action => :index}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
initializer "foreman_inventory_upload.set_dynflow.config.on_init", :before => :finisher_hook do |_app|
|
43
|
+
unless Rails.env.test?
|
44
|
+
ForemanTasks.dynflow.config.on_init do |world|
|
45
|
+
ForemanInventoryUpload::Async::GenerateAllReportsJob.spawn_if_missing(world)
|
36
46
|
end
|
37
47
|
end
|
38
48
|
end
|
@@ -6,10 +6,10 @@ module ForemanInventoryUpload
|
|
6
6
|
@logger = logger
|
7
7
|
end
|
8
8
|
|
9
|
-
def render(
|
9
|
+
def render(organization:)
|
10
10
|
Dir.mktmpdir do |tmpdir|
|
11
11
|
@logger.info "Started generating hosts report in #{tmpdir}"
|
12
|
-
host_batches = ForemanInventoryUpload::Generators::Queries.
|
12
|
+
host_batches = ForemanInventoryUpload::Generators::Queries.for_org(organization)
|
13
13
|
File.open(File.join(tmpdir, 'metadata.json'), 'w') do |metadata_out|
|
14
14
|
metadata_generator = ForemanInventoryUpload::Generators::Metadata.new(metadata_out)
|
15
15
|
metadata_generator.render do |inner_generator|
|
@@ -16,7 +16,8 @@ module ForemanInventoryUpload
|
|
16
16
|
'dmi::bios::relase_date',
|
17
17
|
'distribution::name',
|
18
18
|
'uname::release',
|
19
|
-
'lscpu::flags'
|
19
|
+
'lscpu::flags',
|
20
|
+
'distribution::version',
|
20
21
|
]).pluck(:name, :id)
|
21
22
|
]
|
22
23
|
end
|
@@ -31,21 +32,29 @@ module ForemanInventoryUpload
|
|
31
32
|
:installed_packages,
|
32
33
|
:content_facet,
|
33
34
|
:host_statuses,
|
34
|
-
subscription_facet:
|
35
|
+
subscription_facet: [:pools, :installed_products, :hypervisor_host]
|
35
36
|
)
|
36
37
|
.merge(fact_values)
|
37
38
|
end
|
38
39
|
|
39
40
|
def self.for_report(portal_user)
|
40
|
-
org_ids =
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
41
|
+
org_ids = organizations_for_user(portal_user).pluck(:id)
|
42
|
+
for_slice(Host.unscoped.where(organization_id: org_ids)).in_batches(of: 1_000)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.for_org(organization_id)
|
46
|
+
for_slice(Host.unscoped.where(organization_id: organization_id)).in_batches(of: 1_000)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.organizations_for_user(portal_user)
|
50
|
+
Organization
|
51
|
+
.joins(:telemetry_configuration)
|
52
|
+
.where(
|
53
|
+
redhat_access_telemetry_configurations: {
|
54
|
+
portal_user: portal_user,
|
55
|
+
enable_telemetry: true,
|
56
|
+
}
|
57
|
+
)
|
49
58
|
end
|
50
59
|
end
|
51
60
|
end
|
@@ -23,14 +23,14 @@ module ForemanInventoryUpload
|
|
23
23
|
first = true
|
24
24
|
hosts_batch.each do |host|
|
25
25
|
@stream.comma unless first
|
26
|
-
first = false
|
27
|
-
report_host(host)
|
26
|
+
first = false if report_host(host)
|
28
27
|
end
|
29
28
|
end
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
33
32
|
def report_host(host)
|
33
|
+
return nil unless host&.subscription_facet&.pools&.first
|
34
34
|
@stream.object do
|
35
35
|
@stream.simple_field('display_name', host.name)
|
36
36
|
@stream.simple_field('fqdn', host.fqdn)
|
@@ -49,9 +49,17 @@ module ForemanInventoryUpload
|
|
49
49
|
@stream.stringify_value(nic.mac) if nic.mac
|
50
50
|
end.compact.join(', '))
|
51
51
|
end
|
52
|
-
@stream.object_field('system_profile'
|
52
|
+
@stream.object_field('system_profile') do
|
53
53
|
report_system_profile(host)
|
54
54
|
end
|
55
|
+
@stream.array_field('facts', :last) do
|
56
|
+
@stream.object do
|
57
|
+
@stream.simple_field('namespace', 'satellite')
|
58
|
+
@stream.object_field('facts', :last) do
|
59
|
+
report_satellite_facts(host)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
55
63
|
end
|
56
64
|
end
|
57
65
|
|
@@ -67,7 +75,7 @@ module ForemanInventoryUpload
|
|
67
75
|
'ipv6_addresses': [nic.ip6].compact,
|
68
76
|
'mtu': nic.mtu,
|
69
77
|
'mac_address': nic.mac,
|
70
|
-
'name': nic.identifier
|
78
|
+
'name': nic.identifier,
|
71
79
|
}.compact.to_json
|
72
80
|
end.join(', '))
|
73
81
|
end
|
@@ -92,7 +100,7 @@ module ForemanInventoryUpload
|
|
92
100
|
@stream.raw(installed_products.map do |product|
|
93
101
|
{
|
94
102
|
'name': product.name,
|
95
|
-
'id': product.cp_product_id
|
103
|
+
'id': product.cp_product_id,
|
96
104
|
}.to_json
|
97
105
|
end.join(', '))
|
98
106
|
end
|
@@ -106,6 +114,19 @@ module ForemanInventoryUpload
|
|
106
114
|
end
|
107
115
|
end
|
108
116
|
|
117
|
+
def report_satellite_facts(host)
|
118
|
+
@stream.simple_field('virtual_host_name', host.subscription_facet.hypervisor_host&.name)
|
119
|
+
@stream.simple_field('virtual_host_uuid', host.subscription_facet.hypervisor_host&.subscription_facet&.uuid)
|
120
|
+
if defined?(ForemanThemeSatellite)
|
121
|
+
@stream.simple_field('satellite_version', ForemanThemeSatellite::SATELLITE_VERSION)
|
122
|
+
end
|
123
|
+
@stream.simple_field('system_purpose_usage', host.subscription_facet.purpose_usage)
|
124
|
+
@stream.simple_field('system_purpose_role', host.subscription_facet.purpose_role)
|
125
|
+
@stream.simple_field('distribution_version', fact_value(host, 'distribution::version'))
|
126
|
+
@stream.simple_field('satellite_instance_id', Foreman.respond_to?(:instance_id) ? Foreman.instance_id : nil)
|
127
|
+
@stream.simple_field('organization_id', host.organization_id, :last)
|
128
|
+
end
|
129
|
+
|
109
130
|
def fact_value(host, fact_name)
|
110
131
|
value_record = host.fact_values.find do |fact_value|
|
111
132
|
fact_value.fact_name_id == ForemanInventoryUpload::Generators::Queries.fact_names[fact_name]
|
@@ -11,16 +11,20 @@ module ForemanInventoryUpload
|
|
11
11
|
)
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.uploads_folder
|
15
|
-
@
|
16
|
-
|
17
|
-
|
14
|
+
def self.uploads_folder
|
15
|
+
@uploads_folder ||= ensure_folder(
|
16
|
+
File.join(
|
17
|
+
ForemanInventoryUpload.base_folder,
|
18
|
+
'uploads/'
|
19
|
+
)
|
20
|
+
)
|
21
|
+
end
|
18
22
|
|
19
|
-
|
23
|
+
def self.generated_reports_folder
|
24
|
+
@generated_reports_folder ||= ensure_folder(
|
20
25
|
File.join(
|
21
26
|
ForemanInventoryUpload.base_folder,
|
22
|
-
'
|
23
|
-
"#{group}/"
|
27
|
+
'generated_reports/'
|
24
28
|
)
|
25
29
|
)
|
26
30
|
end
|
@@ -33,12 +37,13 @@ module ForemanInventoryUpload
|
|
33
37
|
'uploader.sh'
|
34
38
|
end
|
35
39
|
|
36
|
-
def self.facts_archive_name
|
37
|
-
|
40
|
+
def self.facts_archive_name(organization)
|
41
|
+
"report_for_#{organization}.tar.gz"
|
38
42
|
end
|
39
43
|
|
40
44
|
def self.upload_url
|
41
|
-
'https://ci.cloud.
|
45
|
+
# for testing set ENV to 'https://ci.cloud.redhat.com/api/ingress/v1/upload'
|
46
|
+
@upload_url ||= ENV['SATELLITE_INVENTORY_UPLOAD_URL'] || 'https://cloud.redhat.com/api/ingress/v1/upload'
|
42
47
|
end
|
43
48
|
|
44
49
|
def self.ensure_folder(folder)
|
data/lib/tasks/generator.rake
CHANGED
@@ -4,12 +4,26 @@ namespace :foreman_inventory_upload do
|
|
4
4
|
namespace :report do
|
5
5
|
desc 'Generate inventory report to be sent to Red Hat cloud'
|
6
6
|
task generate: :environment do
|
7
|
-
|
8
|
-
|
7
|
+
portal_user = ENV['portal_user']
|
8
|
+
organizations = [ENV['organization_id']]
|
9
|
+
base_folder = ENV['target'] || Dir.pwd
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
unless portal_user || organizations.empty?
|
12
|
+
puts "Must specify either portal_user or organization_id"
|
13
|
+
end
|
14
|
+
|
15
|
+
if portal_user
|
16
|
+
puts "Generating report for all organizations associated with #{portal_user}"
|
17
|
+
base_folder = File.join(base_folder, portal_user)
|
18
|
+
organizations = ForemanInventoryUpload::Generators::Queries.organizations_for_user(portal_user).pluck(:id)
|
19
|
+
end
|
20
|
+
|
21
|
+
organizations.each do |organization|
|
22
|
+
target = File.join(base_folder, ForemanInventoryUpload.facts_archive_name(organization))
|
23
|
+
archived_report_generator = ForemanInventoryUpload::Generators::ArchivedReport.new(target, Logger.new(STDOUT))
|
24
|
+
archived_report_generator.render(organization: organization)
|
25
|
+
puts "Successfully generated #{target} for organization id #{organization}"
|
26
|
+
end
|
13
27
|
end
|
14
28
|
end
|
15
29
|
end
|