Sha256: b81840d7e7cbbfc31d1d17d28c981a8cead57094f5aa0ec2e3198049084a593f

Contents?: true

Size: 1.83 KB

Versions: 30

Compression:

Stored size: 1.83 KB

Contents

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

      def plan_delegated_action(proxy, klass, options, proxy_action_class: ::Actions::ProxyAction)
        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(proxy_action_class, 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

30 entries across 30 versions & 1 rubygems

Version Path
foreman-tasks-10.0.1 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-10.0.0 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-9.2.3 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-9.2.2 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-9.2.1 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-9.2.0 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-9.1.1 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-9.0.4 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-9.1.0 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-9.0.2 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-9.0.1 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-8.3.3 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-9.0.0 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-8.2.1 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-8.1.4 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-8.3.2 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-8.3.1 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-8.1.3 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-8.3.0 app/lib/actions/helpers/with_delegated_action.rb
foreman-tasks-8.2.0 app/lib/actions/helpers/with_delegated_action.rb