Sha256: 2c1c34d364245ad0c7c487a65f142b147afcedbf5c24ed1f1c1371bffdfcf3d3

Contents?: true

Size: 999 Bytes

Versions: 1

Compression:

Stored size: 999 Bytes

Contents

module AnsibleTowerClient
  class JobTemplate < BaseModel
    def launch(options = {})
      launch_url = "#{url}launch/"
      options = options.dup
      new_limit = options.delete('limit')
      response = with_temporary_changes(new_limit) do
        api.post(launch_url, options).body
      end

      job = JSON.parse(response)
      api.jobs.find(job['job'])
    end

    def survey_spec
      spec_url = related['survey_spec']
      return nil unless spec_url
      api.get(spec_url).body
    end

    def self.endpoint
      "job_templates".freeze
    end

    private

    def with_temporary_changes(in_limit)
      old_limit = limit
      new_limit = in_limit
      patch("{ \"limit\": \"#{new_limit}\" }")
      begin
        yield
      ensure
        patch("{ \"limit\": \"#{old_limit}\" }")
      end
    end

    def patch(body)
      api.patch do |req|
        req.url(url)
        req.headers['Content-Type'] = 'application/json'
        req.body = body
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ansible_tower_client-0.1.0 lib/ansible_tower_client/job_template.rb