ubalo 0.0.17 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/ubalo +54 -41
- data/lib/ubalo.rb +50 -40
- data/lib/ubalo/version.rb +1 -1
- metadata +10 -10
data/bin/ubalo
CHANGED
@@ -90,7 +90,7 @@ command :pods do |c|
|
|
90
90
|
puts " (none)"
|
91
91
|
else
|
92
92
|
your_pods.each do |pod|
|
93
|
-
puts Ubalo.format_pod(pod
|
93
|
+
puts Ubalo.format_pod(pod)
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
@@ -100,7 +100,7 @@ command :pods do |c|
|
|
100
100
|
puts " (none)"
|
101
101
|
else
|
102
102
|
other_pods.each do |pod|
|
103
|
-
puts Ubalo.format_pod(pod
|
103
|
+
puts Ubalo.format_pod(pod)
|
104
104
|
end
|
105
105
|
end
|
106
106
|
end
|
@@ -123,7 +123,7 @@ def process_download response, destination_path=nil
|
|
123
123
|
name = response.fetch('name')
|
124
124
|
fullname = response.fetch('fullname')
|
125
125
|
url = response.fetch('url')
|
126
|
-
files = response.fetch('
|
126
|
+
files = response.fetch('files')
|
127
127
|
destination_path ||= name
|
128
128
|
|
129
129
|
if File.exists?(destination_path)
|
@@ -168,8 +168,8 @@ command :create do |c|
|
|
168
168
|
|
169
169
|
c.desc "Pod name"
|
170
170
|
c.flag :name
|
171
|
-
c.desc "Pod
|
172
|
-
c.flag :
|
171
|
+
c.desc "Pod template"
|
172
|
+
c.flag :template
|
173
173
|
|
174
174
|
c.action do |global_options,options,args|
|
175
175
|
if options.name
|
@@ -187,20 +187,22 @@ command :create do |c|
|
|
187
187
|
end
|
188
188
|
|
189
189
|
templates = ubalo.available_templates
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
190
|
+
template_names = templates.map{|t| t['name']}
|
191
|
+
|
192
|
+
if options['template']
|
193
|
+
template_name = options['template']
|
194
|
+
unless template_names.include? template_name
|
195
|
+
raise UbaloMessage, "Invalid template name"
|
194
196
|
end
|
195
197
|
else
|
196
|
-
|
197
|
-
menu.prompt = "
|
198
|
-
menu.choices(*
|
198
|
+
template_name = hl.choose do |menu|
|
199
|
+
menu.prompt = "Template for your new pod: "
|
200
|
+
menu.choices(*template_names)
|
199
201
|
end
|
200
202
|
end
|
201
203
|
|
202
|
-
$stderr.print "Creating a new #{
|
203
|
-
response = ubalo.create_pod(pod_name,
|
204
|
+
$stderr.print "Creating a new #{template_name} pod called #{pod_name}..."
|
205
|
+
response = ubalo.create_pod(pod_name, template_name)
|
204
206
|
|
205
207
|
fullname, destination_path = process_download(response)
|
206
208
|
|
@@ -209,6 +211,26 @@ command :create do |c|
|
|
209
211
|
end
|
210
212
|
end
|
211
213
|
|
214
|
+
desc 'Delete a pod'
|
215
|
+
arg_name '<pod name>'
|
216
|
+
command :delete do |c|
|
217
|
+
c.action do |global_options,options,args|
|
218
|
+
pod_name = normalize_pod_name(args.shift)
|
219
|
+
|
220
|
+
hl.choose do |menu|
|
221
|
+
menu.prompt = "Are you sure you want to delete #{pod_name}? "
|
222
|
+
menu.choice :yes do
|
223
|
+
$stderr.print "Deleting #{pod_name}..."
|
224
|
+
response = ubalo.delete_pod(pod_name)
|
225
|
+
$stderr.puts " done."
|
226
|
+
end
|
227
|
+
menu.choice :no do
|
228
|
+
raise UbaloMessage, "Cancelled! No changes made to #{pod_name}."
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
212
234
|
desc 'Run a pod'
|
213
235
|
arg_name '<pod name>'
|
214
236
|
command :run do |c|
|
@@ -292,21 +314,23 @@ command :stop do |c|
|
|
292
314
|
end
|
293
315
|
end
|
294
316
|
|
295
|
-
desc '
|
317
|
+
desc 'Add an ssh key (defaults to ~/.ssh/id_rsa.pub)'
|
296
318
|
arg_name '<file containing ssh key>'
|
297
319
|
command :add_key do |c|
|
298
320
|
c.action do |global_options,options,args|
|
299
321
|
public_key_file = args.shift
|
300
|
-
public_key_file ||=
|
322
|
+
public_key_file ||= '~/.ssh/id_rsa.pub'
|
301
323
|
|
302
|
-
|
324
|
+
response = ubalo.upload_key(File.read(File.expand_path(public_key_file)))
|
325
|
+
puts "Success! Key uploaded."
|
303
326
|
end
|
304
327
|
end
|
305
328
|
|
306
329
|
desc 'Clear your ssh key'
|
307
330
|
command :clear_key do |c|
|
308
331
|
c.action do |global_options,options,args|
|
309
|
-
|
332
|
+
ubalo.clear_key
|
333
|
+
puts "Success! Key cleared."
|
310
334
|
end
|
311
335
|
end
|
312
336
|
|
@@ -324,7 +348,7 @@ command :push do |c|
|
|
324
348
|
|
325
349
|
print "Uploading changes to #{filenames.first}... "
|
326
350
|
result = ubalo.push(local_config.fetch('pod_url'), contents)
|
327
|
-
puts
|
351
|
+
puts "Code changes saved."
|
328
352
|
end
|
329
353
|
end
|
330
354
|
|
@@ -365,25 +389,6 @@ command :pull do |c|
|
|
365
389
|
end
|
366
390
|
end
|
367
391
|
|
368
|
-
desc 'Add an ssh key (defaults to ~/.ssh/id_rsa.pub)'
|
369
|
-
arg_name '<file containing ssh key>'
|
370
|
-
command :add_key do |c|
|
371
|
-
c.action do |global_options,options,args|
|
372
|
-
public_key_file = args.shift
|
373
|
-
public_key_file ||= File.expand_path('~/.ssh/id_rsa.pub')
|
374
|
-
|
375
|
-
response = ubalo.upload_key(File.read(public_key_file))
|
376
|
-
puts response.fetch('message')
|
377
|
-
end
|
378
|
-
end
|
379
|
-
|
380
|
-
desc 'Clear all ssh keys'
|
381
|
-
command :clear_keys do |c|
|
382
|
-
c.action do |global_options,options,args|
|
383
|
-
puts ubalo.clear_keys.fetch('message')
|
384
|
-
end
|
385
|
-
end
|
386
|
-
|
387
392
|
desc 'Edit your environment'
|
388
393
|
command :edit do |c|
|
389
394
|
c.action do |global_options,options,args|
|
@@ -421,10 +426,18 @@ end
|
|
421
426
|
|
422
427
|
desc 'Enter username and password for access'
|
423
428
|
command :login do |c|
|
429
|
+
c.desc "Username"
|
430
|
+
c.flag :username
|
431
|
+
c.desc "Password"
|
432
|
+
c.flag :password
|
433
|
+
|
424
434
|
c.action do |global_options,options,args|
|
425
|
-
|
426
|
-
|
427
|
-
|
435
|
+
unless options[:username] and options[:password]
|
436
|
+
puts "Please enter your Ubalo details for command-line access."
|
437
|
+
end
|
438
|
+
|
439
|
+
login = options[:username] || hl.ask(" login: "){|q| q.echo = true}
|
440
|
+
password = options[:password] || hl.ask(" password: "){|q| q.echo = false}
|
428
441
|
|
429
442
|
response = ubalo.get_authorization(login, password)
|
430
443
|
ubalo.authorization = response.fetch('authorization')
|
data/lib/ubalo.rb
CHANGED
@@ -56,13 +56,8 @@ class Ubalo
|
|
56
56
|
"#{task['label']} #{"(#{task['state']})".lfit(10)} - #{task['pod_name']} (#{time_ago_in_words task['submitted_at']})"
|
57
57
|
end
|
58
58
|
|
59
|
-
def format_pod pod
|
60
|
-
|
61
|
-
name = pod['fullname']
|
62
|
-
else
|
63
|
-
name = pod['name']
|
64
|
-
end
|
65
|
-
" #{name} - #{pod['language_name']}"
|
59
|
+
def format_pod pod
|
60
|
+
" #{pod.fetch('fullname')} - #{pod.fetch('language_name')}"
|
66
61
|
end
|
67
62
|
|
68
63
|
private
|
@@ -102,33 +97,44 @@ class Ubalo
|
|
102
97
|
@base_url = base_url
|
103
98
|
end
|
104
99
|
|
105
|
-
def
|
106
|
-
|
107
|
-
|
100
|
+
def request(method, url, params)
|
101
|
+
if method == :get
|
102
|
+
response = RestClient.get url, add_headers(:params => params, :accept => :json)
|
103
|
+
elsif method == :post
|
104
|
+
response = RestClient.post url, params, add_headers(:accept => :json)
|
105
|
+
elsif method == :put
|
106
|
+
response = RestClient.put url, params, add_headers(:accept => :json)
|
107
|
+
elsif method == :delete
|
108
|
+
response = RestClient.delete url, add_headers(:accept => :json)
|
109
|
+
else
|
110
|
+
raise "don't understand request method #{method.inspect}"
|
111
|
+
end
|
112
|
+
parse(response)
|
108
113
|
end
|
109
114
|
|
110
|
-
def
|
111
|
-
|
112
|
-
parse(response)
|
115
|
+
def post(url, params={})
|
116
|
+
request(:post, url, params)
|
113
117
|
end
|
114
118
|
|
115
|
-
def
|
116
|
-
url
|
117
|
-
url_post(url, params)
|
119
|
+
def get(url, params={})
|
120
|
+
request(:get, url, params)
|
118
121
|
end
|
119
122
|
|
120
|
-
def
|
121
|
-
|
122
|
-
|
123
|
+
def put(url, params={})
|
124
|
+
request(:put, url, params)
|
125
|
+
end
|
126
|
+
|
127
|
+
def delete(url)
|
128
|
+
request(:delete, url, {})
|
123
129
|
end
|
124
130
|
|
125
131
|
def whoami
|
126
|
-
response = get(
|
127
|
-
"You are #{response['username']}, with role #{response['role']}.
|
132
|
+
response = get("#{base_url}/user")
|
133
|
+
"You are #{response['username']}, with role #{response['role']}."
|
128
134
|
end
|
129
135
|
|
130
136
|
def tasks count
|
131
|
-
get(
|
137
|
+
get("#{base_url}/api/tasks", :count => count)
|
132
138
|
end
|
133
139
|
|
134
140
|
def submit_task(pod_name, arg)
|
@@ -136,7 +142,7 @@ class Ubalo
|
|
136
142
|
end
|
137
143
|
|
138
144
|
def submit_task_json hash
|
139
|
-
post(
|
145
|
+
post("#{base_url}/api/submit_task", hash)
|
140
146
|
end
|
141
147
|
|
142
148
|
def wait_task(label, silent=false)
|
@@ -159,28 +165,28 @@ class Ubalo
|
|
159
165
|
end
|
160
166
|
|
161
167
|
def upload_key(key)
|
162
|
-
|
168
|
+
put("#{base_url}/user", :user => {:ssh_key => key})
|
163
169
|
end
|
164
170
|
|
165
171
|
def clear_key
|
166
|
-
|
172
|
+
put("#{base_url}/user", :user => {:ssh_key => nil})
|
167
173
|
end
|
168
174
|
|
169
|
-
def download(
|
170
|
-
get(
|
175
|
+
def download(pod_name)
|
176
|
+
get("#{base_url}/pods/#{pod_name}/files")
|
171
177
|
end
|
172
178
|
|
173
179
|
def upload_code(name, code)
|
174
|
-
post(
|
180
|
+
post("#{base_url}/api/upload_code", {:pod_name => name, :code => code})
|
175
181
|
end
|
176
182
|
|
177
183
|
def ssh_path
|
178
|
-
h = get(
|
184
|
+
h = get("#{base_url}/api/ssh_path")
|
179
185
|
h.fetch('ssh_path')
|
180
186
|
end
|
181
187
|
|
182
188
|
def pods
|
183
|
-
get(
|
189
|
+
get("#{base_url}/pods")
|
184
190
|
end
|
185
191
|
|
186
192
|
def ssh(username, action)
|
@@ -202,7 +208,7 @@ class Ubalo
|
|
202
208
|
end
|
203
209
|
|
204
210
|
def stop_task(label)
|
205
|
-
post(
|
211
|
+
post("#{base_url}/api/stop_task", {:label => label})
|
206
212
|
end
|
207
213
|
|
208
214
|
def show_result(result, json=false)
|
@@ -236,23 +242,23 @@ class Ubalo
|
|
236
242
|
end
|
237
243
|
|
238
244
|
def get_authorization login, password
|
239
|
-
post(
|
245
|
+
post("#{base_url}/user/authorization", :user => {:login => login, :password => password})
|
240
246
|
end
|
241
247
|
|
242
248
|
def available_templates
|
243
|
-
get(
|
249
|
+
get("#{base_url}/templates")
|
244
250
|
end
|
245
251
|
|
246
|
-
def create_pod name,
|
247
|
-
post(
|
252
|
+
def create_pod name, template
|
253
|
+
post("#{base_url}/templates/#{template}/pods", :pod => {:name => name})
|
248
254
|
end
|
249
255
|
|
250
256
|
def push pod_url, contents
|
251
|
-
|
257
|
+
post("#{pod_url}/files", :contents => contents)
|
252
258
|
end
|
253
259
|
|
254
260
|
def pull pod_url
|
255
|
-
|
261
|
+
get("#{pod_url}/files")['files']
|
256
262
|
end
|
257
263
|
|
258
264
|
def check_task label
|
@@ -260,15 +266,19 @@ class Ubalo
|
|
260
266
|
end
|
261
267
|
|
262
268
|
def check_task_json hash
|
263
|
-
get(
|
269
|
+
get("#{base_url}/api/check_task", hash)
|
264
270
|
end
|
265
271
|
|
266
272
|
def publish pod_name
|
267
|
-
|
273
|
+
post("#{base_url}/pods/#{pod_name}/publish")
|
274
|
+
end
|
275
|
+
|
276
|
+
def delete_pod pod_name
|
277
|
+
delete("#{base_url}/pods/#{pod_name}")
|
268
278
|
end
|
269
279
|
|
270
280
|
def unpublish pod_name
|
271
|
-
|
281
|
+
post("#{base_url}/pods/#{pod_name}/unpublish")
|
272
282
|
end
|
273
283
|
|
274
284
|
private
|
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.0.
|
4
|
+
version: 0.0.19
|
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-01-
|
12
|
+
date: 2012-01-17 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: gli
|
16
|
-
requirement: &
|
16
|
+
requirement: &70217556672060 !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: *70217556672060
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: highline
|
27
|
-
requirement: &
|
27
|
+
requirement: &70217556671440 !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: *70217556671440
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: json
|
38
|
-
requirement: &
|
38
|
+
requirement: &70217556670920 !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: *70217556670920
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rest-client
|
49
|
-
requirement: &
|
49
|
+
requirement: &70217556670260 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: 1.6.3
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70217556670260
|
58
58
|
description: CLI and API client for Ubalo
|
59
59
|
email: dev@ubalo.com
|
60
60
|
executables:
|