vmc 0.2.4 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -14,3 +14,4 @@ desc "Synonym for spec"
14
14
  task :test => :spec
15
15
  desc "Synonym for spec"
16
16
  task :tests => :spec
17
+ task :default => :spec
@@ -17,7 +17,7 @@ module VMC::Cli::Command
17
17
  client.add_user(email, password)
18
18
  display 'OK'.green
19
19
 
20
- # if we are not logged in, log in as the new user
20
+ # if we are not logged in for the current target, log in as the new user
21
21
  return unless VMC::Cli::Config.auth_token.nil?
22
22
  @options[:password] = password
23
23
  cmd = User.new(@options)
@@ -160,10 +160,17 @@ module VMC::Cli::Command
160
160
 
161
161
  end
162
162
 
163
- def delete(appname=nil, force=false)
163
+ def delete(appname=nil)
164
+ force = @options[:force]
164
165
  if @options[:all]
165
- apps = client.apps
166
- apps.each { |app| delete_app(app[:name], force) }
166
+ should_delete = force && no_prompt ? 'Y' : 'N'
167
+ unless no_prompt || force
168
+ should_delete = ask 'Delete ALL Applications and Services? (y/N)? '
169
+ end
170
+ if should_delete.upcase == 'Y'
171
+ apps = client.apps
172
+ apps.each { |app| delete_app(app[:name], force) }
173
+ end
167
174
  else
168
175
  err 'No valid appname given' unless appname
169
176
  delete_app(appname, force)
@@ -175,8 +182,7 @@ module VMC::Cli::Command
175
182
  services_to_delete = []
176
183
  app_services = app[:services]
177
184
  app_services.each { |service|
178
- del_service = 'Y' if force
179
- del_service = 'N' if no_prompt
185
+ del_service = force && no_prompt ? 'Y' : 'N'
180
186
  unless no_prompt || force
181
187
  del_service = ask("Provisioned service [#{service}] detected, would you like to delete it? [Yn]: ")
182
188
  end
@@ -301,13 +307,13 @@ module VMC::Cli::Command
301
307
  end
302
308
 
303
309
  def update(appname)
310
+ app = client.app_info(appname)
304
311
  path = @options[:path] || '.'
305
312
  upload_app_bits(appname, path)
306
313
  display "Successfully updated Application: '#{appname}'".green
307
314
  if @options[:canary]
308
315
  display "[--canary] is deprecated and will be removed in a future version".yellow
309
316
  end
310
- app = client.app_info(appname)
311
317
  restart appname if app[:state] == 'STARTED'
312
318
  end
313
319
 
@@ -334,7 +340,7 @@ module VMC::Cli::Command
334
340
  check_app_limit
335
341
 
336
342
  # check memsize here for capacity
337
- check_has_capacity_for(mem_choice_to_quota(memswitch)) if memswitch
343
+ check_has_capacity_for(mem_choice_to_quota(memswitch)) if memswitch && !no_start
338
344
 
339
345
  unless no_prompt || @options[:path]
340
346
  proceed = ask('Would you like to deploy from the current directory? [Yn]: ')
@@ -399,7 +405,7 @@ module VMC::Cli::Command
399
405
  mem_quota = mem_choice_to_quota(mem)
400
406
 
401
407
  # check memsize here for capacity
402
- check_has_capacity_for(mem_quota)
408
+ check_has_capacity_for(mem_quota) unless no_start
403
409
 
404
410
  display 'Creating Application: ', false
405
411
 
@@ -476,11 +482,12 @@ module VMC::Cli::Command
476
482
  total_size = 0
477
483
  resource_files = Dir.glob("#{explode_dir}/**/*", File::FNM_DOTMATCH)
478
484
  resource_files.each do |filename|
485
+ next if (File.directory?(filename) || !File.exists?(filename))
479
486
  fingerprints << {
480
487
  :size => File.size(filename),
481
488
  :sha1 => Digest::SHA1.file(filename).hexdigest,
482
489
  :fn => filename
483
- } unless (File.directory?(filename) || !File.exists?(filename))
490
+ }
484
491
  total_size += File.size(filename)
485
492
  end
486
493
 
