Module: ForemanInventoryUpload

Defined in:
lib/foreman_inventory_upload.rb,
lib/foreman_inventory_upload/generators/tags.rb,
lib/foreman_inventory_upload/generators/slice.rb,
lib/foreman_inventory_upload/generators/queries.rb,
lib/foreman_inventory_upload/async/async_helpers.rb,
lib/foreman_inventory_upload/async/delayed_start.rb,
lib/foreman_inventory_upload/generators/metadata.rb,
lib/foreman_inventory_upload/generators/json_stream.rb,
lib/foreman_inventory_upload/generators/fact_helpers.rb,
lib/foreman_inventory_upload/async/generate_host_report.rb,
lib/foreman_inventory_upload/async/queue_for_upload_job.rb,
lib/foreman_inventory_upload/generators/archived_report.rb,
app/controllers/foreman_inventory_upload/tasks_controller.rb,
lib/foreman_inventory_upload/async/single_host_report_job.rb,
app/controllers/foreman_inventory_upload/reports_controller.rb,
app/controllers/foreman_inventory_upload/uploads_controller.rb,
lib/foreman_inventory_upload/async/generate_all_reports_job.rb,
lib/foreman_inventory_upload/async/upload_report_direct_job.rb,
app/controllers/foreman_inventory_upload/accounts_controller.rb,
lib/foreman_inventory_upload/async/host_inventory_report_job.rb,
lib/foreman_inventory_upload/async/remove_insights_hosts_job.rb,
app/controllers/foreman_inventory_upload/api/tasks_controller.rb,
app/controllers/foreman_inventory_upload/cloud_status_controller.rb,
app/controllers/foreman_inventory_upload/missing_hosts_controller.rb,
lib/foreman_inventory_upload/async/create_missing_insights_facets.rb,
app/controllers/foreman_inventory_upload/uploads_settings_controller.rb,
lib/foreman_inventory_upload/notifications/manifest_import_success_notification_override.rb

Defined Under Namespace

Modules: Api, Async, Generators, Notifications Classes: AccountsController, CloudStatusController, MissingHostsController, ReportsController, TasksController, UploadsController, UploadsSettingsController

Class Method Summary collapse

Class Method Details

.base_folderObject



2
3
4
5
6
7
8
9
10
# File 'lib/foreman_inventory_upload.rb', line 2

def self.base_folder
  # in production setup, where selinux is enabled, we only have rights to
  # create folders under /var/lib/foreman. If the folder does not exist, it's
  # a dev setup, where we can use the parent of the current working directory
  @base_folder ||= File.join(
    Dir.glob('/var/lib/foreman').first || File.dirname(Dir.getwd),
    'red_hat_inventory/'
  )
end

.done_file_path(filename) ⇒ Object



29
30
31
# File 'lib/foreman_inventory_upload.rb', line 29

def self.done_file_path(filename)
  File.join(ForemanInventoryUpload.done_folder, filename)
end

.done_folderObject



25
26
27
# File 'lib/foreman_inventory_upload.rb', line 25

def self.done_folder
  File.join(ForemanInventoryUpload.uploads_folder, 'done/')
end

.ensure_folder(folder) ⇒ Object



84
85
86
87
# File 'lib/foreman_inventory_upload.rb', line 84

def self.ensure_folder(folder)
  FileUtils.mkdir_p(folder)
  folder
end

.facts_archive_name(organization, filter = nil) ⇒ Object



66
67
68
# File 'lib/foreman_inventory_upload.rb', line 66

