ubalo 0.5 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/ubalo +24 -18
- data/lib/ubalo/account.rb +13 -2
- data/lib/ubalo/pod.rb +31 -1
- data/lib/ubalo/pod_dir.rb +24 -0
- data/lib/ubalo/task.rb +6 -1
- data/lib/ubalo/util.rb +7 -1
- data/lib/ubalo/version.rb +5 -1
- metadata +13 -18
data/bin/ubalo
CHANGED
@@ -19,7 +19,10 @@ end
|
|
19
19
|
|
20
20
|
use_openstruct true
|
21
21
|
|
22
|
-
|
22
|
+
|
23
|
+
def logger
|
24
|
+
@logger ||= Ubalo::Util::Logger.new
|
25
|
+
end
|
23
26
|
|
24
27
|
def connect_url
|
25
28
|
@connect_url
|
@@ -61,6 +64,7 @@ end
|
|
61
64
|
desc 'Display authentication information'
|
62
65
|
command :whoami do |c|
|
63
66
|
c.action do |global_options,options,args|
|
67
|
+
account.refresh!
|
64
68
|
puts "You are logged in as #{account.username}."
|
65
69
|
end
|
66
70
|
end
|
@@ -120,13 +124,10 @@ command :clone do |c|
|
|
120
124
|
end
|
121
125
|
|
122
126
|
desc 'Delete a pod'
|
123
|
-
|
124
|
-
command :delete do |c|
|
127
|
+
command 'pod:delete' do |c|
|
125
128
|
c.switch :force
|
126
129
|
|
127
130
|
c.action do |global_options,options,args|
|
128
|
-
pod = account.pod_by_name!(args.shift)
|
129
|
-
|
130
131
|
if options.force
|
131
132
|
pod.delete!
|
132
133
|
else
|
@@ -154,7 +155,7 @@ command :init do |c|
|
|
154
155
|
c.action do |global_options,options,args|
|
155
156
|
name = options[:name] || hl.ask(" pod name: "){|q| q.echo = true}
|
156
157
|
pod = account.pod_or_create_by_name!(name)
|
157
|
-
pod_dir.
|
158
|
+
pod_dir.init(pod.fullname, logger)
|
158
159
|
logger.puts "Success! Next, run ubalo push."
|
159
160
|
end
|
160
161
|
end
|
@@ -172,6 +173,13 @@ command :run do |c|
|
|
172
173
|
end
|
173
174
|
end
|
174
175
|
|
176
|
+
desc 'Show information about a pod'
|
177
|
+
command :pod do |c|
|
178
|
+
c.action do |global_options,options,args|
|
179
|
+
puts pod.printable_result
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
175
183
|
desc 'Run a pod in the background'
|
176
184
|
command :submit do |c|
|
177
185
|
c.action do |global_options,options,args|
|
@@ -186,13 +194,12 @@ desc 'Get the status of a task'
|
|
186
194
|
arg_name '<task label>'
|
187
195
|
command :task do |c|
|
188
196
|
c.action do |global_options,options,args|
|
189
|
-
|
190
|
-
|
197
|
+
if label = args.shift
|
198
|
+
task = account.task_by_label!(label)
|
199
|
+
else
|
200
|
+
task = pod.latest_task
|
191
201
|
end
|
192
|
-
|
193
|
-
logger.print "Getting the status for task #{task.label.inspect}..."
|
194
|
-
task.refresh!
|
195
|
-
logger.puts " found."
|
202
|
+
|
196
203
|
puts task.printable_result
|
197
204
|
end
|
198
205
|
end
|
@@ -207,6 +214,7 @@ command :push do |c|
|
|
207
214
|
pod.refresh!
|
208
215
|
pod.compiled?
|
209
216
|
end
|
217
|
+
puts pod.printable_result
|
210
218
|
end
|
211
219
|
end
|
212
220
|
|
@@ -234,16 +242,14 @@ end
|
|
234
242
|
on_error do |exception|
|
235
243
|
logger.complete_line
|
236
244
|
case exception
|
237
|
-
when Ubalo::Error, GLI::
|
245
|
+
when Ubalo::Error, GLI::BadCommandLine
|
238
246
|
logger.complete_line
|
239
|
-
|
240
|
-
exit 1
|
247
|
+
abort("Error: #{exception.message}")
|
241
248
|
when Interrupt
|
242
249
|
logger.complete_line
|
243
|
-
|
244
|
-
exit 1
|
250
|
+
abort("Cancelled!")
|
245
251
|
else
|
246
|
-
raise
|
252
|
+
raise exception
|
247
253
|
end
|
248
254
|
end
|
249
255
|
|
data/lib/ubalo/account.rb
CHANGED
@@ -12,20 +12,26 @@ module Ubalo
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def request method, path = nil, options = {}
|
15
|
-
if authorization
|
15
|
+
if authorization and !options[:skip_authorization]
|
16
16
|
options[:authorization] = authorization
|
17
17
|
end
|
18
18
|
Util.http_request(method, "#{@base_url}#{path}", options)
|
19
19
|
end
|
20
20
|
|
21
21
|
def authorize(login, password)
|
22
|
-
response = request(:post, "/user/authorization", :params => {:user => {:login => login, :password => password}})
|
22
|
+
response = request(:post, "/user/authorization", :params => {:user => {:login => login, :password => password}}, :skip_authorization => true)
|
23
23
|
@username = response.fetch("username")
|
24
24
|
@authorization = response.fetch("authorization")
|
25
25
|
rescue RestClient::BadRequest
|
26
26
|
raise Ubalo::Error, "Incorrect login or password"
|
27
27
|
end
|
28
28
|
|
29
|
+
def refresh!
|
30
|
+
update_attributes(request(:get, "/users/#{username}"))
|
31
|
+
rescue RestClient::ResourceNotFound
|
32
|
+
raise Ubalo::Error, "Your credentials for #{username} are invalid"
|
33
|
+
end
|
34
|
+
|
29
35
|
def pod_from_json(pod_json)
|
30
36
|
Pod.create_with_json(self, pod_json)
|
31
37
|
end
|
@@ -74,5 +80,10 @@ module Ubalo
|
|
74
80
|
def ==(other)
|
75
81
|
[base_url, username, authorization] == [base_url, other.username, other.authorization]
|
76
82
|
end
|
83
|
+
|
84
|
+
private
|
85
|
+
def update_attributes(attributes)
|
86
|
+
@username = attributes['username']
|
87
|
+
end
|
77
88
|
end
|
78
89
|
end
|
data/lib/ubalo/pod.rb
CHANGED
@@ -6,7 +6,7 @@ module Ubalo
|
|
6
6
|
new(account, json.fetch('user').fetch('username'), json.fetch('name'), json)
|
7
7
|
end
|
8
8
|
|
9
|
-
attr_reader :username, :name, :state, :archive, :updated_at
|
9
|
+
attr_reader :username, :name, :state, :archive, :updated_at, :compilation_run
|
10
10
|
|
11
11
|
def initialize(account, username, name, attributes)
|
12
12
|
@account = account
|
@@ -45,6 +45,14 @@ module Ubalo
|
|
45
45
|
@account.task_from_json(request(:post, "/tasks", :params => params))
|
46
46
|
end
|
47
47
|
|
48
|
+
def latest_task
|
49
|
+
if task_json = request(:get, "/tasks").first
|
50
|
+
@account.task_from_json(task_json)
|
51
|
+
else
|
52
|
+
raise Ubalo::Error, "Could not find latest task for #{fullname.inspect}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
48
56
|
def push_from(pod_dir)
|
49
57
|
new_archive.activate_from(pod_dir)
|
50
58
|
refresh!
|
@@ -69,6 +77,27 @@ module Ubalo
|
|
69
77
|
!!@deleted
|
70
78
|
end
|
71
79
|
|
80
|
+
def printable_result
|
81
|
+
s = ""
|
82
|
+
s << " name: #{fullname}\n"
|
83
|
+
s << " state: #{state}\n"
|
84
|
+
|
85
|
+
if compilation_run
|
86
|
+
s << "status: #{compilation_run.fetch('exit_result')}\n"
|
87
|
+
|
88
|
+
if stdout = compilation_run.fetch('stdout') and stdout.length > 0
|
89
|
+
s << "stdout:\n"
|
90
|
+
s << Util.indent(stdout)
|
91
|
+
end
|
92
|
+
|
93
|
+
if stderr = compilation_run.fetch('stderr') and stderr.length > 0
|
94
|
+
s << "stderr:\n"
|
95
|
+
s << Util.indent(stderr)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
s
|
99
|
+
end
|
100
|
+
|
72
101
|
def inspect
|
73
102
|
"#<Pod #{fullname.inspect} state=#{state.inspect}>"
|
74
103
|
end
|
@@ -80,6 +109,7 @@ module Ubalo
|
|
80
109
|
private
|
81
110
|
def update_attributes(attributes)
|
82
111
|
@state = attributes['state']
|
112
|
+
@compilation_run = attributes['compilation_run']
|
83
113
|
if archive_attr = attributes['archive']
|
84
114
|
@archive = @account.archive_from_json(archive_attr)
|
85
115
|
end
|
data/lib/ubalo/pod_dir.rb
CHANGED
@@ -26,6 +26,30 @@ module Ubalo
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
def init(name, logger)
|
30
|
+
write_name(name)
|
31
|
+
in_path do
|
32
|
+
default_files.each do |filename,content|
|
33
|
+
if File.exist?(filename)
|
34
|
+
logger.puts "Using existing #{filename.inspect}"
|
35
|
+
else
|
36
|
+
logger.puts "Writing an example #{filename.inspect}"
|
37
|
+
File.open(filename, "w"){|f| f.write(content)}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def default_files
|
44
|
+
gem_root = File.expand_path("../../..", __FILE__)
|
45
|
+
files_root = File.join(gem_root, "resources/init_files")
|
46
|
+
files = {}
|
47
|
+
%w{.ubaloignore run.sh}.each do |filename|
|
48
|
+
files[filename] = File.read(File.join(files_root, filename))
|
49
|
+
end
|
50
|
+
files
|
51
|
+
end
|
52
|
+
|
29
53
|
def manifest
|
30
54
|
in_path do
|
31
55
|
Dir.glob('{.**,**}').map do |path|
|
data/lib/ubalo/task.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Ubalo
|
2
2
|
class Task
|
3
|
-
attr_reader :label, :state, :pod_name, :arg, :output, :submitted_at
|
3
|
+
attr_reader :label, :state, :pod_name, :arg, :output, :submitted_at, :elapsed_time
|
4
4
|
|
5
5
|
def self.create_with_json(account, json)
|
6
6
|
new(account, json.fetch('label'), json)
|
@@ -46,7 +46,11 @@ module Ubalo
|
|
46
46
|
|
47
47
|
if container_process
|
48
48
|
s << "status: #{container_process.fetch('exit_result')}\n"
|
49
|
+
end
|
50
|
+
|
51
|
+
s << " time: #{'%.1f' % elapsed_time} s\n"
|
49
52
|
|
53
|
+
if container_process
|
50
54
|
if stdout = container_process.fetch('stdout') and stdout.length > 0
|
51
55
|
s << "stdout:\n"
|
52
56
|
s << Util.indent(stdout)
|
@@ -74,6 +78,7 @@ module Ubalo
|
|
74
78
|
@pod_name = attributes['pod_name']
|
75
79
|
@container_process = attributes['container_process']
|
76
80
|
@submitted_at = attributes['submitted_at']
|
81
|
+
@elapsed_time = attributes['elapsed_time']
|
77
82
|
|
78
83
|
@arg = Util.decode_content(attributes['arg']) if attributes['arg']
|
79
84
|
@output = Util.decode_content(attributes['outputs']) if attributes['outputs']
|
data/lib/ubalo/util.rb
CHANGED
@@ -86,7 +86,7 @@ module Ubalo
|
|
86
86
|
def http_request(method, url, options)
|
87
87
|
params = options.delete(:params) || {}
|
88
88
|
|
89
|
-
headers = {:accept => :json, 'X-Ubalo-Version' => Ubalo
|
89
|
+
headers = {:accept => :json, 'X-Ubalo-Version' => Ubalo.version}
|
90
90
|
|
91
91
|
if authorization = options.delete(:authorization)
|
92
92
|
headers.merge!(:authorization => authorization)
|
@@ -115,6 +115,12 @@ module Ubalo
|
|
115
115
|
else
|
116
116
|
JSON.load(response)
|
117
117
|
end
|
118
|
+
rescue RestClient::BadRequest => e
|
119
|
+
if message = JSON.load(e.response.to_s)["upgrade_message"]
|
120
|
+
raise Ubalo::Error, message
|
121
|
+
else
|
122
|
+
raise e
|
123
|
+
end
|
118
124
|
end
|
119
125
|
|
120
126
|
def pluralize count, word
|
data/lib/ubalo/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ubalo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.6'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: gli
|
16
|
-
requirement: &
|
16
|
+
requirement: &70257222461780 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70257222461780
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: highline
|
27
|
-
requirement: &
|
27
|
+
requirement: &70257222459400 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70257222459400
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: json
|
38
|
-
requirement: &
|
38
|
+
requirement: &70257222473120 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70257222473120
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rest-client
|
49
|
-
requirement: &
|
49
|
+
requirement: &70257222468340 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.6.3
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70257222468340
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: archive-tar-minitar
|
60
|
-
requirement: &
|
60
|
+
requirement: &70257222746760 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70257222746760
|
69
69
|
description: CLI and API client for Ubalo
|
70
70
|
email: dev@ubalo.com
|
71
71
|
executables:
|
@@ -94,18 +94,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
94
94
|
- - ! '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
segments:
|
98
|
-
- 0
|
99
|
-
hash: -1754747755012050403
|
100
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
98
|
none: false
|
102
99
|
requirements:
|
103
100
|
- - ! '>='
|
104
101
|
- !ruby/object:Gem::Version
|
105
102
|
version: '0'
|
106
|
-
segments:
|
107
|
-
- 0
|
108
|
-
hash: -1754747755012050403
|
109
103
|
requirements: []
|
110
104
|
rubyforge_project:
|
111
105
|
rubygems_version: 1.8.11
|
@@ -113,3 +107,4 @@ signing_key:
|
|
113
107
|
specification_version: 3
|
114
108
|
summary: CLI and API client for Ubalo
|
115
109
|
test_files: []
|
110
|
+
has_rdoc:
|