@@ -504,6 +511,15 @@ module VMC::Cli::Command
504
511
 
505
512
  end
506
513
 
514
+ # It's possible the CC tells us that we don't need to pack anything.
515
+ # If so, exit early.
516
+ if VMC::Cli::ZipUtil.get_files_to_pack(explode_dir).empty?
517
+ display ' No resources need to be uploaded'
518
+ display 'Push Status: ', false
519
+ display 'OK'.green
520
+ return
521
+ end
522
+
507
523
  # Perform Packing of the upload bits here.
508
524
  display ' Packing application: ', false
509
525
  VMC::Cli::ZipUtil.pack(explode_dir, upload_file)
@@ -768,7 +784,7 @@ module VMC::Cli::Command
768
784
  map = VMC::Cli::Config.instances
769
785
  instance = map[instance] if map[instance]
770
786
 
771
- ['/logs/err.log', 'logs/stderr.log', 'logs/stdout.log', 'logs/startup.log'].each do |path|
787
+ ['/logs/err.log', '/logs/staging.log', 'logs/stderr.log', 'logs/stdout.log', 'logs/startup.log'].each do |path|
772
788
  begin
773
789
  content = client.app_files(appname, path, instance)
774
790
  rescue
@@ -803,7 +819,7 @@ module VMC::Cli::Command
803
819
  @read ||= 0
804
820
  @read += rsize
805
821
  p = (@read * 100 / FileWithPercentOutput.upload_size).to_i
806
- unless VMC::Cli::Config.output.nil?
822
+ unless VMC::Cli::Config.output.nil? || !STDOUT.tty?
807
823
  clear(FileWithPercentOutput.display_str.size + 5)
808
824
  VMC::Cli::Config.output.print("#{FileWithPercentOutput.display_str} #{p}%")
809
825
  VMC::Cli::Config.output.flush
@@ -815,7 +831,7 @@ module VMC::Cli::Command
815
831
  if result && result.size > 0
816
832
  update_display(result.size)
817
833
  else
818
- unless VMC::Cli::Config.output.nil?
834
+ unless VMC::Cli::Config.output.nil? || !STDOUT.tty?
819
835
  clear(FileWithPercentOutput.display_str.size + 5)
820
836
  VMC::Cli::Config.output.print(FileWithPercentOutput.display_str)
821
837
  display('OK'.green)
@@ -21,7 +21,7 @@ module VMC::Cli::Command
21
21
  say "Successfully logged into [#{target_url}]".green
22
22
  rescue VMC::Client::TargetError
23
23
  display "Problem with login, invalid account or password.".red
24
- retry if (tries += 1) < 3 && prompt_ok
24
+ retry if (tries += 1) < 3 && prompt_ok && !@options[:password]
25
25
  exit 1
26
26
  rescue => e
27
27
  display "Problem with login, #{e}, try again or register for an account.".red
@@ -6,13 +6,13 @@ module VMC::Cli
6
6
  DEFAULT_MEM = '256M'
7
7
 
8
8
  FRAMEWORKS = {
9
- 'Rails' => ['rails/1.0', { :mem => '256M', :description => 'Rails Application'}],
10
- 'Spring' => ['spring_web/1.0', { :mem => '512M', :description => 'Java SpringSource Spring Application'}],
11
- 'Grails' => ['grails/1.0', { :mem => '512M', :description => 'Java SpringSource Grails Application'}],
12
- 'Roo' => ['spring_web/1.0', { :mem => '512M', :description => 'Java SpringSource Roo Application'}],
13
- 'JavaWeb' => ['spring_web/1.0', { :mem => '512M', :description => 'Java Web Application'}],
9
+ 'Rails' => ['rails/1.0', { :mem => '256M', :description => 'Rails Application'}],
10
+ 'Spring' => ['spring_web/1.0', { :mem => '512M', :description => 'Java SpringSource Spring Application'}],
11
+ 'Grails' => ['grails/1.0', { :mem => '512M', :description => 'Java SpringSource Grails Application'}],
12
+ 'Roo' => ['spring_web/1.0', { :mem => '512M', :description => 'Java SpringSource Roo Application'}],
13
+ 'JavaWeb' => ['spring_web/1.0', { :mem => '512M', :description => 'Java Web Application'}],
14
14
  'Sinatra' => [DEFAULT_FRAMEWORK, { :mem => '128M', :description => 'Sinatra Application'}],
15
- 'Node' => ['nodejs/1.0', { :mem => '64M', :description => 'NodeJS Application'}],
15
+ 'Node' => ['nodejs/1.0', { :mem => '64M', :description => 'Node.js Application'}],
16
16
  }
