haile 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/haile +32 -22
- data/lib/haile/client.rb +32 -7
- data/lib/haile/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34e96756dc75b2ef9a5c9b9e543774571ed8e5fb
|
4
|
+
data.tar.gz: b379a6c252dda1fead8179c923ae10733294ef70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c82ef99476bf387e6d77804ef41880c38151cd73344ddb9b9705ca48f0df883e534f57907b731ede634b593705cc1666aca80bda5f5d7a1a2eb8528699be6502
|
7
|
+
data.tar.gz: 65018902d2629d32fd3afd2a5f56c031dc3303be18121c4ca6ecbf663370903c5bf37099f0954ad5d3aa97fee38165aabe80cba78cca92bb777f9f2929c60d62
|
data/bin/haile
CHANGED
@@ -1,29 +1,30 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', '
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'haile'))
|
4
4
|
require 'trollop'
|
5
5
|
|
6
|
-
SUB_COMMANDS = %w[endpoints kill kill_tasks start scale list list_tasks search]
|
6
|
+
SUB_COMMANDS = %w[endpoints kill kill_tasks start scale list list_tasks search docker_deploy]
|
7
7
|
|
8
8
|
global_opts = Trollop.options do
|
9
|
-
version
|
9
|
+
version Haile::VERSION
|
10
10
|
banner <<-EOS
|
11
|
-
Usage:
|
11
|
+
Usage: haile [global options] [command] [options]
|
12
12
|
|
13
13
|
Available commands:
|
14
14
|
|
15
|
-
kill
|
16
|
-
kill_tasks
|
17
|
-
list
|
18
|
-
list_tasks
|
19
|
-
scale
|
20
|
-
search
|
21
|
-
start
|
15
|
+
kill Kill an app and remove it from Marathon.
|
16
|
+
kill_tasks Kill a task or tasks belonging to a specified app.
|
17
|
+
list Show a list of running apps and their options.
|
18
|
+
list_tasks Show a list of an app's running tasks.
|
19
|
+
scale Scale the number of app instances.
|
20
|
+
search Search the current list of apps.
|
21
|
+
start Start a new app.
|
22
|
+
docker_deploy Update the docker image tag of an app.
|
22
23
|
|
23
24
|
Global options:
|
24
25
|
EOS
|
25
26
|
|
26
|
-
opt :
|
27
|
+
opt :marathon_url, 'Marathon URL (default http://localhost:8080, or MARATHON_URL)', :short => '-R', :type => String
|
27
28
|
opt :marathon_user, 'User name to authenticate against Marathon (optional).', :short => '-U', :type => String
|
28
29
|
opt :marathon_pass, 'Password to authenticate against Marathon (optional).', :short => '-P', :type => String
|
29
30
|
stop_on SUB_COMMANDS
|
@@ -73,12 +74,17 @@ cmd_opts = case cmd
|
|
73
74
|
opt :id, 'A unique identifier for the app.', :short => '-i', :type => String, :default => nil
|
74
75
|
opt :command, 'The command for the app.', :short => '-C', :type => String, :default => nil
|
75
76
|
end
|
77
|
+
when 'docker_deploy'
|
78
|
+
Trollop.options do
|
79
|
+
opt :id, 'A unique identifier for the app.', :required => true, :short => '-i', :type => String
|
80
|
+
opt :docker_image, 'The docker image:tag to update to.', :required => true, :short => '-d', :type => String
|
81
|
+
end
|
76
82
|
else
|
77
83
|
{}
|
78
84
|
end
|
79
85
|
|
80
|
-
|
81
|
-
global_opts[:
|
86
|
+
haile = Haile::Client.new(
|
87
|
+
global_opts[:marathon_url],
|
82
88
|
global_opts[:marathon_user],
|
83
89
|
global_opts[:marathon_pass]
|
84
90
|
)
|
@@ -117,7 +123,7 @@ end
|
|
117
123
|
# Run
|
118
124
|
case cmd
|
119
125
|
when 'endpoints'
|
120
|
-
puts
|
126
|
+
puts haile.endpoints(cmd_opts[:id]).parsed_response
|
121
127
|
when 'start'
|
122
128
|
app_opts = {
|
123
129
|
:instances => cmd_opts[:num_instances] || 1,
|
@@ -130,27 +136,31 @@ when 'start'
|
|
130
136
|
}
|
131
137
|
app_opts[:executor] = cmd_opts[:executor] unless cmd_opts[:executor] == nil
|
132
138
|
puts "Starting app '#{cmd_opts[:id]}'"
|
133
|
-
puts
|
139
|
+
puts haile.start(cmd_opts[:id], app_opts)
|
134
140
|
when 'scale'
|
135
141
|
puts "Scaling app '#{cmd_opts[:id]}' to #{cmd_opts[:num_instances]} instances"
|
136
|
-
res =
|
142
|
+
res = haile.scale(cmd_opts[:id], cmd_opts[:num_instances])
|
143
|
+
puts res
|
144
|
+
when 'docker_deploy'
|
145
|
+
puts "Deploying app '#{cmd_opts[:id]}' to #{cmd_opts[:docker_image]}"
|
146
|
+
res = haile.docker_deploy(cmd_opts[:id], cmd_opts[:docker_image])
|
137
147
|
puts res
|
138
148
|
when 'kill'
|
139
149
|
puts "Killing app '#{cmd_opts[:id]}'"
|
140
|
-
puts
|
150
|
+
puts haile.kill(cmd_opts[:id])
|
141
151
|
when 'kill_tasks'
|
142
152
|
KILL_TASKS_KEYS = [:host, :scale, :task_id]
|
143
153
|
|
144
154
|
opts = cmd_opts.clone
|
145
155
|
opts.select! {|k, v| KILL_TASKS_KEYS.include?(k)}
|
146
156
|
|
147
|
-
puts
|
157
|
+
puts haile.kill_tasks(cmd_opts[:id], opts).parsed_response
|
148
158
|
when 'list'
|
149
|
-
handle_listing(
|
159
|
+
handle_listing(haile.list)
|
150
160
|
when 'list_tasks'
|
151
|
-
puts
|
161
|
+
puts haile.list_tasks(cmd_opts[:id]).parsed_response
|
152
162
|
when 'search'
|
153
|
-
handle_listing(
|
163
|
+
handle_listing(haile.search(cmd_opts[:id], cmd_opts[:command]))
|
154
164
|
else
|
155
165
|
Trollop.die "unknown subcommand #{cmd.inspect}"
|
156
166
|
end
|
data/lib/haile/client.rb
CHANGED
@@ -13,9 +13,9 @@ module Haile
|
|
13
13
|
maintain_method_across_redirects
|
14
14
|
default_timeout 5
|
15
15
|
|
16
|
-
EDITABLE_APP_ATTRIBUTES =
|
17
|
-
|
18
|
-
|
16
|
+
EDITABLE_APP_ATTRIBUTES = %w(
|
17
|
+
cmd constraints container cpus env executor id instances mem ports uris
|
18
|
+
)
|
19
19
|
|
20
20
|
def initialize(url = nil, user = nil, pass = nil, proxy = nil)
|
21
21
|
@host = url || ENV['MARATHON_URL'] || 'http://localhost:8080'
|
@@ -65,6 +65,25 @@ module Haile
|
|
65
65
|
wrap_request(:post, '/v2/apps/', :body => body)
|
66
66
|
end
|
67
67
|
|
68
|
+
def docker_deploy(id, image)
|
69
|
+
# Fetch current state and update only the 'container['docker']['image']'
|
70
|
+
# attribute. Since the API only supports PUT, the full representation
|
71
|
+
# of the app must be supplied to update even just a single attribute.
|
72
|
+
|
73
|
+
app = wrap_request(:get, "/v2/apps/#{id}").parsed_response['app']
|
74
|
+
app.select! {|k, v| EDITABLE_APP_ATTRIBUTES.include?(k)}
|
75
|
+
|
76
|
+
begin
|
77
|
+
app['container']['docker']['image'] = image
|
78
|
+
rescue
|
79
|
+
msg = "App doesn't have a docker image configured. Make sure " \
|
80
|
+
"the ID is correct and that this app is already configured " \
|
81
|
+
"with a docker image."
|
82
|
+
return Haile::Response.error(msg)
|
83
|
+
end
|
84
|
+
wrap_request(:put, "/v2/apps/#{id}", :body => app)
|
85
|
+
end
|
86
|
+
|
68
87
|
def scale(id, num_instances)
|
69
88
|
# Fetch current state and update only the 'instances' attribute. Since the
|
70
89
|
# API only supports PUT, the full representation of the app must be
|
@@ -72,7 +91,7 @@ module Haile
|
|
72
91
|
app = wrap_request(:get, "/v2/apps/#{id}").parsed_response['app']
|
73
92
|
app.select! {|k, v| EDITABLE_APP_ATTRIBUTES.include?(k)}
|
74
93
|
|
75
|
-
app[
|
94
|
+
app['instances'] = num_instances
|
76
95
|
wrap_request(:put, "/v2/apps/#{id}", :body => app)
|
77
96
|
end
|
78
97
|
|
@@ -96,10 +115,16 @@ module Haile
|
|
96
115
|
|
97
116
|
def wrap_request(method, url, options = {})
|
98
117
|
options = @default_options.merge(options)
|
99
|
-
|
100
|
-
|
118
|
+
if method == :get
|
119
|
+
puts "GET"
|
120
|
+
http = self.class.send(method, @host + url, options)
|
121
|
+
return Haile::Response.new(http)
|
122
|
+
else
|
123
|
+
puts "#{method} #{@host + url} #{options}"
|
124
|
+
return
|
125
|
+
end
|
101
126
|
rescue => e
|
102
|
-
|
127
|
+
Haile::Response.error(e.message)
|
103
128
|
end
|
104
129
|
|
105
130
|
def query_params(hash)
|
data/lib/haile/version.rb
CHANGED