Class: Marathon::Client
- Inherits:
-
Object
- Object
- Marathon::Client
- Includes:
- HTTParty
- Defined in:
- lib/marathon/client.rb
Instance Method Summary collapse
- #endpoints(id = nil) ⇒ Object
-
#initialize(host = nil, user = nil, pass = nil) ⇒ Client
constructor
A new instance of Client.
- #kill_tasks(appId, params = {}) ⇒ Object
- #list ⇒ Object
- #list_tasks(id) ⇒ Object
- #scale(id, num_instances) ⇒ Object
- #search(id = nil, cmd = nil) ⇒ Object
- #start(id, opts) ⇒ Object
- #stop(id) ⇒ Object
Constructor Details
#initialize(host = nil, user = nil, pass = nil) ⇒ Client
Returns a new instance of Client.
16 17 18 19 20 21 22 23 |
# 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 |
Instance Method Details
#endpoints(id = nil) ⇒ Object
41 42 43 44 45 46 47 |
# 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 = {}) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# 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 ⇒ Object
25 26 27 |
# File 'lib/marathon/client.rb', line 25 def list wrap_request(:get, '/v1/apps') end |
#list_tasks(id) ⇒ Object
29 30 31 |
# 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) ⇒ Object
55 56 57 58 |
# 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) ⇒ Object
33 34 35 36 37 38 39 |
# 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) ⇒ Object
49 50 51 52 53 |
# 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) ⇒ Object
60 61 62 63 |
# File 'lib/marathon/client.rb', line 60 def stop(id) body = {:id => id} wrap_request(:post, '/v1/apps/stop', :body => body) end |