17
17
 
18
18
  class << self
@@ -38,7 +38,7 @@ module VMC::Cli
38
38
  contents = ZipUtil.entry_lines(war_file)
39
39
 
40
40
  # Spring Variations
41
- if contents =~ /WEB-INF\/grails-app/
41
+ if contents =~ /WEB-INF\/lib\/grails-web.*\.jar/
42
42
  return Framework.lookup('Grails')
43
43
  elsif contents =~ /WEB-INF\/classes\/org\/springframework/
44
44
  return Framework.lookup('Spring')
@@ -58,13 +58,13 @@ module VMC::Cli
58
58
  matched_file = fname if (str && str.match(/^\s*require\s*'sinatra'/))
59
59
  end
60
60
  end
61
- if matched_file && !File.exist?('config.ru')
61
+ if matched_file
62
62
  f = Framework.lookup('Sinatra')
63
63
  f.exec = "ruby #{matched_file}"
64
64
  return f
65
65
  end
66
66
 
67
- # Node.JS
67
+ # Node.js
68
68
  elsif !Dir.glob('*.js').empty?
69
69
  # Fixme, make other files work too..
70
70
  if File.exist?('app.js') || File.exist?('index.js') || File.exist?('main.js')
data/lib/cli/runner.rb CHANGED
@@ -81,11 +81,20 @@ class VMC::Cli::Runner
81
81
 
82
82
  opts.on_tail('--options') { puts "#{opts}\n"; exit }
83
83
  end
84
+ instances_delta_arg = check_instances_delta!
84
85
  @args = opts_parser.parse!(@args)
86
+ @args.concat instances_delta_arg
85
87
  convert_options!
86
88
  self
87
89
  end
88
90
 
91
+ def check_instances_delta!
92
+ return unless @args
93
+ instance_args = @args.select { |arg| /[-]\d+/ =~ arg } || []
94
+ @args.delete_if { |arg| instance_args.include? arg}
95
+ instance_args
96
+ end
97
+
89
98
  def display_help
90
99
  puts command_usage
91
100
  exit
@@ -349,9 +358,12 @@ class VMC::Cli::Runner
349
358
  def process_aliases!
350
359
  return if @args.empty?
351
360
  aliases = VMC::Cli::Config.aliases
352
- if key = aliases.values.grep(@args[0]).first
353
- display "[#{@args[0]} aliased to #{aliases.invert[key]}]" if @options[:verbose]
354
- @args[0] = aliases.invert[key]
361
+ aliases.each_pair do |k,v|
362
+ if @args[0] == k
363
+ display "[#{@args[0]} aliased to #{aliases.invert[key]}]" if @options[:verbose]
364
+ @args[0] = v
365
+ break;
366
+ end
355
367
  end
356
368
  end
357
369
 
@@ -366,8 +378,9 @@ class VMC::Cli::Runner
366
378
  end
367
379
 
368
380
  def run
381
+
369
382
  trap('TERM') { print "\nInterupted\n"; exit(false)}
370
- trap("INT") { print "\nInterupted\n"; exit(false)}
383
+ trap('INT') { print "\nInterupted\n"; exit(false)}
371
384
 
372
385
  parse_options!
373
386
 
@@ -406,6 +419,9 @@ class VMC::Cli::Runner
406
419
  rescue VMC::Client::TargetError, VMC::Client::NotFound, VMC::Client::BadTarget => e
407
420
  puts e.message.red
408
421
  @exit_status = false
422
+ rescue VMC::Client::HTTPException => e
423
+ puts e.message.red
424
+ @exit_status = false
409
425
  rescue VMC::Cli::GracefulExit => e
