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-2.0.2 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-1.1.3 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-1.1.2 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-2.0.1 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-2.0.0 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-1.2.0 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-1.1.1 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-1.1.0 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-0.17.6 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-1.0.1 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-1.0.0 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-0.17.5 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-0.17.4 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-0.17.3 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-0.17.2 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-0.16.3 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-0.17.1 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-0.15.11 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-0.16.2 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
foreman-tasks-0.15.10 app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb