Class: ForemanSalt::ReportImporter
- Inherits:
-
Object
- Object
- ForemanSalt::ReportImporter
- Defined in:
- app/services/foreman_salt/report_importer.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#report ⇒ Object
readonly
Returns the value of attribute report.
Class Method Summary collapse
Instance Method Summary collapse
- #import ⇒ Object
-
#initialize(host, raw, proxy_id = nil) ⇒ ReportImporter
constructor
A new instance of ReportImporter.
Constructor Details
#initialize(host, raw, proxy_id = nil) ⇒ ReportImporter
Returns a new instance of ReportImporter.
15 16 17 18 19 |
# File 'app/services/foreman_salt/report_importer.rb', line 15 def initialize(host, raw, proxy_id = nil) @host = find_or_create_host(host) @raw = raw @proxy_id = proxy_id end |
Instance Attribute Details
#report ⇒ Object (readonly)
Returns the value of attribute report.
4 5 6 |
# File 'app/services/foreman_salt/report_importer.rb', line 4 def report @report end |
Class Method Details
.import(raw, proxy_id = nil) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'app/services/foreman_salt/report_importer.rb', line 6 def self.import(raw, proxy_id = nil) fail ::Foreman::Exception.new(_('Invalid report')) unless raw.is_a?(Hash) raw.map do |host, report| importer = ForemanSalt::ReportImporter.new(host, report, proxy_id) importer.import importer.report end end |
Instance Method Details
#import ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/services/foreman_salt/report_importer.rb', line 21 def import logger.info "processing report for #{@host}" logger.debug { "Report: #{@raw.inspect}" } if @host.new_record? && !Setting[:create_new_host_when_report_is_uploaded] logger.info("skipping report for #{@host} as its an unknown host and create_new_host_when_report_is_uploaded setting is disabled") return ConfigReport.new end @host.salt_proxy_id ||= @proxy_id @host.last_report = start_time if @raw.is_a? Array process_failures # If Salt sends us only an array, it's a list of fatal failures else process_normal end @host.save(:validate => false) @host.reload @host.refresh_statuses logger.info("Imported report for #{@host} in #{(Time.zone.now - start_time).round(2)} seconds") end |