410
426
  # Redirected commands end up generating this exception (kind of goto)
411
427
  rescue VMC::Cli::CliExit => e
data/lib/cli/usage.rb CHANGED
@@ -17,7 +17,7 @@ class VMC::Cli::Runner
17
17
  say command_usage
18
18
  end
19
19
 
20
- def command_usage
20
+ def command_usage
21
21
  <<-USAGE
22
22
 
23
23
  #{basic_usage}
data/lib/cli/version.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module VMC
2
2
  module Cli
3
- VERSION = '0.2.4'
3
+ # This version number is used as the RubyGem release version.
4
+ # The internal VMC version number is VMC::VERSION.
5
+ VERSION = '0.2.6'
4
6
  end
5
7
  end
data/lib/cli/zip_util.rb CHANGED
@@ -5,6 +5,8 @@ module VMC::Cli
5
5
 
6
6
  class ZipUtil
7
7
 
8
+ PACK_EXCLUSION_GLOBS = ['..', '.', '*~', '#*#', '*.log']
9
+
8
10
  class << self
9
11
  def entry_lines(file)
10
12
  contents = nil
@@ -36,22 +38,27 @@ module VMC::Cli
36
38
  end
37
39
  end
38
40
 
41
+ def get_files_to_pack(dir)
42
+ Dir.glob("#{dir}/**/*", File::FNM_DOTMATCH).select do |f|
43
+ process = true
44
+ PACK_EXCLUSION_GLOBS.each { |e| process = false if File.fnmatch(e, File.basename(f)) }
45
+ process && File.exists?(f)
46
+ end
47
+ end
48
+
39
49
  def pack(dir, zipfile)
40
- exclude = ['..', '.', '*~', '#*#', '*.log']
41
50
  unless VMC::Cli::Config.nozip
42
- excludes = exclude.map { |e| "\\#{e}" }
51
+ excludes = PACK_EXCLUSION_GLOBS.map { |e| "\\#{e}" }
43
52
  excludes = excludes.join(' ')
44
53
  Dir.chdir(dir) do
45
- `zip -q -r -x #{excludes} #{zipfile} . 2> /dev/null`
54
+ `zip -q -r #{zipfile} . -x #{excludes} 2> /dev/null`
46
55
  return unless $? != 0
47
56
  end
48
57
  end
49
58
  # Do Ruby version if told to or native version failed
50
59
  Zip::ZipFile::open(zipfile, true) do |zf|
51
- Dir.glob("#{dir}/**/*", File::FNM_DOTMATCH).each do |f|
52
- process = true
53
- exclude.each { |e| process = false if File.fnmatch(e, File.basename(f)) }
54
- zf.add(f.sub("#{dir}/",''), f) if (process && File.exists?(f))
60
+ get_files_to_pack(dir).each do |f|
61
+ zf.add(f.sub("#{dir}/",''), f)
55
62
  end
56
63
  end
57
64
  end
data/lib/vmc/client.rb CHANGED
@@ -12,7 +12,7 @@
12
12
  require 'rubygems'
13
13
  require 'json/pure'
14
14
 
15
- require File.dirname(__FILE__) + '/const'
15
+ require File.expand_path('../const', __FILE__)
16
16
 
17
17
  class VMC::Client
18
18
 
@@ -378,8 +378,8 @@ class VMC::Client
378
378
  result
379
379
  rescue Net::HTTPBadResponse => e
380
380
  raise BadTarget "Received bad HTTP response from target: #{e}"
381
- rescue RestClient::Exception => e
382
- raise HTTPException, "HTTP exception: #{e}"
381
+ rescue SystemCallError, RestClient::Exception => e
382
+ raise HTTPException, "HTTP exception: #{e.class}:#{e}"
383
383
  end
384
384
 
385
385
  def truncate(str, limit = 30)
data/lib/vmc/const.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  module VMC
2
2
 
3
- VERSION = '0.2.4'
3
+ # This is the internal VMC version number, and is not necessarily
4
+ # the same as the RubyGem version (VMC::Cli::VERSION).
5
+ VERSION = '0.2.6'
4
6
 
5
7
  # Targets
