Sha256: 13a73a81d9f86cc4c2ed0470408868724c6a01000eaeb7f6ba192ac5bd1d922d

Contents?: true

Size: 1.38 KB

Versions: 49

Compression:

Stored size: 1.38 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 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
      end
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
foreman-tasks-0.7.7 app/models/foreman_tasks/concerns/host_action_subject.rb
foreman-tasks-0.7.6 app/models/foreman_tasks/concerns/host_action_subject.rb
foreman-tasks-0.7.5 app/models/foreman_tasks/concerns/host_action_subject.rb
foreman-tasks-0.7.4 app/models/foreman_tasks/concerns/host_action_subject.rb
foreman-tasks-0.7.3 app/models/foreman_tasks/concerns/host_action_subject.rb
foreman-tasks-0.7.2 app/models/foreman_tasks/concerns/host_action_subject.rb
foreman-tasks-0.7.1 app/models/foreman_tasks/concerns/host_action_subject.rb
foreman-tasks-0.7.0 app/models/foreman_tasks/concerns/host_action_subject.rb
foreman-tasks-0.6.15 app/models/foreman_tasks/concerns/host_action_subject.rb
foreman-tasks-0.6.14 app/models/foreman_tasks/concerns/host_action_subject.rb
foreman-tasks-0.6.13 app/models/foreman_tasks/concerns/host_action_subject.rb
foreman-tasks-0.6.12 app/models/foreman_tasks/concerns/host_action_subject.rb
foreman-tasks-0.6.11 app/models/foreman_tasks/concerns/host_action_subject.rb
foreman-tasks-0.6.10 app/models/foreman_tasks/concerns/host_action_subject.rb
foreman-tasks-0.6.9 app/models/foreman_tasks/concerns/host_action_subject.rb
foreman-tasks-0.6.8 app/models/foreman_tasks/concerns/host_action_subject.rb
foreman-tasks-0.6.7 app/models/foreman_tasks/concerns/host_action_subject.rb
foreman-tasks-0.6.6 app/models/foreman_tasks/concerns/host_action_subject.rb
foreman-tasks-0.6.5 app/models/foreman_tasks/concerns/host_action_subject.rb
foreman-tasks-0.6.4 app/models/foreman_tasks/concerns/host_action_subject.rb