def self.facts_archive_name(organization, filter = nil)
  "report_for_#{organization}#{filter.empty? ? nil : "[#{filter.to_s.parameterize}]"}.tar.xz"
end

.generated_reports_file_path(filename) ⇒ Object



42
43
44
# File 'lib/foreman_inventory_upload.rb', line 42

def self.generated_reports_file_path(filename)
  File.join(ForemanInventoryUpload.generated_reports_folder, filename)
end

.generated_reports_folderObject



33
34
35
36
37
38
39
40
# File 'lib/foreman_inventory_upload.rb', line 33

def self.generated_reports_folder
  @generated_reports_folder ||= ensure_folder(
    File.join(
      ForemanInventoryUpload.base_folder,
      'generated_reports/'
    )
  )
end

.host_by_id_url(host_uuid) ⇒ Object



102
103
104
# File 'lib/foreman_inventory_upload.rb', line 102

def self.host_by_id_url(host_uuid)
  "#{inventory_base_url}/#{host_uuid}"
end

.hosts_by_ids_url(host_uuids) ⇒ Object



106
107
108
109
# File 'lib/foreman_inventory_upload.rb', line 106

def self.hosts_by_ids_url(host_uuids)
  host_ids_string = host_uuids.join(',')
  "#{inventory_base_url}/#{host_ids_string}"
end

.inventory_base_urlObject



89
90
91
# File 'lib/foreman_inventory_upload.rb', line 89

def self.inventory_base_url
  "#{ForemanRhCloud.cert_base_url}/api/inventory/v1/hosts"
end

.inventory_export_urlObject



93
94
95
96
# File 'lib/foreman_inventory_upload.rb', line 93

def self.inventory_export_url
  tags = CGI.escape("satellite/satellite_instance_id=#{Foreman.instance_id}")
  inventory_base_url + "?tags=#{tags}"
end

.inventory_self_urlObject



98
99
100
# File 'lib/foreman_inventory_upload.rb', line 98

def self.inventory_self_url
  inventory_base_url + "?hostname_or_id=#{ForemanRhCloud.foreman_host.fqdn}"
end

.max_org_sizeObject



79
80
81
82
# File 'lib/foreman_inventory_upload.rb', line 79

def self.max_org_size
  # Set max amount of hosts per organization for automatic uploads
  @max_org_size ||= (ENV['SATELLITE_INVENTORY_MAX_ORG_SIZE'] || 150_000).to_i
end

.outputs_folderObject



62
63
64
# File 'lib/foreman_inventory_upload.rb', line 62

def self.outputs_folder
  @outputs_folder ||= ensure_folder(File.join(ForemanInventoryUpload.base_folder, 'outputs/'))
end

.report_file_paths(organization_id) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/foreman_inventory_upload.rb', line 46

def self.report_file_paths(organization_id)
  filename = facts_archive_name(organization_id)
  # Report files start in generated
  # They are then MOVED (not copied) to uploads, then done.
  # When they are moved to the new folder, they overwrite any file with the same name.
  # If it's a generate-only, it will be in generated
  # Failed or incomplete uploads will be in uploads
  # Completed uploads will be in done
  # The ordering here ensures we get the correct file path every time.
  Dir[
    ForemanInventoryUpload.generated_reports_file_path(filename),
    ForemanInventoryUpload.uploads_file_path(filename),
    ForemanInventoryUpload.done_file_path(filename),
  ]
end

.slice_sizeObject



75
76
77
# File 'lib/foreman_inventory_upload.rb', line 75

def self.slice_size
  @slice_size ||= (ENV['SATELLITE_INVENTORY_SLICE_SIZE'] || '1000').to_i
end

.upload_urlObject



70
71
72
73
# File 'lib/foreman_inventory_upload.rb', line 70

def self.upload_url
  # for testing set ENV to 'https://ci.cloud.redhat.com/api/ingress/v1/upload'
  ENV['SATELLITE_INVENTORY_UPLOAD_URL'] || "#{ForemanRhCloud.cert_base_url}/api/ingress/v1/upload"
end

.uploads_file_path(filename) ⇒ Object



21
22
23
# File 'lib/foreman_inventory_upload.rb', line 21

def self.uploads_file_path(filename)
  File.join(ForemanInventoryUpload.uploads_folder, filename)
end

.uploads_folderObject



12
13
14
15
16
17
18
19
# File 'lib/foreman_inventory_upload.rb', line 12

def self.uploads_folder
  @uploads_folder ||= ensure_folder(
    File.join(
      ForemanInventoryUpload.base_folder,
      'uploads/'
    )
  )
end