6
8
  DEFAULT_TARGET = 'http://api.cloudfoundry.com'
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vmc
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 4
10
- version: 0.2.4
5
+ version: 0.2.6
11
6
  platform: ruby
12
7
  authors:
13
8
  - VMware
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-03-19 00:00:00 -05:00
13
+ date: 2011-04-02 00:00:00 -05:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
@@ -26,11 +21,6 @@ dependencies:
26
21
  requirements:
27
22
  - - ~>
28
23
  - !ruby/object:Gem::Version
29
- hash: 1
30
- segments:
31
- - 1
32
- - 5
33
- - 1
34
24
  version: 1.5.1
35
25
  type: :runtime
36
26
  version_requirements: *id001
@@ -42,11 +32,6 @@ dependencies:
42
32
  requirements:
43
33
  - - ~>
44
34
  - !ruby/object:Gem::Version
45
- hash: 13
46
- segments:
47
- - 2
48
- - 0
49
- - 1
50
35
  version: 2.0.1
51
36
  type: :runtime
52
37
  version_requirements: *id002
@@ -58,11 +43,6 @@ dependencies:
58
43
  requirements:
59
44
  - - ~>
60
45
  - !ruby/object:Gem::Version
61
- hash: 13
62
- segments:
63
- - 1
64
- - 6
65
- - 1
66
46
  version: 1.6.1
67
47
  type: :runtime
68
48
  version_requirements: *id003
@@ -74,19 +54,9 @@ dependencies:
74
54
  requirements:
75
55
  - - ">="
76
56
  - !ruby/object:Gem::Version
77
- hash: 13
78
- segments:
79
- - 1
80
- - 6
81
- - 1
82
57
  version: 1.6.1
83
58
  - - <
84
59
  - !ruby/object:Gem::Version
85
- hash: 11
86
- segments:
87
- - 1
88
- - 7
89
- - 0
90
60
  version: 1.7.0
91
61
  type: :runtime
92
62
  version_requirements: *id004
@@ -98,11 +68,6 @@ dependencies:
98
68
  requirements:
99
69
  - - ~>
100
70
  - !ruby/object:Gem::Version
101
- hash: 3
102
- segments:
103
- - 1
104
- - 4
105
- - 2
106
71
  version: 1.4.2
107
72
  type: :runtime
108
73
  version_requirements: *id005
@@ -114,9 +79,6 @@ dependencies:
114
79
  requirements:
115
80
  - - ">="
116
81
  - !ruby/object:Gem::Version
117
- hash: 3
118
- segments:
119
- - 0
120
82
  version: "0"
121
83
  type: :development
122
84
  version_requirements: *id006
@@ -128,11 +90,6 @@ dependencies:
128
90
  requirements:
129
91
  - - ~>
130
92
  - !ruby/object:Gem::Version
131
- hash: 27
132
- segments:
133
- - 1
134
- - 3
135
- - 0
136
93
  version: 1.3.0
137
94
  type: :development
138
95
  version_requirements: *id007
@@ -144,11 +101,6 @@ dependencies:
144
101
  requirements:
145
102
  - - ~>
146
103
  - !ruby/object:Gem::Version
147
- hash: 3
148
- segments:
149
- - 1
150
- - 5
151
- - 0
152
104
  version: 1.5.0
153
105
  type: :development
154
106
  version_requirements: *id008
@@ -219,23 +171,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
219
171
  requirements:
220
172
  - - ">="
221
173
  - !ruby/object:Gem::Version
222
- hash: 3
223
- segments:
224
- - 0
225
174
  version: "0"
226
175
  required_rubygems_version: !ruby/object:Gem::Requirement
227
176
  none: false
228
177
  requirements:
229
178
  - - ">="
230
179
  - !ruby/object:Gem::Version
231
- hash: 3
232
- segments:
233
- - 0
234
180
  version: "0"
235
181
  requirements: []
236
182
 
237
183
  rubyforge_project:
238
- rubygems_version: 1.5.0
184
+ rubygems_version: 1.6.2
239
185
  signing_key:
240
186
  specification_version: 3
241
187
  summary: Client library and CLI that provides access to the VMware Cloud Application Platform.