Sha256: 9ee0cd914239fb61e11b6f13e54c4895241e33e5082bca489645f3e24961ad9e

Contents?: true

Size: 1.93 KB

Versions: 3

Compression:

Stored size: 1.93 KB

Contents

module Actions
  module RemoteExecution
    class RunHostJob < Actions::EntryAction

      def resource_locks
        :link
      end

      include ::Dynflow::Action::Cancellable

      def plan(job_invocation, host, template_invocation, proxy, connection_options = {})
        action_subject(host, :job_name => job_invocation.job_name)
        hostname = find_ip_or_hostname(host)

        raise _("Could not use any template used in the job invocation") if template_invocation.blank?

        settings =  { :global_proxy   => 'remote_execution_global_proxy',
                      :fallback_proxy => 'remote_execution_fallback_proxy' }

        raise _("Could not use any proxy. Consider configuring %{global_proxy} " +
                "or %{fallback_proxy} in settings") % settings if proxy.blank?

        renderer = InputTemplateRenderer.new(template_invocation.template, host, template_invocation)
        script = renderer.render
        raise _("Failed rendering template: %s") % renderer.error_message unless script

        link!(job_invocation)
        link!(template_invocation)

        plan_action(RunProxyCommand, proxy, hostname, script, { :connection_options => connection_options })
      end

      def humanized_output
        live_output.map { |line| line['output'].chomp }.join("\n")
      end

      def live_output
        planned_actions(RunProxyCommand).first.live_output
      end

      def humanized_name
        _('Run %{job_name} on %{host}') % { :job_name => input[:job_name], :host => input[:host][:name] }
      end

      def find_ip_or_hostname(host)
        %w(execution primary provision).each do |flag|
          if host.send("#{flag}_interface") && host.send("#{flag}_interface").ip.present?
            return host.execution_interface.ip
          end
        end

        host.interfaces.each do |interface|
          return interface.ip unless interface.ip.blank?
        end

        return host.fqdn
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
foreman_remote_execution-0.0.10 app/lib/actions/remote_execution/run_host_job.rb
foreman_remote_execution-0.0.8 app/lib/actions/remote_execution/run_host_job.rb
foreman_remote_execution-0.0.7 app/lib/actions/remote_execution/run_host_job.rb