Class: Actions::Foreman::Host::ImportFacts
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from EntryAction
#action_subject, all_action_names, #delay, #drop_all_locks!, serializer_class
#exclusive_lock!, #link!, #lock!
#serialize_args
Methods inherited from Base
#already_running?, #humanized_errors, #humanized_output, #notify_paused, #serializer_class, #task, #task_input, #task_output
included, #log_task_state_change
Class Method Details
.cleanup_after ⇒ Object
default value for cleaning up the tasks, it can be overriden by settings
56
57
58
|
# File 'app/lib/actions/foreman/host/import_facts.rb', line 56
def self.cleanup_after
'30d'
end
|
Instance Method Details
51
52
53
|
# File 'app/lib/actions/foreman/host/import_facts.rb', line 51
def humanized_input
input[:host] && input[:host][:name]
end
|
#humanized_name ⇒ Object
47
48
49
|
# File 'app/lib/actions/foreman/host/import_facts.rb', line 47
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
20
21
22
23
24
|
# 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 = if SETTINGS[:version].short > '1.16'
::Host::Managed.import_host(host_name, certname)
else
::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.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
|
#proxy ⇒ Object
39
40
41
|
# File 'app/lib/actions/foreman/host/import_facts.rb', line 39
def proxy
SmartProxy.find_by(id: input[:proxy_id]) if input[:proxy_id].present?
end
|
#rescue_strategy ⇒ Object
43
44
45
|
# File 'app/lib/actions/foreman/host/import_facts.rb', line 43
def rescue_strategy
::Dynflow::Action::Rescue::Skip
end
|
#resource_locks ⇒ Object
5
6
7
|
# File 'app/lib/actions/foreman/host/import_facts.rb', line 5
def resource_locks
:import_facts
end
|
#run ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'app/lib/actions/foreman/host/import_facts.rb', line 26
def run
::User.as :admin do
host = ::Host.find(input[:host][:id])
state = host.import_facts(input[:facts], proxy)
output[:state] = state
end
rescue ::Foreman::Exception => e
raise e unless e.code == 'ERF51-9911'
end
|