vmc 0.4.0.beta.8 → 0.4.0.beta.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/{vmc-ng/LICENSE → LICENSE} +0 -0
  2. data/{vmc-ng/Rakefile → Rakefile} +0 -0
  3. data/bin/vmc +10 -11
  4. data/{vmc-ng/lib → lib}/vmc/cli/app.rb +106 -58
  5. data/{vmc-ng/lib → lib}/vmc/cli/better_help.rb +0 -0
  6. data/{vmc-ng/lib → lib}/vmc/cli/command.rb +14 -0
  7. data/{vmc-ng/lib → lib}/vmc/cli/dots.rb +0 -0
  8. data/{vmc-ng/lib → lib}/vmc/cli/service.rb +0 -0
  9. data/{vmc-ng/lib → lib}/vmc/cli/user.rb +0 -0
  10. data/{vmc-ng/lib → lib}/vmc/cli.rb +88 -2
  11. data/{vmc-ng/lib → lib}/vmc/constants.rb +0 -0
  12. data/{vmc-ng/lib → lib}/vmc/detect.rb +0 -0
  13. data/{vmc-ng/lib → lib}/vmc/errors.rb +0 -0
  14. data/{vmc-ng/lib → lib}/vmc/plugin.rb +0 -0
  15. data/lib/vmc/version.rb +3 -0
  16. data/{vmc-ng/lib → lib}/vmc.rb +0 -0
  17. metadata +41 -273
  18. data/vmc/LICENSE +0 -24
  19. data/vmc/README.md +0 -102
  20. data/vmc/Rakefile +0 -101
  21. data/vmc/bin/vmc +0 -6
  22. data/vmc/caldecott_helper/Gemfile +0 -10
  23. data/vmc/caldecott_helper/Gemfile.lock +0 -48
  24. data/vmc/caldecott_helper/server.rb +0 -43
  25. data/vmc/config/clients.yml +0 -17
  26. data/vmc/config/micro/offline.conf +0 -2
  27. data/vmc/config/micro/paths.yml +0 -22
  28. data/vmc/config/micro/refresh_ip.rb +0 -20
  29. data/vmc/lib/cli/commands/admin.rb +0 -80
  30. data/vmc/lib/cli/commands/apps.rb +0 -1126
  31. data/vmc/lib/cli/commands/base.rb +0 -227
  32. data/vmc/lib/cli/commands/manifest.rb +0 -56
  33. data/vmc/lib/cli/commands/micro.rb +0 -115
  34. data/vmc/lib/cli/commands/misc.rb +0 -129
  35. data/vmc/lib/cli/commands/services.rb +0 -180
  36. data/vmc/lib/cli/commands/user.rb +0 -65
  37. data/vmc/lib/cli/config.rb +0 -173
  38. data/vmc/lib/cli/console_helper.rb +0 -160
  39. data/vmc/lib/cli/core_ext.rb +0 -122
  40. data/vmc/lib/cli/errors.rb +0 -19
  41. data/vmc/lib/cli/frameworks.rb +0 -265
  42. data/vmc/lib/cli/manifest_helper.rb +0 -302
  43. data/vmc/lib/cli/runner.rb +0 -531
  44. data/vmc/lib/cli/services_helper.rb +0 -84
  45. data/vmc/lib/cli/tunnel_helper.rb +0 -332
  46. data/vmc/lib/cli/usage.rb +0 -115
  47. data/vmc/lib/cli/version.rb +0 -7
  48. data/vmc/lib/cli/zip_util.rb +0 -77
  49. data/vmc/lib/cli.rb +0 -47
  50. data/vmc/lib/vmc/client.rb +0 -471
  51. data/vmc/lib/vmc/const.rb +0 -22
  52. data/vmc/lib/vmc/micro/switcher/base.rb +0 -97
  53. data/vmc/lib/vmc/micro/switcher/darwin.rb +0 -19
  54. data/vmc/lib/vmc/micro/switcher/dummy.rb +0 -15
  55. data/vmc/lib/vmc/micro/switcher/linux.rb +0 -16
  56. data/vmc/lib/vmc/micro/switcher/windows.rb +0 -31
  57. data/vmc/lib/vmc/micro/vmrun.rb +0 -158
  58. data/vmc/lib/vmc/micro.rb +0 -56
  59. data/vmc/lib/vmc.rb +0 -3
  60. data/vmc-ng/bin/vmc +0 -14
  61. data/vmc-ng/lib/vmc/version.rb +0 -3
File without changes
File without changes
data/bin/vmc CHANGED
@@ -1,15 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
+ # vim: ft=ruby
2
3
 
