Sha256: 837a3b69680005868c5e9ce82fb058c6b8004e58594ff36c6d3784a981296858

Contents?: true

Size: 1.77 KB

Versions: 7

Compression:

Stored size: 1.77 KB

Contents

module Actions
  module Foreman
    module Host
      class ImportFacts < Actions::EntryAction
        def resource_locks
          :import_facts
        end

        def plan(_host_type, host_name, facts, certname, proxy_id)
          facts['domain'].try(:downcase!)
          host = if SETTINGS[:version].short > '1.16'
                   ::Host::Base.import_host(host_name, certname, proxy_id)
                 else
                   # backwards compatibility
                   ::Host::Managed.import_host(host_name, facts['_type'], certname, proxy_id)
                 end
          host.save(:validate => false) if host.new_record?
          action_subject(host, :facts => facts)
          if host.build?
            ::Foreman::Logging.logger('foreman-tasks').info "Skipping importing of facts for #{host.name} because it's in build mode"
          else
            plan_self
          end
        end

        def run
          ::User.as :admin do
            host           = ::Host.find(input[:host][:id])
            state          = host.import_facts(input[:facts])
            output[:state] = state
          end
        rescue ::Foreman::Exception => e
          # This error is what is thrown by Host#ImportHostAndFacts when
          # the Host is in the build state. This can be refactored once
          # issue #3959 is fixed.
          raise e unless e.code == 'ERF51-9911'
        end

        def rescue_strategy
          ::Dynflow::Action::Rescue::Skip
        end

        def humanized_name
          _('Import facts')
        end

        def humanized_input
          input[:host] && input[:host][:name]
        end

        # default value for cleaning up the tasks, it can be overriden by settings
        def self.cleanup_after
          '30d'
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
foreman-tasks-0.14.0 app/lib/actions/foreman/host/import_facts.rb
foreman-tasks-0.13.4 app/lib/actions/foreman/host/import_facts.rb
foreman-tasks-0.13.3 app/lib/actions/foreman/host/import_facts.rb
foreman-tasks-0.13.2 app/lib/actions/foreman/host/import_facts.rb
foreman-tasks-0.13.1 app/lib/actions/foreman/host/import_facts.rb
foreman-tasks-0.13.0 app/lib/actions/foreman/host/import_facts.rb
foreman-tasks-0.12.2 app/lib/actions/foreman/host/import_facts.rb