Sha256: 5b1b8d48eb5344d15f03cdeb0e400c7b54d3793a3fac5f0c633054098e160770
Contents?: true
Size: 1.6 KB
Versions: 12
Compression:
Stored size: 1.6 KB
Contents
module ForemanTasks module Concerns module HostActionSubject extend ActiveSupport::Concern include ForemanTasks::Concerns::ActionSubject def action_input_key "host" end def available_locks [:read, :write, :import_facts] end module ClassMethods # TODO: This should get into the Foreman core, extracting the # +importHostAndFacts+ method into two def import_host(hostname, certname, facts, proxy_id = nil) raise(::Foreman::Exception.new("Invalid Facts, must be a Hash")) unless facts.is_a?(Hash) 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] return Host.new if host.nil? # 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 and the upload came from puppet, # use it as puppet proxy. if facts['_type'].blank? || facts['_type'] == 'puppet' host.puppet_proxy_id ||= proxy_id end host.save(:validate => false) if host.new_record? host end end end end end
Version data entries
12 entries across 12 versions & 1 rubygems