Class: Actions::Foreman::Host::ImportFacts

Inherits:
EntryAction
  • Object
show all
Defined in:
app/lib/actions/foreman/host/import_facts.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from EntryAction

#action_subject, all_action_names, #delay, serializer_class

Methods included from Helpers::Lock

#exclusive_lock!, #link!, #lock!

Methods included from Helpers::ArgsSerialization

#serialize_args

Methods inherited from Base

#already_running?, #humanized_errors, #humanized_output, #serializer_class, #task, #task_input, #task_output

Class Method Details

.cleanup_afterObject

default value for cleaning up the tasks, it can be overriden by settings



48
49
50
# File 'app/lib/actions/foreman/host/import_facts.rb', line 48

def self.cleanup_after
  '30d'
end

Instance Method Details

#humanized_inputObject



43
44
45
# File 'app/lib/actions/foreman/host/import_facts.rb', line 43

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

#humanized_nameObject



39
40
41
# File 'app/lib/actions/foreman/host/import_facts.rb', line 39

def humanized_name
  _("Import facts")
end

#plan(host_type, host_name, facts, certname, proxy_id) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'app/lib/actions/foreman/host/import_facts.rb', line 11

def plan(host_type, host_name, facts, certname, proxy_id)
  facts['domain'].try(:downcase!)
  host = ::Host::Base.import_host(host_name, certname, facts, proxy_id)
  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

#rescue_strategyObject



35
36
37
# File 'app/lib/actions/foreman/host/import_facts.rb', line 35

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

#resource_locksObject



7
8
9
# File 'app/lib/actions/foreman/host/import_facts.rb', line 7

def resource_locks
  :import_facts
end

#runObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/lib/actions/foreman/host/import_facts.rb', line 22

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