class Marathon::Client
Public Class Methods
new(host = nil, user = nil, pass = nil)
click to toggle source
# File lib/marathon/client.rb, line 16 def initialize(host = nil, user = nil, pass = nil) @host = host || ENV['MARATHON_HOST'] || 'http://localhost:8080' @default_options = {} if user && pass @default_options[:basic_auth] = {:username => user, :password => pass} end end
Public Instance Methods
endpoints(id = nil)
click to toggle source
# File lib/marathon/client.rb, line 41 def endpoints(id = nil) if id.nil? wrap_request(:get, "/v1/endpoints") else wrap_request(:get, "/v1/endpoints/#{id}") end end
kill_tasks(appId, params = {})
click to toggle source
# File lib/marathon/client.rb, line 65 def kill_tasks(appId, params = {}) body = {} params = { :scale => false, :host => '*', :appId => appId, :id => nil }.merge(params) wrap_request(:post, "/v1/tasks/kill?#{query_params(params)}", :body => body) end
list()
click to toggle source
# File lib/marathon/client.rb, line 25 def list wrap_request(:get, '/v1/apps') end
list_tasks(id)
click to toggle source
# File lib/marathon/client.rb, line 29 def list_tasks(id) wrap_request(:get, URI.escape("/v1/apps/#{id}/tasks")) end
scale(id, num_instances)
click to toggle source
# File lib/marathon/client.rb, line 55 def scale(id, num_instances) body = {:id => id, :instances => num_instances} wrap_request(:post, '/v1/apps/scale', :body => body) end
search(id = nil, cmd = nil)
click to toggle source
# File lib/marathon/client.rb, line 33 def search(id = nil, cmd = nil) params = {} params[:id] = id unless id.nil? params[:cmd] = cmd unless cmd.nil? wrap_request(:get, "/v1/apps/search?#{query_params(params)}") end
start(id, opts)
click to toggle source
# File lib/marathon/client.rb, line 49 def start(id, opts) body = opts.dup body[:id] = id wrap_request(:post, '/v1/apps/start', :body => body) end
stop(id)
click to toggle source
# File lib/marathon/client.rb, line 60 def stop(id) body = {:id => id} wrap_request(:post, '/v1/apps/stop', :body => body) end
Private Instance Methods
query_params(hash)
click to toggle source
# File lib/marathon/client.rb, line 86 def query_params(hash) hash = hash.select { |k,v| !v.nil? } URI.escape(hash.map { |k,v| "#{k}=#{v}" }.join('&')) end
wrap_request(method, url, options = {})
click to toggle source
# File lib/marathon/client.rb, line 78 def wrap_request(method, url, options = {}) options = @default_options.merge(options) http = self.class.send(method, @host + url, options) Marathon::Response.new(http) rescue => e Marathon::Response.error(e.message) end