Sha256: 1583971e1c489e251ec5b912ee73ebfb6b1fd23ea72de0f387c710ee9cd60edb

Contents?: true

Size: 1.07 KB

Versions: 16

Compression:

Stored size: 1.07 KB

Contents

module InventorySync
  module Async
    class InventorySelfHostSync < QueryInventoryJob
      set_callback :step, :around, :create_facets

      def plan
        unless cloud_auth_available?
          logger.debug('Cloud authentication is not available, skipping self host sync')
          return
        end

        plan_self
      end

      def create_facets
        # get the results from the event
        results = yield

        add_missing_insights_facet(results.uuid_by_fqdn) unless results.uuid_by_fqdn.empty?
        results
      end

      def rescue_strategy_for_self
        Dynflow::Action::Rescue::Fail
      end

      private

      def add_missing_insights_facet(uuids_hash)
        facet = InsightsFacet.find_or_create_by(host_id: ForemanRhCloud.foreman_host.id) do |facet|
          facet.uuid = uuids_hash.values.first
        end

        # fix empty uuid in case the facet already exists
        facet.update(uuid: uuids_hash.values.first) unless facet.uuid
      end

      def request_url
        ForemanInventoryUpload.inventory_self_url
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
foreman_rh_cloud-4.0.36 lib/inventory_sync/async/inventory_self_host_sync.rb
foreman_rh_cloud-4.0.35 lib/inventory_sync/async/inventory_self_host_sync.rb
foreman_rh_cloud-5.0.35 lib/inventory_sync/async/inventory_self_host_sync.rb
foreman_rh_cloud-5.0.34 lib/inventory_sync/async/inventory_self_host_sync.rb
foreman_rh_cloud-5.0.33 lib/inventory_sync/async/inventory_self_host_sync.rb
foreman_rh_cloud-4.0.32 lib/inventory_sync/async/inventory_self_host_sync.rb
foreman_rh_cloud-5.0.32 lib/inventory_sync/async/inventory_self_host_sync.rb
foreman_rh_cloud-4.0.31 lib/inventory_sync/async/inventory_self_host_sync.rb
foreman_rh_cloud-5.0.31 lib/inventory_sync/async/inventory_self_host_sync.rb
foreman_rh_cloud-5.0.30 lib/inventory_sync/async/inventory_self_host_sync.rb
foreman_rh_cloud-4.0.30 lib/inventory_sync/async/inventory_self_host_sync.rb
foreman_rh_cloud-4.0.29 lib/inventory_sync/async/inventory_self_host_sync.rb
foreman_rh_cloud-5.0.29 lib/inventory_sync/async/inventory_self_host_sync.rb
foreman_rh_cloud-5.0.28 lib/inventory_sync/async/inventory_self_host_sync.rb
foreman_rh_cloud-4.0.27 lib/inventory_sync/async/inventory_self_host_sync.rb
foreman_rh_cloud-4.0.26 lib/inventory_sync/async/inventory_self_host_sync.rb