3
- vmc = File.expand_path("../../vmc", __FILE__)
4
- vmc_ng = File.expand_path("../../vmc-ng", __FILE__)
4
+ require "rubygems"
5
+ require "thor"
5
6
 
6
- bin =
7
- if File.exists?(File.expand_path("~/.vmc/use-ng"))
8
- $LOAD_PATH.unshift "#{vmc_ng}/lib"
9
- "#{vmc_ng}/bin/vmc"
10
- else
11
- "#{vmc}/bin/vmc"
12
- end
7
+ require "vmc"
8
+ require "vmc/plugin"
13
9
 
14
- $0 = bin
15
- load bin
10
+ VMC::Plugin.load_all
11
+
12
+ $exit_status = 0
13
+ VMC::CLI.start(ARGV)
14
+ exit($exit_status)
@@ -37,8 +37,8 @@ module VMC
37
37
  group :apps, :manage
38
38
  flag(:name) { ask("Name") }
39
39
  flag(:path)
40
- flag(:url) { |name, target|
41
- ask("URL", :default => "#{name}.#{target}")
40
+ flag(:url) { |default|
41
+ ask("URL", :default => default)
42
42
  }
43
43
  flag(:memory) { |framework, runtime|
44
44
  ask("Memory Limit",
@@ -60,6 +60,9 @@ module VMC
60
60
  flag(:runtime) { |choices|
61
61
  ask("Runtime", :choices => choices)
62
62
  }
63
+ flag(:command) {
64
+ ask("Startup command")
65
+ }
63
66
  flag(:start, :default => true)
64
67
  flag(:restart, :default => true)
65
68
  flag(:create_services, :type => :boolean) {
@@ -87,9 +90,6 @@ module VMC
87
90
 
88
91
  app.total_instances = input(:instances)
89
92
 
90
- domain = client.target.sub(/^https?:\/\/api\.(.+)\/?/, '\1')
91
- app.urls = [input(:url, name, domain)]
92
-
93
93
  if detected.empty?
94
94
  framework = input(:framework, frameworks.keys.sort, nil)
95
95
  else
@@ -108,6 +108,19 @@ module VMC
108
108
  app.framework = framework
109
109
  app.runtime = runtime
110
110
 
111
+ if framework == "standalone"
112
+ app.command = input(:command)
113
+
114
+ if (url = input(:url, "none")) != "none"
115
+ app.urls = [url]
116
+ else
117
+ app.urls = []
118
+ end
119
+ else
120
+ domain = client.target.sub(/^https?:\/\/api\.(.+)\/?/, '\1')
121
+ app.urls = [input(:url, "#{name}.#{domain}")]
122
+ end
123
+
111
124
  app.memory = megabytes(input(:memory, framework, runtime))
112
125
 
113
126
  bindings = []
@@ -179,7 +192,7 @@ module VMC
179
192
  desc "start APPS...", "Start an application"
180
193
  group :apps, :manage
181
194
  flag :name
182
- flag :debug_mode
195
+ flag :debug_mode, :aliases => "-d"
183
196
  def start(*names)
184
197
  if name = passed_value(:name)
185
198
  names = [name]
@@ -195,7 +208,7 @@ module VMC
195
208
  switch_mode(app, input(:debug_mode))
196
209
 
197
210
  with_progress("Starting #{c(name, :name)}") do |s|
198
- if app.running?
211
+ if app.started?
199
212
  s.skip do
200
213
  err "Already started."
201
214
  end
@@ -247,7 +260,7 @@ module VMC
247
260
  desc "restart APPS...", "Stop and start an application"
248
261
  group :apps, :manage
249
262
  flag :name
250
- flag :debug_mode
263
+ flag :debug_mode, :aliases => "-d"
251
264
  def restart(*names)
252
265
  stop(*names)
253
266
  start(*names)
@@ -262,36 +275,52 @@ module VMC
262
275
  flag(:name) { |names|
263
276
  ask("Delete which application?", :choices => names)
264
277
  }
278
+ flag(:orphaned, :aliases => "-o", :type => :boolean,
279
+ :desc => "Delete orphaned instances")
265
280
  flag(:all, :default => false)
266
281
  def delete(*names)
267
282
  if input(:all)
268
283
  return unless input(:really, "ALL APPS", :bad)
269
284
 
270
- with_progress("Deleting all applications") do
271
- client.apps.collect(&:delete!)
285
+ apps = client.apps
286
+
287
+ orphaned = find_orphaned_services(apps)
288
+
289
+ apps.each do |a|
290
+ with_progress("Deleting #{c(a.name, :name)}") do
291
+ a.delete!
292
+ end
272
293
  end
273
294
 
295
+ delete_orphaned_services(orphaned)
296
+
274
297
  return
275
298
  end
276
299
 
300
+ apps = client.apps
301
+
277
302
  if names.empty?
278
- apps = client.apps
279
303
  fail "No applications." if apps.empty?
280
304
 
281
305
  names = [input(:name, apps.collect(&:name).sort)]
282
306
  end
283
307
 
284
- names.each do |name|
285
- really = input(:really, name, :name)
308
+ to_delete = names.collect { |n| apps.find { |a| a.name == n } }
309
+ orphaned = find_orphaned_services(to_delete)
310
+
311
+ to_delete.each do |app|
312
+ really = input(:really, app.name, :name)
286
313
 
287
314
  forget(:really)
288
315
 
289
316
  next unless really
290
317
 
291
- with_progress("Deleting #{c(name, :name)}") do
292
- client.app(name).delete!
318
+ with_progress("Deleting #{c(app.name, :name)}") do
319
+ app.delete!
293
320
  end
294
321
  end
322
+
323
+ delete_orphaned_services(orphaned)
295
324
  end
296
325
 
297
326
  desc "instances APPS...", "List an app's instances"
@@ -323,6 +352,7 @@ module VMC
323
352
 
324
353
  desc "scale APP", "Update the instances/memory limit for an application"
325
354
  group :apps, :info, :hidden => true
355
+ flag :name
326
356
  flag(:instances, :type => :numeric) { |default|
327
357
  ask("Instances", :default => default)
328
358
  }
@@ -331,7 +361,9 @@ module VMC
331
361
  :default => human_size(default * 1024 * 1024, 0),
332
362
  :choices => MEM_CHOICES)
333
363
  }
334
- def scale(name)
364
+ def scale(name = nil)
365
+ name ||= input(:name)
366
+
335
367
  app = client.app(name)
336
368
 
337
369
  instances = passed_value(:instances)
@@ -351,9 +383,12 @@ module VMC
351
383
 
352
384
  desc "logs APP", "Print out an app's logs"
353
385
  group :apps, :info, :hidden => true
386
+ flag :name
354
387
  flag(:instance, :type => :numeric, :default => 0)
355
388
  flag(:all, :default => false)
356
- def logs(name)
389
+ def logs(name = nil)
390
+ name ||= input(:name)
391
+
357
392
  app = client.app(name)
358
393
  fail "Unknown application." unless app.exists?
359
394
 
@@ -397,7 +432,10 @@ module VMC
397
432
 
398
433
  desc "file APP [PATH]", "Print out an app's file contents"
399
434
  group :apps, :info, :hidden => true
400
- def file(name, path = "/")
435
+ flag :name
436
+ def file(name = nil, path = "/")
437
+ name ||= input(:name)
438
+
401
439
  file =
402
440
  with_progress("Getting file contents") do
403
441
  client.app(name).file(*path.split("/"))
@@ -410,16 +448,18 @@ module VMC
410
448
 
411
449
  desc "files APP [PATH]", "Examine an app's files"
412
450
  group :apps, :info, :hidden => true
413
- def files(name, path = "/")
451
+ flag :name
452
+ def files(name = nil, path = "/")
453
+ name ||= input(:name)
454
+
414
455
  files =
415
456
  with_progress("Getting file listing") do
416
457
  client.app(name).files(*path.split("/"))
417
458
  end
418
459
 
419
460
  puts "" unless simple_output?
420
-
421
461
  files.each do |file|
422
- puts file
462
+ puts file.join("/")
423
463
  end
424
464
  end
425
465
 
@@ -450,17 +490,26 @@ module VMC
450
490
 
451
491
  desc "stats APP", "Display application instance status"
452
492
  group :apps, :info, :hidden => true
453
- def stats(name)
493
+ flag :name
494
+ def stats(name = nil)
495
+ name ||= input(:name)
496
+
454
497
  stats =
455
498
  with_progress("Getting stats") do
456
499
  client.app(name).stats
457
500
  end
458
501
 
459
502
  stats.sort_by { |k, _| k }.each do |idx, info|
503
+ puts ""
504
+
505
+ if info["state"] == "DOWN"
506
+ puts "Instance #{c("\##{idx}", :instance)} is down."
507
+ next
508
+ end
509
+
460
510
  stats = info["stats"]
461
511
  usage = stats["usage"]
462
- puts ""
463
- puts "instance #{c("#" + idx, :name)}:"
512
+ puts "instance #{c("\##{idx}", :instance)}:"
464
513
  print " cpu: #{percentage(usage["cpu"])} of"
465
514
  puts " #{b(stats["cores"])} cores"
466
515
  puts " memory: #{usage(usage["mem"] * 1024, stats["mem_quota"])}"
@@ -585,13 +634,14 @@ module VMC
585
634
  # set app debug mode, ensuring it's valid, and shutting it down
586
635
  def switch_mode(app, mode)
587
636
  mode = nil if mode == "none"
637
+ mode = "run" if mode == "debug_mode" # no value given
588
638
 
589
639
  return false if app.debug_mode == mode
590
640
 
591
641
  if mode.nil?
592
642
  with_progress("Removing debug mode") do
593
643
  app.debug_mode = nil
594
- app.stop! if app.running?
644
+ app.stop! if app.started?
595
645
  end
596
646
 
597
647
  return true
@@ -602,13 +652,9 @@ module VMC
602
652
  modes = runtimes[app.runtime]["debug_modes"] || []
603
653
  if modes.include?(mode)
604
654
  app.debug_mode = mode
605
- app.stop! if app.running?
606
- true
655
+ app.stop! if app.started?
607
656
  else
608
- s.fail do
609
- err "Unknown mode '#{mode}'; available: #{modes.inspect}"
610
- false
611
- end
657
+ fail "Unknown mode '#{mode}'; available: #{modes.join ", "}"
612
658
  end
613
659
  end
614
660
  end
@@ -666,45 +712,47 @@ module VMC
666
712
  end
667
713
  end
668
714
 
669
- def display_app(a)
670
- if simple_output?
671
- puts a.name
672
- return
673
- end
674
-
675
- puts ""
715
+ def display_instance(i)
716
+ print "instance #{c("\##{i.index}", :instance)}: "
717
+ puts "#{b(c(i.state.downcase, state_color(i.state)))} "
676
718
 
677
- status = app_status(a)
719
+ puts " started: #{c(i.since.strftime("%F %r"), :cyan)}"
678
720
 
679
- print "#{c(a.name, :name)}: #{status}"
721
+ if d = i.debugger
722
+ puts " debugger: port #{b(d[:port])} at #{b(d[:ip])}"
723
+ end
680
724
 
681
- unless a.total_instances == 1
682
- print ", #{b(a.total_instances)} instances"
725
+ if c = i.console
726
+ puts " console: port #{b(c[:port])} at #{b(c[:ip])}"
683
727
  end
728
+ end
684
729
 
685
- puts ""
730
+ def find_orphaned_services(apps)
731
+ orphaned = []
686
732
 
687
- unless a.urls.empty?
688
- puts " urls: #{a.urls.collect { |u| b(u) }.join(", ")}"
733
+ apps.each do |a|
734
+ a.services.each do |s|
735
+ if apps.none? { |x| x != a && x.services.include?(s) }
736
+ orphaned << s
737
+ end
738
+ end
689
739
  end
690
740
 
691
- unless a.services.empty?
692
- puts " services: #{a.services.collect { |s| b(s) }.join(", ")}"
693
- end
741
+ orphaned
694
742
  end
695
743
 
696
- def display_instance(i)
697
- print "instance #{c("\##{i.index}", :instance)}: "
698
- puts "#{b(c(i.state.downcase, state_color(i.state)))} "
699
-
700
- puts " started: #{c(i.since.strftime("%F %r"), :cyan)}"
744
+ def delete_orphaned_services(names)
745
+ return if names.empty?
701
746
 
702
- if d = i.debugger
703
- puts " debugger: port #{b(d["port"])} at #{b(d["ip"])}"
704
- end
747
+ puts "" unless simple_output?
705
748
 
706
- if c = i.console
707
- puts " console: port #{b(c["port"])} at #{b(c["ip"])}"
749
+ names.select { |s|
750
+ input(:orphaned) ||
751
+ ask("Delete orphaned service #{c(s, :name)}?", :default => false)
752
+ }.each do |s|
753
+ with_progress("Deleting service #{c(s, :name)}") do
754
+ client.service(s).delete!
755
+ end
708
756
  end
709
757
  end
710
758
  end
File without changes
@@ -10,6 +10,8 @@ require "vmc/cli/dots"
10
10
  require "vmc/cli/better_help"
11
11
 
12
12
 
13
+ $vmc_asked_auth = false
14
+
13
15
  module VMC
14
16
  module Interactive
15
17
  include ::Interactive::Rewindable
@@ -362,6 +364,18 @@ module VMC
362
364
  rescue UserError => e
363
365
  err e.message
364
366
  rescue CFoundry::Denied => e
367
+ if !$vmc_asked_auth && e.error_code == 200
368
+ $vmc_asked_auth = true
369
+
370
+ puts ""
371
+ puts c("Not authenticated! Try logging in:", :warning)
372
+
373
+ VMC::CLI.start(["login"])
374
+ @client = nil
375
+
376
+ retry
377
+ end
378
+
365
379
  err "Denied: #{e.description}"
366
380
  rescue Exception => e
367
381
  msg = e.class.name
File without changes
File without changes
File without changes
@@ -233,6 +233,10 @@ module VMC
233
233
 
234
234
  desc "apps", "List your applications"
235
235
  group :apps
236
+ flag :name, :desc => "Filter by name regexp"
237
+ flag :runtime, :desc => "Filter by runtime regexp"
238
+ flag :framework, :desc => "Filter by framework regexp"
239
+ flag :url, :desc => "Filter by url regexp"
236
240
  def apps
237
241
  apps =
238
242
  with_progress("Getting applications") do
@@ -246,12 +250,17 @@ module VMC
246
250
  end
247
251
 
248
252
  apps.each.with_index do |a, num|
249
- display_app(a)
253
+ display_app(a) if app_matches(a)
250
254
  end
251
255
  end
252
256
 
253
257
  desc "services", "List your services"
254
258
  group :services
259
+ flag :name, :desc => "Filter by name regexp"
260
+ flag :app, :desc => "Filter by bound application regexp"
261
+ flag :type, :desc => "Filter by service type regexp"
262
+ flag :vendor, :desc => "Filter by service vendor regexp"
263
+ flag :tier, :desc => "Filter by service tier regexp"
255
264
  def services
256
265
  services =
257
266
  with_progress("Getting services") do
@@ -264,8 +273,15 @@ module VMC
264
273
  puts "No services."
265
274
  end
266
275
 
276
+ if app = options[:app]
277
+ apps = client.apps
278
+ services.reject! do |s|
279
+ apps.none? { |a| a.services.include? s.name }
280
+ end
281
+ end
282
+
267
283
  services.each do |s|
268
- display_service(s)
284
+ display_service(s) if service_matches(s)
269
285
  end
270
286
  end
271
287
 
@@ -313,6 +329,76 @@ module VMC
313
329
 
314
330
  private
315
331
 
332
+ def app_matches(a)
333
+ if name = options[:name]
334
+ return false if a.name !~ /#{name}/
335
+ end
336
+
337
+ if runtime = options[:runtime]
338
+ return false if a.runtime !~ /#{runtime}/
339
+ end
340
+
341
+ if framework = options[:framework]
342
+ return false if a.framework !~ /#{framework}/
343
+ end
344
+
345
+ if url = options[:url]
346
+ return false if a.urls.none? { |u| u =~ /#{url}/ }
347
+ end
348
+
349
+ true
350
+ end
351
+
352
+ IS_UTF8 = !!(ENV["LC_ALL"] || ENV["LC_CTYPE"] || ENV["LANG"])["UTF-8"]
353
+
354
+ def display_app(a)
355
+ if simple_output?
356
+ puts a.name
357
+ return
358
+ end
359
+
360
+ puts ""
361
+
362
+ status = app_status(a)
363
+
364
+ puts "#{c(a.name, :name)}: #{status}"
365
+
366
+ puts " platform: #{b(a.framework)} on #{b(a.runtime)}"
367
+
368
+ print " usage: #{b(human_size(a.memory * 1024 * 1024, 0))}"
369
+ print " #{c(IS_UTF8 ? "\xc3\x97" : "x", :dim)} #{b(a.total_instances)}"
370
+ print " instance#{a.total_instances == 1 ? "" : "s"}"
371
+ puts ""
372
+
373
+ unless a.urls.empty?
374
+ puts " urls: #{a.urls.collect { |u| b(u) }.join(", ")}"
375
+ end
376
+
377
+ unless a.services.empty?
378
+ puts " services: #{a.services.collect { |s| b(s) }.join(", ")}"
379
+ end
380
+ end
381
+
382
+ def service_matches(s)
383
+ if name = options[:name]
384
+ return false if s.name !~ /#{name}/
385
+ end
386
+
387
+ if type = options[:type]
388
+ return false if s.type !~ /#{type}/
389
+ end
390
+
391
+ if vendor = options[:vendor]
392
+ return false if s.vendor !~ /#{vendor}/
393
+ end
394
+
395
+ if tier = options[:tier]
396
+ return false if s.tier !~ /#{tier}/
397
+ end
398
+
399
+ true
400
+ end
401
+
316
402
  def display_service(s)
317
403
  if simple_output?
318
404
  puts s.name
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ module VMC
2
+ VERSION = "0.4.0.beta.9"
3
+ end
File without changes