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, #drop_all_locks!, 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, #notify_paused, #serializer_class, #task, #task_input, #task_output

Methods included from TaskSynchronization

included, #sync_execution_plan_to_task

Methods included from Helpers::LifecycleLogging

included, #log_task_state_change

Class Method Details

.cleanup_afterObject

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



51
52
53
# File 'app/lib/actions/foreman/host/import_facts.rb', line 51

def self.cleanup_after
  '30d'
end

Instance Method Details

#humanized_inputObject



46
47
48
# File 'app/lib/actions/foreman/host/import_facts.rb', line 46

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

#humanized_nameObject



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

def humanized_name
  _('Import facts')
end

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



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

def plan(_host_type, host_name, facts, certname, proxy_id)
  facts['domain'].try(:downcase!)
  host = ::Host::Managed.import_host(host_name, certname)
  host.save(:validate => false) if host.new_record?
  action_subject(host, :facts => facts.to_unsafe_h, :proxy_id => proxy_id)
  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

#proxyObject



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

def proxy
  SmartProxy.find_by(id: input[:proxy_id]) if input[:proxy_id].present?
end

#rescue_strategyObject



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

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

#resource_locksObject



5
6
7
# File 'app/lib/actions/foreman/host/import_facts.rb', line 5

def resource_locks
  :import_facts
end

#runObject



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

def run
  ::User.as :admin do
    host           = ::Host.find(input[:host][:id])
    state          = ::HostFactImporter.new(host).import_facts(input[:facts], proxy)
    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