wakame 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +18 -0
- data/README.rdoc +2 -4
- data/Rakefile +4 -1
- data/VERSION +1 -1
- data/app_generators/wakame/templates/config/cluster.rb +36 -0
- data/app_generators/wakame/wakame_generator.rb +1 -0
- data/lib/wakame/action.rb +19 -34
- data/lib/wakame/actions/launch_cluster.rb +6 -3
- data/lib/wakame/actions/launch_vm.rb +57 -0
- data/lib/wakame/actions/migrate_service.rb +6 -25
- data/lib/wakame/actions/propagate_instances.rb +16 -41
- data/lib/wakame/actions/reload_service.rb +2 -2
- data/lib/wakame/actions/shutdown_cluster.rb +4 -0
- data/lib/wakame/actions/start_service.rb +30 -9
- data/lib/wakame/actions/stop_service.rb +1 -4
- data/lib/wakame/actions/util.rb +0 -24
- data/lib/wakame/actor/mysql.rb +106 -0
- data/lib/wakame/actor/service_monitor.rb +10 -0
- data/lib/wakame/actor/system.rb +19 -9
- data/lib/wakame/actor.rb +1 -1
- data/lib/wakame/agent.rb +23 -17
- data/lib/wakame/command/action_status.rb +7 -38
- data/lib/wakame/command/agent_status.rb +18 -0
- data/lib/wakame/command/launch_cluster.rb +0 -4
- data/lib/wakame/command/launch_vm.rb +11 -0
- data/lib/wakame/command/migrate_service.rb +12 -9
- data/lib/wakame/command/propagate_service.rb +15 -7
- data/lib/wakame/command/reload_service.rb +21 -0
- data/lib/wakame/command/shutdown_cluster.rb +0 -5
- data/lib/wakame/command/shutdown_vm.rb +20 -0
- data/lib/wakame/command/status.rb +6 -66
- data/lib/wakame/command/stop_service.rb +31 -0
- data/lib/wakame/command.rb +3 -0
- data/lib/wakame/command_queue.rb +76 -5
- data/lib/wakame/configuration.rb +6 -1
- data/lib/wakame/event.rb +6 -5
- data/lib/wakame/event_dispatcher.rb +5 -3
- data/lib/wakame/initializer.rb +1 -1
- data/lib/wakame/master.rb +14 -10
- data/lib/wakame/monitor/agent.rb +1 -6
- data/lib/wakame/monitor/service.rb +13 -1
- data/lib/wakame/packets.rb +51 -13
- data/lib/wakame/rule_engine.rb +7 -18
- data/lib/wakame/runner/administrator_command.rb +517 -46
- data/lib/wakame/service.rb +104 -173
- data/lib/wakame/trigger.rb +1 -10
- data/lib/wakame/triggers/process_command.rb +9 -2
- data/lib/wakame/util.rb +21 -21
- data/lib/wakame/vm_manipulator.rb +1 -0
- data/tests/test_service.rb +30 -6
- data/wakame_generators/resource/templates/ec2_elb/ec2_elb.rb +80 -0
- data/wakame_generators/resource/templates/mysql_master/conf/my.cnf +3 -1
- data/wakame_generators/resource/templates/mysql_master/init.d/mysql +3 -3
- data/wakame_generators/resource/templates/mysql_master/mysql_master.rb +11 -12
- data/{app_generators/wakame/templates/cluster/resources/mysql_master → wakame_generators/resource/templates/mysql_slave}/conf/my.cnf +19 -9
- data/{app_generators/wakame/templates/cluster/resources/mysql_master/init.d/mysql → wakame_generators/resource/templates/mysql_slave/init.d/mysql-slave} +4 -4
- data/wakame_generators/resource/templates/mysql_slave/mysql_slave.rb +123 -0
- data/wakame_generators/resource/templates/nginx/conf/nginx.conf +166 -0
- data/wakame_generators/resource/templates/nginx/init.d/nginx +70 -0
- data/{app_generators/wakame/templates/cluster/resources/apache_lb/apache_lb.rb → wakame_generators/resource/templates/nginx/nginx.rb} +28 -17
- metadata +46 -27
- data/app_generators/wakame/templates/cluster/resources/apache_app/apache_app.rb +0 -54
- data/app_generators/wakame/templates/cluster/resources/apache_app/conf/apache2.conf +0 -46
- data/app_generators/wakame/templates/cluster/resources/apache_app/conf/envvars-app +0 -7
- data/app_generators/wakame/templates/cluster/resources/apache_app/conf/sites-app.conf +0 -23
- data/app_generators/wakame/templates/cluster/resources/apache_app/conf/system-app.conf +0 -67
- data/app_generators/wakame/templates/cluster/resources/apache_app/init.d/apache2-app +0 -192
- data/app_generators/wakame/templates/cluster/resources/apache_lb/conf/apache2.conf +0 -46
- data/app_generators/wakame/templates/cluster/resources/apache_lb/conf/envvars-lb +0 -6
- data/app_generators/wakame/templates/cluster/resources/apache_lb/conf/sites-lb.conf +0 -54
- data/app_generators/wakame/templates/cluster/resources/apache_lb/conf/system-lb.conf +0 -75
- data/app_generators/wakame/templates/cluster/resources/apache_lb/init.d/apache2-lb +0 -192
- data/app_generators/wakame/templates/cluster/resources/apache_www/apache_www.rb +0 -50
- data/app_generators/wakame/templates/cluster/resources/apache_www/conf/apache2.conf +0 -47
- data/app_generators/wakame/templates/cluster/resources/apache_www/conf/envvars-www +0 -7
- data/app_generators/wakame/templates/cluster/resources/apache_www/conf/sites-www.conf +0 -23
- data/app_generators/wakame/templates/cluster/resources/apache_www/conf/system-www.conf +0 -63
- data/app_generators/wakame/templates/cluster/resources/apache_www/init.d/apache2-www +0 -192
- data/app_generators/wakame/templates/cluster/resources/ec2_elastic_ip/ec2_elastic_ip.rb +0 -39
- data/app_generators/wakame/templates/cluster/resources/mysql_master/mysql_master.rb +0 -174
- data/tests/conf/a +0 -1
- data/tests/conf/b +0 -1
- data/tests/conf/c +0 -1
@@ -1,65 +1,82 @@
|
|
1
1
|
|
2
2
|
require 'uri'
|
3
|
+
require 'cgi'
|
3
4
|
require 'ext/uri'
|
4
5
|
require 'optparse'
|
5
|
-
|
6
|
-
require '
|
7
|
-
|
6
|
+
require 'net/http'
|
7
|
+
require 'json'
|
8
8
|
require 'erb'
|
9
|
-
|
10
9
|
require 'wakame'
|
11
|
-
|
10
|
+
|
11
|
+
#require 'openssl'
|
12
|
+
#require 'base64'
|
12
13
|
|
13
14
|
$root_constants = Module.constants
|
14
15
|
|
15
16
|
module Wakame
|
16
17
|
module Runner
|
17
18
|
class AdministratorCommand
|
18
|
-
|
19
19
|
attr_reader :options
|
20
|
-
|
20
|
+
|
21
21
|
def initialize(args)
|
22
|
-
@args = args.dup
|
23
|
-
|
24
|
-
:command_server_uri => Wakame.config.
|
22
|
+
@args = args.dup
|
23
|
+
@options = {
|
24
|
+
:command_server_uri => Wakame.config.http_command_server_uri
|
25
25
|
}
|
26
|
+
@public_key = "1234567890"
|
26
27
|
end
|
27
28
|
|
28
29
|
def parse(args=@args)
|
29
30
|
args = args.dup
|
30
31
|
|
31
32
|
comm_parser = OptionParser.new { |opts|
|
33
|
+
opts.version = VERSION
|
32
34
|
opts.banner = "Usage: wakameadm [options] command [options]"
|
33
35
|
|
34
36
|
opts.separator ""
|
35
37
|
opts.separator "options:"
|
36
|
-
opts.on( "-s", "--server
|
38
|
+
opts.on( "-s", "--server HttpURI", "command server" ) {|str| @options[:command_server_uri] = str }
|
37
39
|
}
|
38
40
|
|
39
|
-
|
41
|
+
|
40
42
|
comm_parser.order!(args)
|
41
43
|
@options.freeze
|
44
|
+
|
42
45
|
return parse_subcommand(args)
|
43
46
|
end
|
44
47
|
|
45
48
|
def run
|
46
|
-
|
47
|
-
|
49
|
+
req = parse
|
50
|
+
subcommand = req[:command]
|
51
|
+
|
52
|
+
if Wakame.config.enable_authentication == "true"
|
53
|
+
get_params = authentication(req[:command_server_uri], req[:query_string])
|
54
|
+
else
|
55
|
+
get_params = req[:command_server_uri] + req[:query_string]
|
56
|
+
end
|
48
57
|
begin
|
49
|
-
|
50
|
-
|
51
|
-
subcommand = cmd_queue.send_cmd(subcommand)
|
52
|
-
if subcommand.is_a? Exception
|
53
|
-
STDERR.puts subcommand
|
54
|
-
exit 1
|
55
|
-
end
|
56
|
-
#res = cmd_queue.send(subcommand.class.command_name)
|
58
|
+
res = subcommand.run(get_params)
|
59
|
+
res = JSON.parse(res)
|
57
60
|
rescue => e
|
58
|
-
STDERR.puts e
|
61
|
+
res = STDERR.puts e
|
59
62
|
exit 1
|
60
63
|
end
|
61
64
|
|
62
|
-
|
65
|
+
unless req[:json_print].nil?
|
66
|
+
require 'pp'
|
67
|
+
pp res
|
68
|
+
else
|
69
|
+
case res[0]["status"]
|
70
|
+
when 404
|
71
|
+
p "Command Error: #{res[0]["message"]}"
|
72
|
+
when 403
|
73
|
+
p "Authentication Error: #{res[0]["message"]}"
|
74
|
+
when 500
|
75
|
+
p "Server Error: #{res[0]["message"]}"
|
76
|
+
else
|
77
|
+
subcommand.print_result(res)
|
78
|
+
end
|
79
|
+
end
|
63
80
|
end
|
64
81
|
|
65
82
|
private
|
@@ -69,44 +86,498 @@ module Wakame
|
|
69
86
|
if @subcmd.nil?
|
70
87
|
fail "Please pass a sub command."
|
71
88
|
end
|
72
|
-
|
73
89
|
subcommands = {}
|
74
|
-
(Wakame::
|
75
|
-
const = Util.build_const("Wakame::
|
90
|
+
(Wakame::Cli::Subcommand.constants - $root_constants).each { |c|
|
91
|
+
const = Util.build_const("Wakame::Cli::Subcommand::#{c}")
|
76
92
|
if const.is_a?(Class)
|
77
93
|
cmdobj = nil
|
78
94
|
begin
|
79
95
|
cmdobj = const.new
|
80
|
-
raise '' unless cmdobj.kind_of?(Wakame::
|
96
|
+
raise '' unless cmdobj.kind_of?(Wakame::Cli::Subcommand)
|
81
97
|
rescue => e
|
82
98
|
next
|
83
99
|
end
|
84
|
-
|
85
100
|
subcommands[cmdobj.class.command_name] = cmdobj
|
86
101
|
end
|
87
102
|
}
|
88
|
-
|
89
103
|
subcommand = subcommands[@subcmd]
|
90
104
|
fail "No such sub command: #{@subcmd}" if subcommand.nil?
|
91
105
|
|
92
|
-
subcommand.parse(args)
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
106
|
+
options = subcommand.parse(args)
|
107
|
+
query_string = CGI.escape('action') + "=" + CGI.escape(@subcmd) + options[:query].to_s
|
108
|
+
request_params = {
|
109
|
+
:command => subcommand,
|
110
|
+
:command_server_uri => @options[:command_server_uri] + "?",
|
111
|
+
:query_string => query_string,
|
112
|
+
:json_print => options[:json_print]
|
113
|
+
}
|
114
|
+
|
115
|
+
request_params
|
116
|
+
end
|
117
|
+
|
118
|
+
def authentication(uri, query)
|
119
|
+
key = @public_key
|
120
|
+
req = query + "&" + CGI.escape('timestamp') + "=" + CGI.escape(Time.now.utc.strftime("%Y%m%dT%H%M%SZ"))
|
121
|
+
hash = OpenSSL::HMAC::digest(OpenSSL::Digest::SHA256.new, key, req)
|
122
|
+
sign = uri.to_s + req.to_s + "&signature=" + Base64.encode64(hash).gsub(/\+/, "").gsub(/\n/, "").to_s
|
123
|
+
sign
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
module Cli
|
129
|
+
module Subcommand
|
130
|
+
class CommandArgumentError < StandardError; end
|
131
|
+
|
132
|
+
def self.included(klass)
|
133
|
+
klass.class_eval {
|
134
|
+
class << self
|
135
|
+
def command_name
|
136
|
+
@command_name ||= Util.snake_case(self.to_s.split('::').last)
|
137
|
+
end
|
138
|
+
|
139
|
+
def command_name=(name)
|
140
|
+
@command_name=name
|
141
|
+
end
|
142
|
+
end
|
143
|
+
}
|
108
144
|
end
|
109
145
|
|
146
|
+
def parse(args)
|
147
|
+
end
|
148
|
+
|
149
|
+
def run(options)
|
150
|
+
end
|
151
|
+
|
152
|
+
def print_result(res)
|
153
|
+
end
|
154
|
+
|
155
|
+
def create_parser(args,&blk)
|
156
|
+
parser = OptionParser.new(&blk)
|
157
|
+
parser.order!(args)
|
158
|
+
parser
|
159
|
+
end
|
160
|
+
|
161
|
+
def uri(options)
|
162
|
+
uri = options
|
163
|
+
res = Net::HTTP.get(URI.parse("#{uri}"))
|
164
|
+
return res
|
165
|
+
end
|
166
|
+
|
167
|
+
def summary
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
class Wakame::Cli::Subcommand::LaunchCluster
|
174
|
+
include Wakame::Cli::Subcommand
|
175
|
+
|
176
|
+
#command_name = 'launch_cluster'
|
177
|
+
def parse(args)
|
178
|
+
blk = Proc.new {|opts|
|
179
|
+
opts.banner = "Usage: launch_cluster [options]"
|
180
|
+
opts.separator ""
|
181
|
+
opts.separator "options:"
|
182
|
+
}
|
183
|
+
cmd = create_parser(args, &blk)
|
184
|
+
options = {}
|
185
|
+
options
|
186
|
+
end
|
187
|
+
|
188
|
+
def run(options)
|
189
|
+
res = uri(options)
|
190
|
+
res
|
191
|
+
end
|
192
|
+
|
193
|
+
def print_result(res)
|
194
|
+
p res[0]["message"]
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
class Wakame::Cli::Subcommand::ShutdownCluster
|
199
|
+
include Wakame::Cli::Subcommand
|
200
|
+
|
201
|
+
def parse(args)
|
202
|
+
blk = Proc.new {|opts|
|
203
|
+
opts.banner = "Usage: shutdown_cluster"
|
204
|
+
opts.separator ""
|
205
|
+
opts.separator "options:"
|
206
|
+
}
|
207
|
+
cmd = create_parser(args, &blk)
|
208
|
+
options = {}
|
209
|
+
options
|
210
|
+
end
|
211
|
+
|
212
|
+
def run(options)
|
213
|
+
res = uri(options)
|
214
|
+
res
|
215
|
+
end
|
216
|
+
|
217
|
+
def print_result(res)
|
218
|
+
p res[0]["message"]
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
class Wakame::Cli::Subcommand::Status
|
223
|
+
include Wakame::Cli::Subcommand
|
224
|
+
|
225
|
+
STATUS_TMPL = <<__E__
|
226
|
+
Cluster : <%= @service_cluster["name"].to_s %> (<%= @service_cluster["status"].to_s %>)
|
227
|
+
<%- @service_cluster["properties"].each { |prop, v| -%>
|
228
|
+
<%= v["type"].to_s %> : <current=<%= v["instance_count"] %> min=<%= v["min_instances"] %>, max=<%= v["max_instances"] %><%= v["require_agent"] ? "" : ", AgentLess" %>>
|
229
|
+
<%- v["instances"].each { |id|
|
230
|
+
svc_inst = @service_cluster["instances"][id]
|
231
|
+
-%>
|
232
|
+
<%= svc_inst["instance_id"] %> (<%= trans_svc_status(svc_inst["status"]) %>)
|
233
|
+
<%- } -%>
|
234
|
+
<%- } -%>
|
235
|
+
<%- if @service_cluster["instances"].size > 0 -%>
|
236
|
+
|
237
|
+
Instances :
|
238
|
+
<%- @service_cluster["instances"].each { |k, v| -%>
|
239
|
+
<%= v["instance_id"] %> : <%= v["property"] %> (<%= trans_svc_status(v["status"]) %>)
|
240
|
+
<%- if v["agent_id"] -%>
|
241
|
+
On VM instance: <%= v["agent_id"]%>
|
242
|
+
<%- end -%>
|
243
|
+
<%- } -%>
|
244
|
+
<%- end -%>
|
245
|
+
<%- if @agent_monitor["registered"].size > 0 -%>
|
246
|
+
|
247
|
+
Agents :
|
248
|
+
<%- @agent_monitor["registered"].each { |a| -%>
|
249
|
+
<%= a["agent_id"] %> : <%= a["attr"]["local_ipv4"] %>, <%= a["attr"]["public_ipv4"] %> load=<%= a["attr"]["uptime"] %>, <%= (Time.now - Time.parse(a["last_ping_at"])).to_i %> sec(s), placement=<%= a["attr"]["availability_zone"] %><%= a["root_path"] %> (<%= a["status"] %>)
|
250
|
+
<%- if !a["services"].nil? && a["services"].size > 0 && !@service_cluster["instances"].empty? -%>
|
251
|
+
Services (<%= a["services"].size %>): <%= a["services"].collect{|id| @service_cluster["instances"][id]["property"] unless @service_cluster["instances"][id].nil? }.join(', ') %>
|
252
|
+
<%- end -%>
|
253
|
+
<%- } -%>
|
254
|
+
<%- end -%>
|
255
|
+
__E__
|
256
|
+
|
257
|
+
SVC_STATUS_MSG={
|
258
|
+
Wakame::Service::STATUS_OFFLINE=>'Offline',
|
259
|
+
Wakame::Service::STATUS_ONLINE=>'ONLINE',
|
260
|
+
Wakame::Service::STATUS_UNKNOWN=>'Unknown',
|
261
|
+
Wakame::Service::STATUS_FAIL=>'Fail',
|
262
|
+
Wakame::Service::STATUS_STARTING=>'Starting...',
|
263
|
+
Wakame::Service::STATUS_STOPPING=>'Stopping...',
|
264
|
+
Wakame::Service::STATUS_RELOADING=>'Reloading...',
|
265
|
+
Wakame::Service::STATUS_MIGRATING=>'Migrating...',
|
266
|
+
}
|
267
|
+
|
268
|
+
def parse(args)
|
269
|
+
options = {}
|
270
|
+
blk = Proc.new {|opts|
|
271
|
+
opts.banner = "Usage: status [options]"
|
272
|
+
opts.separator ""
|
273
|
+
opts.separator "options:"
|
274
|
+
opts.on("--dump"){|j| options[:json_print] = "yes" }
|
275
|
+
}
|
276
|
+
cmd = create_parser(args, &blk)
|
277
|
+
options
|
278
|
+
end
|
279
|
+
|
280
|
+
def run(options)
|
281
|
+
res = uri(options)
|
282
|
+
res
|
283
|
+
end
|
284
|
+
|
285
|
+
def print_result(res)
|
286
|
+
require 'time'
|
287
|
+
if res[1]["data"].nil?
|
288
|
+
p res[0]["message"]
|
289
|
+
else
|
290
|
+
@service_cluster = res[1]["data"]["service_cluster"]
|
291
|
+
@agent_monitor = res[1]["data"]["agent_monitor"]
|
292
|
+
puts ERB.new(STATUS_TMPL, nil, '-').result(binding)
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
private
|
297
|
+
def trans_svc_status(stat)
|
298
|
+
SVC_STATUS_MSG[stat]
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
class Wakame::Cli::Subcommand::ActionStatus
|
303
|
+
include Wakame::Cli::Subcommand
|
304
|
+
|
305
|
+
ACTION_STATUS_TMPL= <<__E__
|
306
|
+
Running Actions : <%= @status.size %> action(s)
|
307
|
+
<%- if @status.size > 0 -%>
|
308
|
+
<%- @status.each { |id, j| -%>
|
309
|
+
JOB <%= id %> :
|
310
|
+
start : <%= j["created_at"] %>
|
311
|
+
<%= tree_subactions(j["root_action"]) %>
|
312
|
+
<%- } -%>
|
313
|
+
<%- end -%>
|
314
|
+
__E__
|
315
|
+
|
316
|
+
def parse(args)
|
317
|
+
options = {}
|
318
|
+
blk = Proc.new {|opts|
|
319
|
+
opts.banner = "Usage: action_status"
|
320
|
+
opts.separator ""
|
321
|
+
opts.separator "options:"
|
322
|
+
opts.on("--dump"){|j| options[:json_print] = "yes" }
|
323
|
+
}
|
324
|
+
cmd = create_parser(args, &blk)
|
325
|
+
options
|
326
|
+
end
|
327
|
+
|
328
|
+
def run(options)
|
329
|
+
res = uri(options)
|
330
|
+
res
|
331
|
+
end
|
332
|
+
|
333
|
+
def print_result(res)
|
334
|
+
if res[1]["data"].nil?
|
335
|
+
p res[0]["message"]
|
336
|
+
else
|
337
|
+
@status = res[1]['data']
|
338
|
+
puts ERB.new(ACTION_STATUS_TMPL, nil, '-').result(binding)
|
110
339
|
end
|
111
340
|
end
|
341
|
+
|
342
|
+
private
|
343
|
+
def tree_subactions(root, level=0)
|
344
|
+
str= (" " * level) + "#{root["type"]} (#{root["status"]})"
|
345
|
+
unless root["subactions"].nil?
|
346
|
+
root["subactions"].each { |a|
|
347
|
+
str << "\n "
|
348
|
+
str << tree_subactions(a, level + 1)
|
349
|
+
}
|
350
|
+
end
|
351
|
+
str
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
class Wakame::Cli::Subcommand::PropagateService
|
356
|
+
include Wakame::Cli::Subcommand
|
357
|
+
|
358
|
+
def parse(args)
|
359
|
+
params = {}
|
360
|
+
blk = Proc.new {|opts|
|
361
|
+
opts.banner = "Usage: propagate_service"
|
362
|
+
opts.separator ""
|
363
|
+
opts.separator "options:"
|
364
|
+
opts.on("-s SERVICE_NAME", "--service SERVICE_NAME"){|str| params[:service] = str}
|
365
|
+
opts.on("-n NUMBER", "--number NUMBER"){|i| params["num"] = i}
|
366
|
+
}
|
367
|
+
cmd = create_parser(args, &blk)
|
368
|
+
options = {}
|
369
|
+
options[:query] = "&" + params.collect{|k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v)}"}.join("&")
|
370
|
+
options
|
371
|
+
end
|
372
|
+
|
373
|
+
def run(options)
|
374
|
+
res = uri(options)
|
375
|
+
res
|
376
|
+
end
|
377
|
+
|
378
|
+
def print_result(res)
|
379
|
+
p res[0]["message"]
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
class Wakame::Cli::Subcommand::StopService
|
384
|
+
include Wakame::Cli::Subcommand
|
385
|
+
|
386
|
+
def parse(args)
|
387
|
+
params = {}
|
388
|
+
blk = Proc.new {|opts|
|
389
|
+
opts.banner = "Usage: stop_service [options] \"Service ID\""
|
390
|
+
opts.separator ""
|
391
|
+
opts.separator "options:"
|
392
|
+
opts.on("-i INSTANCE_ID", "--instance INSTANCE_ID"){|i| params[:service_id] = i}
|
393
|
+
opts.on("-s SERVICE_NAME", "--service SERVICE_NAME"){|str| params[:service_name] = str}
|
394
|
+
opts.on("-a AGENT_ID", "--agent AGENT_ID"){|i| params[:agent_id] = i}
|
395
|
+
}
|
396
|
+
cmd = create_parser(args, &blk)
|
397
|
+
options = {}
|
398
|
+
options[:query] = "&" + params.collect{|k,v| CGI.escape(k.to_s) + "=" + CGI.escape(v)}.join("&")
|
399
|
+
options
|
400
|
+
end
|
401
|
+
|
402
|
+
def run(options)
|
403
|
+
res = uri(options)
|
404
|
+
res
|
405
|
+
end
|
406
|
+
|
407
|
+
def print_result(res)
|
408
|
+
p res[0]["message"]
|
409
|
+
end
|
410
|
+
end
|
411
|
+
|
412
|
+
class Wakame::Cli::Subcommand::MigrateService
|
413
|
+
include Wakame::Cli::Subcommand
|
414
|
+
def parse(args)
|
415
|
+
params = {}
|
416
|
+
blk = Proc.new {|opts|
|
417
|
+
opts.banner = "Usage: migrate_service [options] \"Service ID\""
|
418
|
+
opts.separator ""
|
419
|
+
opts.separator "options:"
|
420
|
+
opts.on("-a Agent ID", "--agent Agent ID"){ |i| params[:agent_id] = i}
|
421
|
+
}
|
422
|
+
cmd = create_parser(args, &blk)
|
423
|
+
service_id = args.shift || abort("[ERROR]: Service ID was not given")
|
424
|
+
params[:service_id] = service_id
|
425
|
+
options = {}
|
426
|
+
options[:query] = "&" + params.collect{|k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v)}"}.join("&")
|
427
|
+
options
|
428
|
+
end
|
429
|
+
|
430
|
+
def run(options)
|
431
|
+
res = uri(options)
|
432
|
+
res
|
433
|
+
end
|
434
|
+
|
435
|
+
def print_result(res)
|
436
|
+
p res[0]["message"]
|
437
|
+
end
|
112
438
|
end
|
439
|
+
|
440
|
+
class Wakame::Cli::Subcommand::ShutdownVm
|
441
|
+
include Wakame::Cli::Subcommand
|
442
|
+
|
443
|
+
def parse(args)
|
444
|
+
params = {}
|
445
|
+
blk = Proc.new {|opts|
|
446
|
+
opts.banner = "Usage: shutdown_vm [options] \"Agent ID\""
|
447
|
+
opts.separator ""
|
448
|
+
opts.separator "options:"
|
449
|
+
opts.on("-f", "--force"){|str| params[:force] = "yes"}
|
450
|
+
}
|
451
|
+
cmd = create_parser(args, &blk)
|
452
|
+
agent_id = args.shift || abort("[ERROR]: Agent ID was not given")
|
453
|
+
params[:agent_id] = agent_id
|
454
|
+
options = {}
|
455
|
+
options[:query] = "&" + params.collect{|k,v| CGI.escape(k.to_s) + "=" + CGI.escape(v)}.join("&")
|
456
|
+
options
|
457
|
+
end
|
458
|
+
|
459
|
+
def run(options)
|
460
|
+
res = uri(options)
|
461
|
+
res
|
462
|
+
end
|
463
|
+
|
464
|
+
def print_result(res)
|
465
|
+
p res[0]["message"]
|
466
|
+
end
|
467
|
+
end
|
468
|
+
|
469
|
+
class Wakame::Cli::Subcommand::LaunchVm
|
470
|
+
include Wakame::Cli::Subcommand
|
471
|
+
|
472
|
+
def parse(args)
|
473
|
+
blk = Proc.new {|opts|
|
474
|
+
opts.banner = "Usage: launch_vm"
|
475
|
+
opts.separator ""
|
476
|
+
opts.separator "options:"
|
477
|
+
}
|
478
|
+
cmd = create_parser(args, &blk)
|
479
|
+
options = {}
|
480
|
+
options
|
481
|
+
end
|
482
|
+
|
483
|
+
def run(options)
|
484
|
+
res = uri(options)
|
485
|
+
res
|
486
|
+
end
|
487
|
+
|
488
|
+
def print_result(res)
|
489
|
+
p res[0]["message"]
|
490
|
+
end
|
491
|
+
end
|
492
|
+
|
493
|
+
class Wakame::Cli::Subcommand::ReloadService
|
494
|
+
include Wakame::Cli::Subcommand
|
495
|
+
|
496
|
+
def parse(args)
|
497
|
+
params = {}
|
498
|
+
blk = Proc.new {|opts|
|
499
|
+
opts.banner = "Usage: ReloadService [options] \"Service NAME\""
|
500
|
+
opts.separator ""
|
501
|
+
opts.separator "options:"
|
502
|
+
}
|
503
|
+
cmd = create_parser(args, &blk)
|
504
|
+
service_name = args.shift || abort("[ERROR]: Service NAME was not given")
|
505
|
+
params[:service_name] = service_name
|
506
|
+
options = {}
|
507
|
+
options[:query] = "&" + params.collect{|k,v| CGI.escape(k.to_s) + "=" + CGI.escape(v)}.join("&")
|
508
|
+
options
|
509
|
+
end
|
510
|
+
|
511
|
+
def run(options)
|
512
|
+
res = uri(options)
|
513
|
+
res
|
514
|
+
end
|
515
|
+
|
516
|
+
def print_result(res)
|
517
|
+
p res[0]["message"]
|
518
|
+
end
|
519
|
+
end
|
520
|
+
|
521
|
+
class Wakame::Cli::Subcommand::AgentStatus
|
522
|
+
include Wakame::Cli::Subcommand
|
523
|
+
|
524
|
+
STATUS_TMPL = <<__E__
|
525
|
+
Agent :<%= @agent["agent_id"]%> load=<%= @agent["attr"]["uptime"]%>, <%= (Time.now - Time.parse(@agent["last_ping_at"])).to_i%> sec(s), placement=<%= @agent["attr"]["availability_zone"]%><%= @agent["root_path"] %> (<%= trans_svc_status(@agent["status"]) %>)
|
526
|
+
Instance ID : <%= @agent["attr"]["instance_id"]%>
|
527
|
+
AMI ID : <%= @agent["attr"]["ami_id"]%>
|
528
|
+
Public DNS Name : <%= @agent["attr"]["public_hostname"]%>
|
529
|
+
Private DNS Name : <%= @agent["attr"]["local_hostname"]%>
|
530
|
+
Instance Type : <%= @agent["attr"]["instance_type"]%>
|
531
|
+
Availability Zone : <%= @agent["attr"]["availability_zone"]%>
|
532
|
+
|
533
|
+
<%- if !@agent["services"].nil? && @agent["services"].size > 0 -%>
|
534
|
+
Services (<%= @agent["services"].size%>):
|
535
|
+
<%- @agent["services"].each {|id| -%>
|
536
|
+
<%= @service_cluster["instances"][id]["instance_id"]%> : <%= @service_cluster["instances"][id]["property"]%> (<%= trans_svc_status(@service_cluster["instances"][id]["status"])%>)
|
537
|
+
<%- } -%>
|
538
|
+
<%- end -%>
|
539
|
+
__E__
|
540
|
+
|
541
|
+
SVC_STATUS_MSG={
|
542
|
+
Wakame::Service::STATUS_OFFLINE=>'Offline',
|
543
|
+
Wakame::Service::STATUS_ONLINE=>'ONLINE',
|
544
|
+
Wakame::Service::STATUS_UNKNOWN=>'Unknown',
|
545
|
+
Wakame::Service::STATUS_FAIL=>'Fail',
|
546
|
+
Wakame::Service::STATUS_STARTING=>'Starting...',
|
547
|
+
Wakame::Service::STATUS_STOPPING=>'Stopping...',
|
548
|
+
Wakame::Service::STATUS_RELOADING=>'Reloading...',
|
549
|
+
Wakame::Service::STATUS_MIGRATING=>'Migrating...',
|
550
|
+
}
|
551
|
+
|
552
|
+
def parse(args)
|
553
|
+
params = {}
|
554
|
+
blk = Proc.new {|opts|
|
555
|
+
opts.banner = "Usage: AgentStatus [options] \"Agent ID\""
|
556
|
+
opts.separator ""
|
557
|
+
opts.separator "options:"
|
558
|
+
}
|
559
|
+
cmd = create_parser(args, &blk)
|
560
|
+
agent_id = args.shift || abort("[ERROR]: Agent ID was not given")
|
561
|
+
params[:agent_id] = agent_id
|
562
|
+
options = {}
|
563
|
+
options[:query] = "&" + params.collect{|k,v| CGI.escape(k.to_s) + "=" + CGI.escape(v)}.join("&")
|
564
|
+
options
|
565
|
+
end
|
566
|
+
|
567
|
+
def run(options)
|
568
|
+
res = uri(options)
|
569
|
+
res
|
570
|
+
end
|
571
|
+
|
572
|
+
def print_result(res)
|
573
|
+
require 'time'
|
574
|
+
@agent = res[1]["data"]["agent_status"]
|
575
|
+
@service_cluster = res[1]["data"]["service_cluster"]
|
576
|
+
puts ERB.new(STATUS_TMPL, nil, '-').result(binding)
|
577
|
+
end
|
578
|
+
|
579
|
+
private
|
580
|
+
def trans_svc_status(stat)
|
581
|
+
SVC_STATUS_MSG[stat]
|
582
|
+
end
|
583
|
+
end
|