Sha256: df5c99294e197b23399fc03f3d709809848dfc664529a35ec32b07ebb7b7e91d

Contents?: true

Size: 1.79 KB

Versions: 43

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.reverse.find do |step|
          step.action_id == input[:delegated_action_id]
        end
        return unless delegated_step
        world.persistence.load_action(delegated_step)
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
foreman-tasks-6.0.3 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-7.0.0 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-6.0.2 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-4.1.6 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-5.2.3 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-6.0.1 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-5.2.2 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-6.0.0 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-5.2.1 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-5.3.0 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-5.2.0 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-5.1.1 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-5.1.0 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-4.1.5 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-4.1.4 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-4.1.3 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-3.0.6 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-5.0.0 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-4.1.2 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-4.1.1 app/lib/actions/helpers/with_delegated_action.rb