Sha256: 870ff243704226a06e63acd5f59e7ea36c065b20cc18f536a4214aaafaae9893

Contents?: true

Size: 1.77 KB

Versions: 15

Compression:

Stored size: 1.77 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',
              'distribution::version',
            ]).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, :hypervisor_host]
          )
          .merge(fact_values)
      end

      def self.for_report(portal_user)
        org_ids = organizations_for_user(portal_user).pluck(:id)
        for_slice(Host.unscoped.where(organization_id: org_ids)).in_batches(of: 1_000)
      end

      def self.for_org(organization_id)
        for_slice(Host.unscoped.where(organization_id: organization_id)).in_batches(of: 1_000)
      end

      def self.organizations_for_user(portal_user)
        Organization
          .joins(:telemetry_configuration)
          .where(
            redhat_access_telemetry_configurations: {
              portal_user: portal_user,
              enable_telemetry: true,
            }
          )
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
foreman_rh_cloud-0.9.4.1 lib/foreman_inventory_upload/generators/queries.rb
foreman_rh_cloud-1.0.4.1 lib/foreman_inventory_upload/generators/queries.rb
foreman_rh_cloud-1.0.4 lib/foreman_inventory_upload/generators/queries.rb
foreman_rh_cloud-2.0.4 lib/foreman_inventory_upload/generators/queries.rb
foreman_rh_cloud-0.9.4 lib/foreman_inventory_upload/generators/queries.rb
foreman_inventory_upload-2.0.4.pre.2 lib/foreman_inventory_upload/generators/queries.rb
foreman_inventory_upload-2.0.4.pre.1 lib/foreman_inventory_upload/generators/queries.rb
foreman_inventory_upload-2.0.3 lib/foreman_inventory_upload/generators/queries.rb
foreman_inventory_upload-1.0.3 lib/foreman_inventory_upload/generators/queries.rb
foreman_inventory_upload-0.9.2 lib/foreman_inventory_upload/generators/queries.rb
foreman_inventory_upload-1.0.2 lib/foreman_inventory_upload/generators/queries.rb
foreman_inventory_upload-0.9.1 lib/foreman_inventory_upload/generators/queries.rb
foreman_inventory_upload-1.0.1 lib/foreman_inventory_upload/generators/queries.rb
foreman_inventory_upload-0.9.0 lib/foreman_inventory_upload/generators/queries.rb
foreman_inventory_upload-1.0.0 lib/foreman_inventory_upload/generators/queries.rb