Sha256: b5b0fd92c1a8c01acb2300ada46663ffb28cd2a44fbe0a41a508e9771eea1e2c

Contents?: true

Size: 1.51 KB

Versions: 6

Compression:

Stored size: 1.51 KB

Contents

module ForemanInventoryUpload
  module Generators
    class Queries
      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',
            ]).pluck(:name, :id)
          ]
      end

      def self.for_slice(base)
        fact_values = FactValue.where(fact_name_id: fact_names.values)
        base
          .joins(:subscription_facet)
          .eager_load(:fact_values)
          .preload(
            :interfaces,
            :installed_packages,
            :content_facet,
            :host_statuses,
            subscription_facet: [:pools, :installed_products]
          )
          .merge(fact_values)
      end

      def self.for_report(portal_user)
        org_ids = Organization
                  .joins(:telemetry_configuration)
                  .where(
                    redhat_access_telemetry_configurations: {
                      portal_user: portal_user,
                      enable_telemetry: true,
                    }
                  ).pluck(:id)
        for_slice(Host.where(organization_id: org_ids)).in_batches(of: 1_000)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
foreman_inventory_upload-1.0.0.beta6 lib/foreman_inventory_upload/generators/queries.rb
foreman_inventory_upload-1.0.0.beta5 lib/foreman_inventory_upload/generators/queries.rb
foreman_inventory_upload-1.0.0.beta4 lib/foreman_inventory_upload/generators/queries.rb
foreman_inventory_upload-1.0.0.beta3 lib/foreman_inventory_upload/generators/queries.rb
foreman_inventory_upload-1.0.0.beta2 lib/foreman_inventory_upload/generators/queries.rb
foreman_inventory_upload-1.0.0.beta1 lib/foreman_inventory_upload/generators/queries.rb