class InventorySync::Async::HostResult

Attributes

organization[R]
uuid_by_fqdn[R]

Public Class Methods

new(result, organization) click to toggle source
# File lib/inventory_sync/async/host_result.rb, line 6
def initialize(result, organization)
  @organization = organization
  @total = result['total']
  @count = result['count']
  @page = result['page']
  @per_page = result['per_page']
  @sub_ids = result["results"].map { |host| host['subscription_manager_id'] }
  @uuid_by_sub_id = Hash[result["results"].map { |host| [host['subscription_manager_id'], host['id']] }]
  @uuid_by_fqdn = Hash[result["results"].map { |host| [host['fqdn']&.downcase, host['id']] }]
  @results = result["results"]
end

Public Instance Methods

host_id(sub_id) click to toggle source
# File lib/inventory_sync/async/host_result.rb, line 32
def host_id(sub_id)
  hosts[sub_id]
end
host_uuids() click to toggle source
# File lib/inventory_sync/async/host_result.rb, line 42
def host_uuids
  @host_uuids ||= Hash[@sub_ids.map { |sub_id| [host_id(sub_id), @uuid_by_sub_id[sub_id]] }].except(nil)
end
hosts() click to toggle source
# File lib/inventory_sync/async/host_result.rb, line 36
def hosts
  @hosts ||= Hash[
    Katello::Host::SubscriptionFacet.where(uuid: @sub_ids).pluck(:uuid, :host_id)
  ]
end
last?() click to toggle source
# File lib/inventory_sync/async/host_result.rb, line 55
def last?
  @total <= @per_page * @page
end
missing_hosts() click to toggle source
# File lib/inventory_sync/async/host_result.rb, line 46
def missing_hosts
  @results.select { |host| hosts[host['subscription_manager_id']].nil? }
end
percentage() click to toggle source
# File lib/inventory_sync/async/host_result.rb, line 50
def percentage
  ratio = @per_page * @page * 1.0 / @total * 100
  ratio > 100 ? 100 : ratio.truncate(2)
end
status_hashes() click to toggle source
# File lib/inventory_sync/async/host_result.rb, line 18
def status_hashes
  @sub_ids.map do |sub_id|
    host_id = host_id(sub_id)
    if host_id
      {
        host_id: host_id,
        status: InventorySync::InventoryStatus::SYNC,
        reported_at: DateTime.current,
        type: InventorySync::InventoryStatus.name,
      }
    end
  end.compact
end