foreman_rh_cloud 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +619 -0
- data/README.md +38 -0
- data/Rakefile +47 -0
- data/app/controllers/foreman_inventory_upload/accounts_controller.rb +39 -0
- data/app/controllers/foreman_inventory_upload/react_controller.rb +7 -0
- data/app/controllers/foreman_inventory_upload/reports_controller.rb +30 -0
- data/app/controllers/foreman_inventory_upload/uploads_controller.rb +31 -0
- data/app/helpers/foreman_inventory_upload_helper.rb +13 -0
- data/app/views/foreman_inventory_upload/layouts/react.html.erb +16 -0
- data/config/routes.rb +10 -0
- data/lib/foreman_inventory_upload.rb +51 -0
- data/lib/foreman_inventory_upload/async/generate_all_reports_job.rb +19 -0
- data/lib/foreman_inventory_upload/async/generate_report_job.rb +37 -0
- data/lib/foreman_inventory_upload/async/progress_output.rb +61 -0
- data/lib/foreman_inventory_upload/async/queue_for_upload_job.rb +47 -0
- data/lib/foreman_inventory_upload/async/shell_process.rb +36 -0
- data/lib/foreman_inventory_upload/async/upload_report_job.rb +58 -0
- data/lib/foreman_inventory_upload/generators/archived_report.rb +53 -0
- data/lib/foreman_inventory_upload/generators/fact_helpers.rb +18 -0
- data/lib/foreman_inventory_upload/generators/json_stream.rb +55 -0
- data/lib/foreman_inventory_upload/generators/metadata.rb +36 -0
- data/lib/foreman_inventory_upload/generators/queries.rb +61 -0
- data/lib/foreman_inventory_upload/generators/slice.rb +147 -0
- data/lib/foreman_inventory_upload/scripts/uploader.sh.erb +44 -0
- data/lib/foreman_rh_cloud.rb +4 -0
- data/lib/foreman_rh_cloud/engine.rb +62 -0
- data/lib/foreman_rh_cloud/version.rb +3 -0
- data/lib/tasks/foreman_rh_cloud_tasks.rake +37 -0
- data/lib/tasks/generator.rake +29 -0
- data/locale/Makefile +60 -0
- data/locale/en/foreman_rh_cloud.po +19 -0
- data/locale/foreman_rh_cloud.pot +19 -0
- data/locale/gemspec.rb +2 -0
- data/package.json +125 -0
- data/test/controllers/accounts_controller_test.rb +25 -0
- data/test/controllers/reports_controller_test.rb +21 -0
- data/test/controllers/uploads_controller_test.rb +21 -0
- data/test/factories/inventory_upload_factories.rb +88 -0
- data/test/test_plugin_helper.rb +26 -0
- data/test/unit/archived_report_generator_test.rb +61 -0
- data/test/unit/metadata_generator_test.rb +40 -0
- data/test/unit/shell_process_job_test.rb +27 -0
- data/test/unit/slice_generator_test.rb +177 -0
- 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 +145 -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 +35 -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 +18 -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 +53 -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 +47 -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 +43 -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 +318 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
module ForemanInventoryUpload
|
4
|
+
module Async
|
5
|
+
class ShellProcess < ::ApplicationJob
|
6
|
+
def perform(instance_label)
|
7
|
+
klass_name = self.class.name
|
8
|
+
logger.debug("Starting #{klass_name} with label #{instance_label}")
|
9
|
+
progress_output = ProgressOutput.register(instance_label)
|
10
|
+
Open3.popen2e(env, command) do |_stdin, stdout_stderr, wait_thread|
|
11
|
+
progress_output.status = "Running in pid #{wait_thread.pid}"
|
12
|
+
|
13
|
+
stdout_stderr.each do |out_line|
|
14
|
+
progress_output.write_line(out_line)
|
15
|
+
end
|
16
|
+
|
17
|
+
progress_output.status = wait_thread.value.to_s
|
18
|
+
end
|
19
|
+
logger.debug("Finished job #{klass_name} with label #{instance_label}")
|
20
|
+
ensure
|
21
|
+
progress_output.close
|
22
|
+
end
|
23
|
+
|
24
|
+
def command
|
25
|
+
end
|
26
|
+
|
27
|
+
def env
|
28
|
+
{}
|
29
|
+
end
|
30
|
+
|
31
|
+
def logger
|
32
|
+
Foreman::Logging.logger('background')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
module ForemanInventoryUpload
|
4
|
+
module Async
|
5
|
+
class UploadReportJob < ShellProcess
|
6
|
+
def self.output_label(label)
|
7
|
+
"upload_for_#{label}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def perform(filename, organization_id)
|
11
|
+
@filename = filename
|
12
|
+
@organization = Organization.find(organization_id)
|
13
|
+
|
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
|
21
|
+
end
|
22
|
+
|
23
|
+
def command
|
24
|
+
File.join(File.dirname(@filename), ForemanInventoryUpload.upload_script_file)
|
25
|
+
end
|
26
|
+
|
27
|
+
def env
|
28
|
+
env_vars = super.merge(
|
29
|
+
'FILES' => @filename,
|
30
|
+
'CER_PATH' => @cer_path
|
31
|
+
)
|
32
|
+
if http_proxy_string
|
33
|
+
env_vars['http_proxy'] = http_proxy_string
|
34
|
+
env_vars['https_proxy'] = http_proxy_string
|
35
|
+
end
|
36
|
+
env_vars
|
37
|
+
end
|
38
|
+
|
39
|
+
def http_proxy_string
|
40
|
+
@http_proxy_string ||= begin
|
41
|
+
if Setting[:content_default_http_proxy]
|
42
|
+
HttpProxy.unscoped.find_by(name: Setting[:content_default_http_proxy])&.full_url
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def rh_credentials
|
48
|
+
@rh_credentials ||= begin
|
49
|
+
candlepin_id_certificate = @organization.owner_details['upstreamConsumer']['idCert']
|
50
|
+
{
|
51
|
+
cert: candlepin_id_certificate['cert'],
|
52
|
+
key: candlepin_id_certificate['key'],
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module ForemanInventoryUpload
|
2
|
+
module Generators
|
3
|
+
class ArchivedReport
|
4
|
+
def initialize(target, logger = Rails.logger)
|
5
|
+
@target = target
|
6
|
+
@logger = logger
|
7
|
+
end
|
8
|
+
|
9
|
+
def render(organization:)
|
10
|
+
Dir.mktmpdir do |tmpdir|
|
11
|
+
@logger.info "Started generating hosts report in #{tmpdir}"
|
12
|
+
host_batches = ForemanInventoryUpload::Generators::Queries.for_org(organization)
|
13
|
+
File.open(File.join(tmpdir, 'metadata.json'), 'w') do |metadata_out|
|
14
|
+
metadata_generator = ForemanInventoryUpload::Generators::Metadata.new(metadata_out)
|
15
|
+
metadata_generator.render do |inner_generator|
|
16
|
+
first = true
|
17
|
+
host_batches.each do |hosts_batch|
|
18
|
+
slice_id = Foreman.uuid
|
19
|
+
hosts_count = hosts_batch.count
|
20
|
+
@logger.info "Adding slice #{slice_id} with #{hosts_count} hosts"
|
21
|
+
generate_slice(tmpdir, slice_id, hosts_batch)
|
22
|
+
inner_generator.add_slice(slice_id, hosts_count, first)
|
23
|
+
first = false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
@logger.info 'Report generation finished'
|
28
|
+
|
29
|
+
@logger.info 'Archiving generated report'
|
30
|
+
# success = system('tar', '-zcvf', @target, '-C', tmpdir, '.')
|
31
|
+
Open3.popen2e('tar', '-zcvf', @target, '-C', tmpdir, '.') do |_in, out, wait_thr|
|
32
|
+
@logger.info("tar: #{out.read}")
|
33
|
+
|
34
|
+
if wait_thr.value.success?
|
35
|
+
@logger.info 'Report archived successfully'
|
36
|
+
else
|
37
|
+
@logger.info "Tar command failed: #{$CHILD_STATUS}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def generate_slice(tmpdir, slice_id, hosts_batch)
|
46
|
+
File.open(File.join(tmpdir, "#{slice_id}.json"), 'w') do |slice_out|
|
47
|
+
slice_generator = ForemanInventoryUpload::Generators::Slice.new(hosts_batch, slice_out, slice_id)
|
48
|
+
slice_generator.render
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ForemanInventoryUpload
|
2
|
+
module Generators
|
3
|
+
module FactHelpers
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
def fact_value(host, fact_name)
|
7
|
+
value_record = host.fact_values.find do |fact_value|
|
8
|
+
fact_value.fact_name_id == ForemanInventoryUpload::Generators::Queries.fact_names[fact_name]
|
9
|
+
end
|
10
|
+
value_record&.value
|
11
|
+
end
|
12
|
+
|
13
|
+
def kilobytes_to_bytes(kilobytes)
|
14
|
+
kilobytes * 1024
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module ForemanInventoryUpload
|
2
|
+
module Generators
|
3
|
+
class JsonStream
|
4
|
+
attr_reader :out
|
5
|
+
def initialize(out)
|
6
|
+
@out = out
|
7
|
+
end
|
8
|
+
|
9
|
+
def array
|
10
|
+
@out << '['
|
11
|
+
yield
|
12
|
+
@out << ']'
|
13
|
+
end
|
14
|
+
|
15
|
+
def object
|
16
|
+
@out << '{'
|
17
|
+
yield
|
18
|
+
@out << '}'
|
19
|
+
end
|
20
|
+
|
21
|
+
def comma
|
22
|
+
@out << ', '
|
23
|
+
end
|
24
|
+
|
25
|
+
def raw(string)
|
26
|
+
@out << string
|
27
|
+
end
|
28
|
+
|
29
|
+
def simple_field(name, value, last = false)
|
30
|
+
@out << "\"#{name}\": #{stringify_value(value)}#{last ? '' : ','}" unless value.nil?
|
31
|
+
end
|
32
|
+
|
33
|
+
def array_field(name, last = false, &block)
|
34
|
+
@out << "\"#{name}\": "
|
35
|
+
array(&block)
|
36
|
+
@out << ',' unless last
|
37
|
+
end
|
38
|
+
|
39
|
+
def object_field(name, last = false, &block)
|
40
|
+
@out << "\"#{name}\": "
|
41
|
+
object(&block)
|
42
|
+
@out << ',' unless last
|
43
|
+
end
|
44
|
+
|
45
|
+
def stringify_value(value)
|
46
|
+
return value if value.is_a?(Integer)
|
47
|
+
return value if value.is_a?(TrueClass)
|
48
|
+
return value if value.is_a?(FalseClass)
|
49
|
+
return value.to_json if value.is_a?(Hash)
|
50
|
+
|
51
|
+
"\"#{value}\""
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ForemanInventoryUpload
|
2
|
+
module Generators
|
3
|
+
class Metadata
|
4
|
+
def initialize(output = [])
|
5
|
+
@stream = JsonStream.new(output)
|
6
|
+
end
|
7
|
+
|
8
|
+
def add_slice(slice_id, hosts_count, first)
|
9
|
+
@stream.comma unless first
|
10
|
+
|
11
|
+
@stream.object_field(slice_id, :last) do
|
12
|
+
@stream.simple_field('number_hosts', hosts_count, :last)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def render(metadata = nil, &block)
|
17
|
+
render_report(metadata, &block)
|
18
|
+
@stream.out
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def render_report(metadata)
|
24
|
+
@stream.object do
|
25
|
+
@stream.simple_field('report_id', Foreman.uuid)
|
26
|
+
@stream.simple_field('host_inventory_api_version', '1.0')
|
27
|
+
@stream.simple_field('source', 'Satellite')
|
28
|
+
@stream.simple_field('source_metadata', metadata)
|
29
|
+
@stream.object_field('report_slices', :last) do
|
30
|
+
yield(self)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module ForemanInventoryUpload
|
2
|
+
module Generators
|
3
|
+
class Queries
|
4
|
+
def self.fact_names
|
5
|
+
@fact_names ||= Hash[
|
6
|
+
Katello::RhsmFactName.where(name:
|
7
|
+
[
|
8
|
+
'dmi::system::uuid',
|
9
|
+
'virt::uuid',
|
10
|
+
'cpu::cpu(s)',
|
11
|
+
'cpu::cpu_socket(s)',
|
12
|
+
'cpu::core(s)_per_socket',
|
13
|
+
'memory::memtotal',
|
14
|
+
'dmi::bios::vendor',
|
15
|
+
'dmi::bios::version',
|
16
|
+
'dmi::bios::relase_date',
|
17
|
+
'distribution::name',
|
18
|
+
'uname::release',
|
19
|
+
'lscpu::flags',
|
20
|
+
'distribution::version',
|
21
|
+
]).pluck(:name, :id)
|
22
|
+
]
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.for_slice(base)
|
26
|
+
fact_values = FactValue.where(fact_name_id: fact_names.values)
|
27
|
+
base
|
28
|
+
.joins(:subscription_facet)
|
29
|
+
.eager_load(:fact_values)
|
30
|
+
.preload(
|
31
|
+
:interfaces,
|
32
|
+
:installed_packages,
|
33
|
+
:content_facet,
|
34
|
+
:host_statuses,
|
35
|
+
subscription_facet: [:pools, :installed_products, :hypervisor_host]
|
36
|
+
)
|
37
|
+
.merge(fact_values)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.for_report(portal_user)
|
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
|
+
)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
module ForemanInventoryUpload
|
2
|
+
module Generators
|
3
|
+
class Slice
|
4
|
+
include FactHelpers
|
5
|
+
|
6
|
+
attr_accessor :slice_id
|
7
|
+
|
8
|
+
def initialize(hosts, output = [], slice_id = Foreman.uuid)
|
9
|
+
@stream = JsonStream.new(output)
|
10
|
+
@hosts = hosts
|
11
|
+
@slice_id = slice_id
|
12
|
+
end
|
13
|
+
|
14
|
+
def render
|
15
|
+
report_slice(@hosts)
|
16
|
+
@stream.out
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def report_slice(hosts_batch)
|
22
|
+
@stream.object do
|
23
|
+
@stream.simple_field('report_slice_id', @slice_id)
|
24
|
+
@stream.array_field('hosts', :last) do
|
25
|
+
first = true
|
26
|
+
hosts_batch.each do |host|
|
27
|
+
next unless host&.subscription_facet&.pools&.first
|
28
|
+
@stream.comma unless first
|
29
|
+
first = false if report_host(host)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def report_host(host)
|
36
|
+
@stream.object do
|
37
|
+
@stream.simple_field('display_name', host.name)
|
38
|
+
@stream.simple_field('fqdn', host.fqdn)
|
39
|
+
@stream.simple_field('account', host.subscription_facet.pools.first.account_number.to_s)
|
40
|
+
@stream.simple_field('subscription_manager_id', host.subscription_facet.uuid)
|
41
|
+
@stream.simple_field('satellite_id', host.subscription_facet.uuid)
|
42
|
+
@stream.simple_field('bios_uuid', fact_value(host, 'dmi::system::uuid'))
|
43
|
+
@stream.simple_field('vm_uuid', fact_value(host, 'virt::uuid'))
|
44
|
+
@stream.array_field('ip_addresses') do
|
45
|
+
@stream.raw(host.interfaces.map do |nic|
|
46
|
+
@stream.stringify_value(nic.ip) if nic.ip
|
47
|
+
end.compact.join(', '))
|
48
|
+
end
|
49
|
+
@stream.array_field('mac_addresses') do
|
50
|
+
@stream.raw(host.interfaces.map do |nic|
|
51
|
+
@stream.stringify_value(nic.mac) if nic.mac
|
52
|
+
end.compact.join(', '))
|
53
|
+
end
|
54
|
+
@stream.object_field('system_profile') do
|
55
|
+
report_system_profile(host)
|
56
|
+
end
|
57
|
+
@stream.array_field('facts') do
|
58
|
+
@stream.object do
|
59
|
+
@stream.simple_field('namespace', 'satellite')
|
60
|
+
@stream.object_field('facts', :last) do
|
61
|
+
report_satellite_facts(host)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
@stream.array_field('tags', :last) do
|
67
|
+
report_tag('satellite', 'satellite_instance_id', Foreman.instance_id) if Foreman.respond_to?(:instance_id)
|
68
|
+
report_tag('satellite', 'organization_id', host.organization_id, :last)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def report_tag(namespace, key, value, last = nil)
|
74
|
+
@stream.object do
|
75
|
+
@stream.simple_field('namespace', namespace)
|
76
|
+
@stream.simple_field('key', key)
|
77
|
+
@stream.simple_field('value', value, :last)
|
78
|
+
end
|
79
|
+
@stream.comma unless last
|
80
|
+
end
|
81
|
+
|
82
|
+
def report_system_profile(host)
|
83
|
+
@stream.simple_field('number_of_cpus', fact_value(host, 'cpu::cpu(s)').to_i)
|
84
|
+
@stream.simple_field('number_of_sockets', fact_value(host, 'cpu::cpu_socket(s)').to_i)
|
85
|
+
@stream.simple_field('cores_per_socket', fact_value(host, 'cpu::core(s)_per_socket').to_i)
|
86
|
+
@stream.simple_field('system_memory_bytes', kilobytes_to_bytes(fact_value(host, 'memory::memtotal').to_i))
|
87
|
+
@stream.array_field('network_interfaces') do
|
88
|
+
@stream.raw(host.interfaces.map do |nic|
|
89
|
+
{
|
90
|
+
'ipv4_addresses': [nic.ip].compact,
|
91
|
+
'ipv6_addresses': [nic.ip6].compact,
|
92
|
+
'mtu': nic.try(:mtu),
|
93
|
+
'mac_address': nic.mac,
|
94
|
+
'name': nic.identifier,
|
95
|
+
}.compact.to_json
|
96
|
+
end.join(', '))
|
97
|
+
end
|
98
|
+
@stream.simple_field('bios_vendor', fact_value(host, 'dmi::bios::vendor'))
|
99
|
+
@stream.simple_field('bios_version', fact_value(host, 'dmi::bios::version'))
|
100
|
+
@stream.simple_field('bios_release_date', fact_value(host, 'dmi::bios::relase_date'))
|
101
|
+
if (cpu_flags = fact_value(host, 'lscpu::flags'))
|
102
|
+
@stream.array_field('cpu_flags') do
|
103
|
+
@stream.raw(cpu_flags.split.map do |flag|
|
104
|
+
@stream.stringify_value(flag)
|
105
|
+
end.join(', '))
|
106
|
+
end
|
107
|
+
end
|
108
|
+
@stream.simple_field('os_release', fact_value(host, 'distribution::name'))
|
109
|
+
@stream.simple_field('os_kernel_version', fact_value(host, 'uname::release'))
|
110
|
+
@stream.simple_field('arch', host.architecture&.name)
|
111
|
+
@stream.simple_field('subscription_status', host.subscription_status_label)
|
112
|
+
@stream.simple_field('katello_agent_running', host.content_facet&.katello_agent_installed?)
|
113
|
+
@stream.simple_field('satellite_managed', true)
|
114
|
+
unless (installed_products = host.subscription_facet&.installed_products).empty?
|
115
|
+
@stream.array_field('installed_products') do
|
116
|
+
@stream.raw(installed_products.map do |product|
|
117
|
+
{
|
118
|
+
'name': product.name,
|
119
|
+
'id': product.cp_product_id,
|
120
|
+
}.to_json
|
121
|
+
end.join(', '))
|
122
|
+
end
|
123
|
+
end
|
124
|
+
@stream.array_field('installed_packages', :last) do
|
125
|
+
first = true
|
126
|
+
host.installed_packages.each do |package|
|
127
|
+
@stream.raw("#{first ? '' : ', '}#{@stream.stringify_value(package.nvra)}")
|
128
|
+
first = false
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def report_satellite_facts(host)
|
134
|
+
@stream.simple_field('virtual_host_name', host.subscription_facet.hypervisor_host&.name)
|
135
|
+
@stream.simple_field('virtual_host_uuid', host.subscription_facet.hypervisor_host&.subscription_facet&.uuid)
|
136
|
+
if defined?(ForemanThemeSatellite)
|
137
|
+
@stream.simple_field('satellite_version', ForemanThemeSatellite::SATELLITE_VERSION)
|
138
|
+
end
|
139
|
+
@stream.simple_field('system_purpose_usage', host.subscription_facet.purpose_usage)
|
140
|
+
@stream.simple_field('system_purpose_role', host.subscription_facet.purpose_role)
|
141
|
+
@stream.simple_field('distribution_version', fact_value(host, 'distribution::version'))
|
142
|
+
@stream.simple_field('satellite_instance_id', Foreman.respond_to?(:instance_id) ? Foreman.instance_id : nil)
|
143
|
+
@stream.simple_field('organization_id', host.organization_id, :last)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|