Module: ForemanTasks::Concerns::HostActionSubject::ClassMethods

Defined in:
app/models/foreman_tasks/concerns/host_action_subject.rb

Instance Method Summary collapse

Instance Method Details

#importHost(hostname, certname, proxy_id = nil) ⇒ Object

TODO: This should get into the Foreman core, extracting the importHostAndFacts method into two

Raises:

  • (::Foreman::Exception)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/foreman_tasks/concerns/host_action_subject.rb', line 18

def importHost(hostname, certname, proxy_id = nil)
  raise(::Foreman::Exception.new("Invalid Hostname, must be a String")) unless hostname.is_a?(String)

  # downcase everything
  hostname.try(:downcase!)
  certname.try(:downcase!)

  host = certname.present? ? Host.find_by_certname(certname) : nil
  host ||= Host.find_by_name hostname
  host ||= Host.new(:name => hostname, :certname => certname) if Setting[:create_new_host_when_facts_are_uploaded]
  if host
    # if we were given a certname but found the Host by hostname we should update the certname
    host.certname = certname if certname.present?
    # if proxy authentication is enabled and we have no puppet proxy set, use it.
    host.puppet_proxy_id ||= proxy_id
    host.save(:validate => false)
    return host
  else
    return
  end
end