Sha256: ee41dc12040a67ba5a87b63233b19cff5f4cd2549870a760cf2e8fa23a9a24e6

Contents?: true

Size: 1.79 KB

Versions: 55

Compression:

Stored size: 1.79 KB

Contents

module Actions
  module Helpers
    module WithDelegatedAction
      include ::Actions::Helpers::WithContinuousOutput

      def plan_delegated_action(proxy, klass, options)
        case proxy
        when :not_defined
          if klass.is_a?(String)
            raise Foreman::Exception, _('No proxy defined for execution')
          else
            delegated_action = plan_action(klass, options)
          end
        when :not_available
          raise Foreman::Exception, _('All proxies with the required feature are unavailable at the moment')
        when ::SmartProxy
          delegated_action = plan_action(::Actions::ProxyAction, proxy, klass, options)
        end

        input[:delegated_action_id] = delegated_action.id
        delegated_action
      end

      def humanized_output
        delegated_output
      end

      def continuous_output_providers
        super.tap do |ret|
          ret << delegated_action if delegated_action.respond_to?(:fill_continuous_output)
        end
      end

      def delegated_output
        return @delegated_output if @delegated_output
        action = delegated_action
        @delegated_output = case action
                            when NilClass
                              {}
                            when ::Actions::ProxyAction
                              action.proxy_output(true)
                            else
                              action.output
                            end
      end

      def delegated_action
        # TODO: make it easier in dynflow to load action data
        delegated_step = task.execution_plan.steps.values.find_all do |step|
          step.action_id == input[:delegated_action_id]
        end.last
        return unless delegated_step
        world.persistence.load_action(delegated_step)
      end
    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
foreman-tasks-0.17.3 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-0.17.2 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-0.16.3 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-0.17.1 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-0.15.11 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-0.16.2 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-0.15.10 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-0.16.1 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-0.17.0 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-0.15.9 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-0.15.8 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-0.14.6 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-0.15.7 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-0.16.0 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-0.15.6 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-0.15.5 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-0.15.4 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-0.15.3 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-0.15.2 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-0.15.1 app/lib/actions/helpers/with_delegated_action.rb