Class: Marathon::Client
- Inherits:
-
Object
- Object
- Marathon::Client
- Includes:
- HTTParty
- Defined in:
- lib/marathon/client.rb
Constant Summary collapse
- EDITABLE_APP_ATTRIBUTES =
[ :cmd, :constraints, :container, :cpus, :env, :executor, :id, :instances, :mem, :ports, :uris]
Instance Method Summary collapse
- #deployments ⇒ Object
- #endpoints(id = nil) ⇒ Object
- #find(id) ⇒ Object
- #find_deployment_by_name(name) ⇒ Object
-
#initialize(host = nil, user = nil, pass = nil, proxy = nil) ⇒ Client
constructor
A new instance of Client.
- #kill(id) ⇒ Object
- #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
- #update(id, opts) ⇒ Object
Constructor Details
#initialize(host = nil, user = nil, pass = nil, proxy = nil) ⇒ Client
Returns a new instance of Client.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/marathon/client.rb', line 20 def initialize(host = nil, user = nil, pass = nil, proxy = nil) @host = host || ENV['MARATHON_HOST'] || 'http://localhost:8080' @default_options = {} if user && pass @default_options[:basic_auth] = {:username => user, :password => pass} end if proxy @default_options[:http_proxyaddr] = proxy[:addr] @default_options[:http_proxyport] = proxy[:port] @default_options[:http_proxyuser] = proxy[:user] if proxy[:user] @default_options[:http_proxypass] = proxy[:pass] if proxy[:pass] end end |
Instance Method Details
#deployments ⇒ Object
56 57 58 |
# File 'lib/marathon/client.rb', line 56 def deployments wrap_request(:get, "/v2/deployments") end |
#endpoints(id = nil) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/marathon/client.rb', line 66 def endpoints(id = nil) if id.nil? url = "/v2/tasks" else url = "/v2/apps/#{id}/tasks" end wrap_request(:get, url) end |
#find(id) ⇒ Object
40 41 42 |
# File 'lib/marathon/client.rb', line 40 def find(id) wrap_request(:get, "/v2/apps/#{id}") end |
#find_deployment_by_name(name) ⇒ Object
60 61 62 63 64 |
# File 'lib/marathon/client.rb', line 60 def find_deployment_by_name(name) wrap_request(:get, "/v2/deployments").parsed_response.find do |deployment| deployment['affectedApps'].include?("/#{name}") end end |
#kill(id) ⇒ Object
99 100 101 |
# File 'lib/marathon/client.rb', line 99 def kill(id) wrap_request(:delete, "/v2/apps/#{id}") end |
#kill_tasks(appId, params = {}) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/marathon/client.rb', line 103 def kill_tasks(appId, params = {}) if params[:task_id].nil? wrap_request(:delete, "/v2/apps/#{appId}/tasks?#{query_params(params)}") else query = params.clone task_id = query[:task_id] query.delete(:task_id) wrap_request(:delete, "/v2/apps/#{appId}/tasks/#{task_id}?#{query_params(query)}") end end |
#list ⇒ Object
36 37 38 |
# File 'lib/marathon/client.rb', line 36 def list wrap_request(:get, '/v2/apps') end |
#list_tasks(id) ⇒ Object
44 45 46 |
# File 'lib/marathon/client.rb', line 44 def list_tasks(id) wrap_request(:get, URI.escape("/v2/apps/#{id}/tasks")) end |
#scale(id, num_instances) ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/marathon/client.rb', line 88 def scale(id, num_instances) # Fetch current state and update only the 'instances' attribute. Since the # API only supports PUT, the full representation of the app must be # supplied to update even just a single attribute. app = wrap_request(:get, "/v2/apps/#{id}").parsed_response['app'] app.select! {|k, v| EDITABLE_APP_ATTRIBUTES.include?(k)} app[:instances] = num_instances wrap_request(:put, "/v2/apps/#{id}", :body => app) end |
#search(id = nil, cmd = nil) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/marathon/client.rb', line 48 def search(id = nil, cmd = nil) params = {} params[:id] = id unless id.nil? params[:cmd] = cmd unless cmd.nil? wrap_request(:get, "/v2/apps?#{query_params(params)}") end |
#start(id, opts) ⇒ Object
76 77 78 79 80 |
# File 'lib/marathon/client.rb', line 76 def start(id, opts) body = opts.dup body[:id] = id wrap_request(:post, '/v2/apps/', :body => body) end |
#update(id, opts) ⇒ Object
82 83 84 85 86 |
# File 'lib/marathon/client.rb', line 82 def update(id, opts) body = opts.dup body[:id] = id wrap_request(:put, "/v2/apps/#{id}", :body => body) end |