Class: ForemanInventoryUpload::Generators::Queries

Inherits:
Object
  • Object
show all
Defined in:
lib/foreman_inventory_upload/generators/queries.rb

Class Method Summary collapse

Class Method Details

.fact_namesObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/foreman_inventory_upload/generators/queries.rb', line 4

def self.fact_names
  @fact_names ||= Hash[
    Katello::RhsmFactName.where(name:
      [
        'dmi::system::uuid',
        'virt::uuid',
        'cpu::cpu(s)',
        'cpu::cpu_socket(s)',
        'cpu::core(s)_per_socket',
        'memory::memtotal',
        'dmi::bios::vendor',
        'dmi::bios::version',
        'dmi::bios::relase_date',
        'distribution::name',
        'uname::release',
        'lscpu::flags',
        'distribution::version',
        'distribution::id',
        'virt::is_guest',
        'dmi::system::manufacturer',
        'dmi::system::product_name',
        'dmi::chassis::asset_tag',
        'insights_client::obfuscate_hostname_enabled',
        'insights_client::obfuscate_ip_enabled',
        'insights_client::hostname',
        'insights_client::ips',
        'insights_id',
      ]).pluck(:name, :id)
    ]
end

.for_org(organization_id, use_batches: true) ⇒ Object



49
50
51
52
# File 'lib/foreman_inventory_upload/generators/queries.rb', line 49

def self.for_org(organization_id, use_batches: true)
  base_query = for_slice(Host.unscoped.where(organization_id: organization_id))
  use_batches ? base_query.in_batches(of: ForemanInventoryUpload.slice_size) : base_query
end

.for_slice(base) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/foreman_inventory_upload/generators/queries.rb', line 35

def self.for_slice(base)
  base
    .search_for("not params.#{InsightsCloud.enable_client_param} = f")
    .joins(:subscription_facet)
    .preload(
      :interfaces,
      :installed_packages,
      :content_facet,
      :host_statuses,
      :inventory_upload_facts,
      subscription_facet: [:pools, :installed_products, :hypervisor_host]
    )
end