Sha256: 63026c0d0f8082b0a4a29258ef2efb8832306c26eab24c411146e60a1f18299e

Contents?: true

Size: 1.29 KB

Versions: 24

Compression:

Stored size: 1.29 KB

Contents

module ForemanInventoryUpload
  module Generators
    class Metadata
      include FactHelpers
      def initialize(output = [])
        @stream = JsonStream.new(output)
      end

      def add_slice(slice_id, hosts_count, first)
        @stream.comma unless first

        @stream.object_field(slice_id, :last) do
          @stream.simple_field('number_hosts', hosts_count, :last)
        end
      end

      def render(metadata = nil, &block)
        render_report(metadata, &block)
        @stream.out
      end

      private

      def render_report(metadata)
        metadata ||= {}
        metadata['foreman_rh_cloud_version'] = ForemanRhCloud::VERSION

        @stream.object do
          @stream.simple_field('report_id', Foreman.uuid)
          @stream.simple_field('host_inventory_api_version', '1.0')
          @stream.simple_field('source', 'Satellite')
          @stream.simple_field('reporting_host_name', hostname_match)
          @stream.simple_field('reporting_host_ips', host_ips(ForemanRhCloud.foreman_host))
          @stream.simple_field('reporting_host_bios_uuid', bios_uuid(ForemanRhCloud.foreman_host))
          @stream.simple_field('source_metadata', metadata)
          @stream.object_field('report_slices', :last) do
            yield(self)
          end
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
foreman_rh_cloud-9.0.59 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-11.0.2 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-11.0.1 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-11.0.0 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-9.0.58 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-10.0.2 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-9.0.57 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-10.0.1 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-9.0.56 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-9.0.55 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-9.0.54 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-9.0.53 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-9.0.52 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-8.0.52 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-9.0.51 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-8.0.51 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-7.0.48 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-7.0.47 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-8.0.50 lib/foreman_inventory_upload/generators/metadata.rb
foreman_rh_cloud-8.0.49 lib/foreman_inventory_upload/generators/metadata.rb