Sha256: f00b179b81253fb8b0038abf889ccef9e552172f747240b221f333ca6af3921e

Contents?: true

Size: 1.62 KB

Versions: 92

Compression:

Stored size: 1.62 KB

Contents

module ProxyAPI
  module ForemanDynflow
    class DynflowProxy
      PREFIX = 'dynflow'.freeze

      class Task < ProxyAPI::Resource
        def initialize(args)
          @url = "#{args[:url]}/#{PREFIX}/tasks"
          super args
          @connect_params[:headers] ||= {}
          @connect_params[:headers]['content-type'] = 'application/json'
        end
      end

      def initialize(args)
        @args = args
      end

      # Initiate the command
      def trigger_task(action_name, action_input)
        payload = MultiJson.dump(:action_name => action_name, :action_input => action_input)
        MultiJson.load(Task.new(@args).send(:post, payload))
      end

      # Cancel the command
      def cancel_task(proxy_task_id)
        MultiJson.load(Task.new(@args).send(:post, '', "#{proxy_task_id}/cancel"))
      end

      def status_of_task(proxy_task_id)
        MultiJson.load(Task.new(@args).send(:get, "#{proxy_task_id}/status"))
      end

      def tasks_count(state)
        MultiJson.load(Task.new(@args).send(:get, "count?state=#{state}"))['count'].to_i
      end

      def task_states(ids)
        payload = MultiJson.dump(:task_ids => ids)
        MultiJson.load(Task.new(@args).send(:post, payload, 'status'))
      end

      def operations
        MultiJson.load(Task.new(@args).send(:get, 'operations'))
      end

      def launch_tasks(operation, input, options = {})
        data = { :input => input,
                 :operation => operation,
                 :options => options }
        payload = MultiJson.dump(data)
        MultiJson.load(Task.new(@args).send(:post, payload, 'launch'))
      end
    end
  end
end

Version data entries

92 entries across 92 versions & 1 rubygems

Version Path
foreman-tasks-8.1.2 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-8.1.1 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-8.1.0 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-8.0.2 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-8.0.1 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-8.0.0 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-7.2.1 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-7.1.1 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-7.2.0 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-7.1.0 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-6.0.3 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-7.0.0 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-6.0.2 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-4.1.6 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-5.2.3 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-6.0.1 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-5.2.2 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-6.0.0 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-5.2.1 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-5.3.0 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb