ubalo 0.0.19 → 0.0.20

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.
Files changed (4) hide show
  1. data/bin/ubalo +28 -25
  2. data/lib/ubalo.rb +22 -21
  3. data/lib/ubalo/version.rb +1 -1
  4. metadata +11 -11
data/bin/ubalo CHANGED
@@ -153,7 +153,7 @@ command :get do |c|
153
153
  pod_name = normalize_pod_name(args.shift)
154
154
  destination_path = args.shift
155
155
 
156
- $stderr.print "Fetching code for #{pod_name}..."
156
+ $stderr.print "Fetching files for #{pod_name}..."
157
157
  response = ubalo.download(pod_name)
158
158
 
159
159
  fullname, destination_path = process_download(response)
@@ -236,19 +236,25 @@ arg_name '<pod name>'
236
236
  command :run do |c|
237
237
  c.desc 'Use JSON for input and output'
238
238
  c.switch :json
239
+ c.switch :ssh
239
240
 
240
241
  c.action do |global_options,options,args|
241
242
  pod_name = normalize_pod_name(args.shift)
242
243
  if options.json
243
- args = receive_json_from_stdin
244
- response = ubalo.submit_task_json(args)
244
+ arg = receive_json_from_stdin
245
245
  else
246
+ arg = args.join(" ")
246
247
  $stderr.print "Running #{pod_name}..."
247
- response = ubalo.submit_task(pod_name, args.join(" "))
248
248
  end
249
- task_label = response.fetch('label')
250
- result = ubalo.wait_task(task_label, options.json)
251
- ubalo.show_result(result, options.json)
249
+
250
+ if options.ssh
251
+ result = ubalo.run_task(pod_name, arg)
252
+ else
253
+ response = ubalo.submit_task(pod_name, arg)
254
+ task_label = response.fetch('label')
255
+ result = ubalo.wait_task(task_label, options.json)
256
+ ubalo.show_result(result, options.json)
257
+ end
252
258
  end
253
259
  end
254
260
 
@@ -310,7 +316,7 @@ command :stop do |c|
310
316
  task_label = args.first
311
317
  $stderr.print "Stopping task #{task_label}..."
312
318
  result = ubalo.stop_task(task_label)
313
- $stderr.puts " task now #{result.fetch('state')}."
319
+ $stderr.puts " stopped."
314
320
  end
315
321
  end
316
322
 
@@ -334,48 +340,45 @@ command :clear_key do |c|
334
340
  end
335
341
  end
336
342
 
337
- desc 'Push code to Ubalo'
343
+ desc 'Push files to Ubalo'
338
344
  command :push do |c|
339
345
  c.action do |global_options,options,args|
340
346
  filenames = local_config.fetch('filenames')
341
- contents = {}
347
+ files = {}
342
348
  filenames.each do |filename|
343
- contents[filename] = File.read(filename)
349
+ files[filename] = File.read(filename)
344
350
  end
345
351
 
346
- # Don't bother formatting for multiple files just yet.
347
- fail unless filenames.length == 1
348
-
349
- print "Uploading changes to #{filenames.first}... "
350
- result = ubalo.push(local_config.fetch('pod_url'), contents)
352
+ print "Uploading changes... "
353
+ result = ubalo.push(local_config.fetch('pod_url'), files)
351
354
  puts "Code changes saved."
352
355
  end
353
356
  end
354
357
 
355
- desc 'Pull code from Ubalo'
358
+ desc 'Pull files from Ubalo'
356
359
  command :pull do |c|
357
360
  c.action do |global_options,options,args|
358
361
  print "Pulling changes from Ubalo..."
359
- contents = ubalo.pull(local_config.fetch('pod_url'))
362
+ files = ubalo.pull(local_config.fetch('pod_url'))
360
363
  puts " received."
361
364
 
362
365
  filenames = local_config.fetch('filenames')
363
366
 
364
367
  filenames.each do |filename|
365
368
  if File.exists?(filename)
366
- existing_contents = File.read(filename)
369
+ existing_content = File.read(filename)
367
370
  else
368
- existing_contents = nil
371
+ existing_content = nil
369
372
  end
370
373
 
371
- if contents.fetch(filename) == existing_contents
374
+ if files.fetch(filename) == existing_content
372
375
  puts "Checking #{filename}... no changes."
373
376
  else
374
377
  hl.choose do |menu|
375
378
  menu.prompt = "Changes made to #{filename}. Overwrite your copy? "
376
379
  menu.choice :yes do
377
380
  open(filename, 'w') do |f|
378
- f.puts contents.fetch(filename)
381
+ f.puts files.fetch(filename)
379
382
  end
380
383
  puts "Changes saved to #{filename}."
381
384
  end
@@ -394,7 +397,7 @@ command :edit do |c|
394
397
  c.action do |global_options,options,args|
395
398
  username = args.first || local_username
396
399
  puts "Opening an ssh connection to edit the environment belonging to #{username}."
397
- ubalo.ssh(username, 'edit-environment')
400
+ ubalo.ssh('edit environment', username)
398
401
  end
399
402
  end
400
403
 
@@ -403,7 +406,7 @@ command "shared:edit" do |c|
403
406
  c.action do |global_options,options,args|
404
407
  username = args.first || local_username
405
408
  puts "Opening an ssh connection to edit the shared data belonging to #{username}."
406
- ubalo.ssh(username, 'edit-shared-data')
409
+ ubalo.ssh('edit shared data', username)
407
410
  end
408
411
  end
409
412
 
@@ -420,7 +423,7 @@ command :cp do |c|
420
423
  ubalo.ssh_path
421
424
  end
422
425
 
423
- ubalo.scp(local_username, opts, scp_args)
426
+ ubalo.scp(opts, scp_args, local_username)
424
427
  end
425
428
  end
426
429
 
data/lib/ubalo.rb CHANGED
@@ -134,15 +134,16 @@ class Ubalo
134
134
  end
135
135
 
136
136
  def tasks count
137
- get("#{base_url}/api/tasks", :count => count)
137
+ get("#{base_url}/tasks", :count => count)
138
138
  end
139
139
 
140
- def submit_task(pod_name, arg)
141
- submit_task_json({:pod_name => pod_name, :arg => arg})
140
+ def run_task(pod_name, arg)
141
+ puts "Running #{pod_name} interactively..."
142
+ ssh('run task', pod_name, arg)
142
143
  end
143
144
 
144
- def submit_task_json hash
145
- post("#{base_url}/api/submit_task", hash)
145
+ def submit_task pod_name, arg
146
+ post("#{base_url}/pods/#{pod_name}/tasks", :arg => arg)
146
147
  end
147
148
 
148
149
  def wait_task(label, silent=false)
@@ -189,26 +190,26 @@ class Ubalo
189
190
  get("#{base_url}/pods")
190
191
  end
191
192
 
192
- def ssh(username, action)
193
- ssh_command = "ssh -o SendEnv='UBALO_OWNER_NAME UBALO_ACTION TERM' -tq #{ssh_path}"
194
- Process.spawn({'UBALO_OWNER_NAME' => username, 'UBALO_ACTION' => action}, ssh_command)
195
- pid, status = Process.wait2
196
- unless status.success?
197
- abort "Error running ssh"
198
- end
193
+ def ssh(action, *args)
194
+ ssh_command = "ssh -o SendEnv='UBALO_ARGS UBALO_ACTION TERM' -tq #{ssh_path}"
195
+ execute(action, args, ssh_command)
196
+ end
197
+
198
+ def scp(opts, command, *args)
199
+ scp_command = "scp -o SendEnv='UBALO_ARGS UBALO_ACTION' #{opts} #{command}"
200
+ execute('edit environment', args, scp_command)
199
201
  end
200
202
 
201
- def scp(username, opts, args)
202
- scp_command = "scp -o SendEnv='UBALO_OWNER_NAME UBALO_ACTION' #{opts} #{args}"
203
- Process.spawn({'UBALO_OWNER_NAME' => username, 'UBALO_ACTION' => 'edit-environment'}, scp_command)
203
+ def execute(action, args, command)
204
+ Process.spawn({'UBALO_ACTION' => action, 'UBALO_ARGS' => JSON.dump(args)}, command)
204
205
  pid, status = Process.wait2
205
206
  unless status.success?
206
- abort "Error running cp"
207
+ abort "Error running command"
207
208
  end
208
209
  end
209
210
 
210
211
  def stop_task(label)
211
- post("#{base_url}/api/stop_task", {:label => label})
212
+ post("#{base_url}/tasks/#{label}/stop")
212
213
  end
213
214
 
214
215
  def show_result(result, json=false)
@@ -253,8 +254,8 @@ class Ubalo
253
254
  post("#{base_url}/templates/#{template}/pods", :pod => {:name => name})
254
255
  end
255
256
 
256
- def push pod_url, contents
257
- post("#{pod_url}/files", :contents => contents)
257
+ def push pod_url, files
258
+ post("#{pod_url}/files", :files => files)
258
259
  end
259
260
 
260
261
  def pull pod_url
@@ -262,11 +263,11 @@ class Ubalo
262
263
  end
263
264
 
264
265
  def check_task label
265
- check_task_json({:label => label})
266
+ get("#{base_url}/tasks/#{label}")
266
267
  end
267
268
 
268
269
  def check_task_json hash
269
- get("#{base_url}/api/check_task", hash)
270
+ check_task(hash[:label])
270
271
  end
271
272
 
272
273
  def publish pod_name
data/lib/ubalo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Ubalo
2
- VERSION = "0.0.19"
2
+ VERSION = "0.0.20"
3
3
  end
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.19
4
+ version: 0.0.20
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-17 00:00:00.000000000Z
12
+ date: 2012-01-23 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gli
16
- requirement: &70217556672060 !ruby/object:Gem::Requirement
16
+ requirement: &2154176360 !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: *70217556672060
24
+ version_requirements: *2154176360
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: highline
27
- requirement: &70217556671440 !ruby/object:Gem::Requirement
27
+ requirement: &2154175940 !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: *70217556671440
35
+ version_requirements: *2154175940
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: json
38
- requirement: &70217556670920 !ruby/object:Gem::Requirement
38
+ requirement: &2154175520 !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: *70217556670920
46
+ version_requirements: *2154175520
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rest-client
49
- requirement: &70217556670260 !ruby/object:Gem::Requirement
49
+ requirement: &2154175020 !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: *70217556670260
57
+ version_requirements: *2154175020
58
58
  description: CLI and API client for Ubalo
59
59
  email: dev@ubalo.com
60
60
  executables:
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  version: '0'
86
86
  requirements: []
87
87
  rubyforge_project:
88
- rubygems_version: 1.8.7
88
+ rubygems_version: 1.8.6
89
89
  signing_key:
90
90
  specification_version: 3
91
91
  summary: CLI and API client for Ubalo