vmc 0.2.11 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -48,6 +48,11 @@ MIT license, please see the LICENSE file. All rights reserved._
48
48
  stats <appname> Display resource usage for the application
49
49
  instances <appname> List application instances
50
50
 
51
+ Application Environment
52
+ env <appname> List application environment variables
53
+ env-add <appname> <variable[=]value> Add an environment variable to an application
54
+ env-del <appname> <variable> Delete an environment variable to an application
55
+
51
56
  Services
52
57
  services Lists of services available and provisioned
53
58
  create-service <service> [--name,--bind] Create a provisioned service
@@ -65,6 +70,10 @@ MIT license, please see the LICENSE file. All rights reserved._
65
70
  add-user [--email, --passwd] Register a new user (requires admin privileges)
66
71
  delete-user <user> Delete a user and all apps and services (requires admin privileges)
67
72
 
73
+ System
74
+ runtimes Display the supported runtimes of the target system
75
+ frameworks Display the recognized frameworks of the target system
76
+
68
77
  Misc
69
78
  aliases List aliases
70
79
  alias <alias[=]command> Create an alias for a command
@@ -125,7 +125,7 @@ module VMC::Cli::Command
125
125
  display "Updating Memory Reservation to #{mem_quota_to_choice(memsize)}: ", false
126
126
 
127
127
  # check memsize here for capacity
128
- check_has_capacity_for(memsize - mem)
128
+ check_has_capacity_for((memsize - mem) * app[:instances])
129
129
 
130
130
  mem = memsize
131
131
 
@@ -308,12 +308,11 @@ module VMC::Cli::Command
308
308
 
309
309
  def update(appname)
310
310
  app = client.app_info(appname)
311
- path = @options[:path] || '.'
312
- upload_app_bits(appname, path)
313
- display "Successfully updated Application: '#{appname}'".green
314
311
  if @options[:canary]
315
312
  display "[--canary] is deprecated and will be removed in a future version".yellow
316
313
  end
314
+ path = @options[:path] || '.'
315
+ upload_app_bits(appname, path)
317
316
  restart appname if app[:state] == 'STARTED'
318
317
  end
319
318
 
@@ -342,7 +341,9 @@ module VMC::Cli::Command
342
341
  check_app_limit
343
342
 
344
343
  # check memsize here for capacity
345
- check_has_capacity_for(mem_choice_to_quota(memswitch)) if memswitch && !no_start
344
+ if memswitch && !no_start
345
+ check_has_capacity_for(mem_choice_to_quota(memswitch) * instances)
346
+ end
346
347
 
347
348
  unless no_prompt || @options[:path]
348
349
  proceed = ask('Would you like to deploy from the current directory? [Yn]: ')
@@ -407,15 +408,15 @@ module VMC::Cli::Command
407
408
  mem_quota = mem_choice_to_quota(mem)
408
409
 
409
410
  # check memsize here for capacity
410
- check_has_capacity_for(mem_quota) unless no_start
411
+ check_has_capacity_for(mem_quota * instances) unless no_start
411
412
 
412
413
  display 'Creating Application: ', false
413
414
 
414
415
  manifest = {
415
416
  :name => "#{appname}",
416
417
  :staging => {
417
- :model => framework.name,
418
- :stack => exec
418
+ :framework => framework.name,
419
+ :runtime => @options[:runtime]
419
420
  },
420
421
  :uris => [url],
421
422
  :instances => instances,
@@ -443,6 +444,57 @@ module VMC::Cli::Command
443
444
  start(appname, true) unless no_start
444
445
  end
445
446
 
447
+ def environment(appname)
448
+ app = client.app_info(appname)
449
+ env = app[:env] || []
450
+ return display JSON.pretty_generate(env) if @options[:json]
451
+ return display "No Environment Variables" if env.empty?
452
+ etable = table do |t|
453
+ t.headings = 'Variable', 'Value'
454
+ env.each do |e|
455
+ k,v = e.split('=')
456
+ t << [k, v]
457
+ end
458
+ end
459
+ display "\n"
460
+ display etable
461
+ end
462
+
463
+ def environment_add(appname, k, v=nil)
464
+ app = client.app_info(appname)
465
+ env = app[:env] || []
466
+ k,v = k.split('=') unless v
467
+ env << "#{k}=#{v}"
468
+ display "Adding Environment Variable [#{k}=#{v}]: ", false
469
+ app[:env] = env
470
+ client.update_app(appname, app)
471
+ display 'OK'.green
472
+ restart appname if app[:state] == 'STARTED'
473
+ end
474
+
475
+ def environment_del(appname, variable)
476
+ app = client.app_info(appname)
477
+ env = app[:env] || []
478
+ deleted_env = nil
479
+ env.each do |e|
480
+ k,v = e.split('=')
481
+ if (k == variable)
482
+ deleted_env = e
483
+ break;
484
+ end
485
+ end
486
+ display "Deleting Environment Variable [#{variable}]: ", false
487
+ if deleted_env
488
+ env.delete(deleted_env)
489
+ app[:env] = env
490
+ client.update_app(appname, app)
491
+ display 'OK'.green
492
+ restart appname if app[:state] == 'STARTED'
493
+ else
494
+ display 'OK'.green
495
+ end
496
+ end
497
+
446
498
  private
447
499
 
448
500
  def app_exists?(appname)
@@ -30,7 +30,7 @@ module VMC::Cli
30
30
  def client
31
31
  return @client if @client
32
32
  @client = VMC::Client.new(target_url, auth_token)
33
- @client.trace = true if VMC::Cli::Config.trace
33
+ @client.trace = VMC::Cli::Config.trace if VMC::Cli::Config.trace
34
34
  @client.proxy_for @options[:proxy] if @options[:proxy]
35
35
  @client
36
36
  end
@@ -50,6 +50,29 @@ module VMC::Cli
50
50
  @auth_token = VMC::Cli::Config.auth_token
51
51
  end
52
52
 
53
+ def runtimes_info
54
+ return @runtimes if @runtimes
55
+ info = client_info
56
+ @runtimes = {}
57
+ if info[:frameworks]
58
+ info[:frameworks].each_value do |f|
59
+ next unless f[:runtimes]
60
+ f[:runtimes].each { |r| @runtimes[r[:name]] = r}
61
+ end
62
+ end
63
+ @runtimes
64
+ end
65
+
66
+ def frameworks_info
67
+ return @frameworks if @frameworks
68
+ info = client_info
69
+ @frameworks = []
70
+ if info[:frameworks]
71
+ info[:frameworks].each_value { |f| @frameworks << [f[:name]] }
72
+ end
73
+ @frameworks
74
+ end
75
+
53
76
  end
54
77
  end
55
78
  end
@@ -42,7 +42,7 @@ module VMC::Cli::Command
42
42
  end
43
43
 
44
44
  def info
45
- info = client.info
45
+ info = client_info
46
46
  return display JSON.pretty_generate(info) if @options[:json]
47
47
 
48
48
  display "\n#{info[:description]}"
@@ -67,12 +67,36 @@ module VMC::Cli::Command
67
67
  end
68
68
  end
69
69
 
70
+ def runtimes
71
+ raise VMC::Client::AuthError unless client.logged_in?
72
+ return display JSON.pretty_generate(runtimes_info) if @options[:json]
73
+ return display "No Runtimes" if runtimes_info.empty?
74
+ rtable = table do |t|
75
+ t.headings = 'Name', 'Description', 'Version'
76
+ runtimes_info.each_value { |rt| t << [rt[:name], rt[:description], rt[:version]] }
77
+ end
78
+ display "\n"
79
+ display rtable
80
+ end
81
+
82
+ def frameworks
83
+ raise VMC::Client::AuthError unless client.logged_in?
84
+ return display JSON.pretty_generate(frameworks_info) if @options[:json]
85
+ return display "No Frameworks" if frameworks_info.empty?
86
+ rtable = table do |t|
87
+ t.headings = ['Name']
88
+ frameworks_info.each { |f| t << f }
89
+ end
90
+ display "\n"
91
+ display rtable
92
+ end
93
+
70
94
  def aliases
71
95
  aliases = VMC::Cli::Config.aliases
72
96
  return display JSON.pretty_generate(aliases) if @options[:json]
73
97
  return display "No Aliases" if aliases.empty?
74
98
  atable = table do |t|
75
- t.headings = 'Alias', "Command"
99
+ t.headings = 'Alias', 'Command'
76
100
  aliases.each { |k,v| t << [k, v] }
77
101
  end
78
102
  display "\n"
@@ -3,7 +3,7 @@ module VMC::Cli::Command
3
3
  class User < Base
4
4
 
5
5
  def info
6
- info = client.info
6
+ info = client_info
7
7
  username = info[:user] || 'N/A'
8
8
  return display JSON.pretty_generate([username]) if @options[:json]
9
9
  display "\n[#{username}]"
@@ -34,7 +34,7 @@ module VMC::Cli::Command
34
34
  end
35
35
 
36
36
  def change_password(password=nil)
37
- info = client.info
37
+ info = client_info
38
38
  email = info[:user]
39
39
  err "Need to be logged in to change password." unless email
40
40
  say "Changing password for '#{email}'\n"
@@ -6,13 +6,21 @@ 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'}],
14
- 'Sinatra' => [DEFAULT_FRAMEWORK, { :mem => '128M', :description => 'Sinatra Application'}],
15
- 'Node' => ['nodejs/1.0', { :mem => '64M', :description => 'Node.js 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
+ # 'Sinatra' => [DEFAULT_FRAMEWORK, { :mem => '128M', :description => 'Sinatra Application'}],
15
+ # 'Node' => ['nodejs/1.0', { :mem => '64M', :description => 'Node.js Application'}],
16
+
17
+ 'Rails' => ['rails3', { :mem => '256M', :description => 'Rails Application'}],
18
+ 'Spring' => ['spring', { :mem => '512M', :description => 'Java SpringSource Spring Application'}],
19
+ 'Grails' => ['grails', { :mem => '512M', :description => 'Java SpringSource Grails Application'}],
20
+ 'Roo' => ['spring', { :mem => '512M', :description => 'Java SpringSource Roo Application'}],
21
+ 'JavaWeb' => ['spring', { :mem => '512M', :description => 'Java Web Application'}],
22
+ 'Sinatra' => ['sinatra', { :mem => '128M', :description => 'Sinatra Application'}],
23
+ 'Node' => ['node', { :mem => '64M', :description => 'Node.js Application'}],
16
24
  }
17
25
 
18
26
  class << self
@@ -55,7 +63,7 @@ module VMC::Cli
55
63
  next if matched_file
56
64
  File.open(fname, 'r') do |f|
57
65
  str = f.read # This might want to be limited
58
- matched_file = fname if (str && str.match(/^\s*require\s*'sinatra'/))
66
+ matched_file = fname if (str && str.match(/^\s*require\s*['"]sinatra['"]/))
59
67
  end
60
68
  end
61
69
  if matched_file
data/lib/cli/runner.rb CHANGED
@@ -45,7 +45,9 @@ class VMC::Cli::Runner
45
45
  opts.on('--all') { @options[:all] = true }
46
46
 
47
47
  # generic tracing and debugging
48
- opts.on('-t', '--trace') { @options[:trace] = true }
48
+ opts.on('-t [TKEY]') { |tkey| @options[:trace] = tkey || true }
49
+ opts.on('--trace [TKEY]') { |tkey| @options[:trace] = tkey || true }
50
+
49
51
  opts.on('-q', '--quiet') { @options[:quiet] = true }
50
52
 
51
53
  # Don't use builtin zip
@@ -71,6 +73,8 @@ class VMC::Cli::Runner
71
73
  opts.on('-v', '--version') { set_cmd(:misc, :version) }
72
74
  opts.on('-h', '--help') { puts "#{command_usage}\n"; exit }
73
75
 
76
+ opts.on('--runtime RUNTIME') { |rt| @options[:runtime] = rt }
77
+
74
78
  # deprecated
75
79
  opts.on('--exec EXEC') { |exec| @options[:exec] = exec }
76
80
  opts.on('--noframework') { @options[:noframework] = true }
@@ -156,6 +160,14 @@ class VMC::Cli::Runner
156
160
  usage('vmc info')
157
161
  set_cmd(:misc, :info)
158
162
 
163
+ when 'runtimes'
164
+ usage('vmc runtimes')
165
+ set_cmd(:misc, :runtimes)
166
+
167
+ when 'frameworks'
168
+ usage('vmc frameworks')
169
+ set_cmd(:misc, :frameworks)
170
+
159
171
  when 'user'
160
172
  usage('vmc user')
161
173
  set_cmd(:user, :info)
@@ -289,6 +301,22 @@ class VMC::Cli::Runner
289
301
  usage('vmc services')
290
302
  set_cmd(:services, :services)
291
303
 
304
+ when 'env'
305
+ usage('vmc env <appname>')
306
+ set_cmd(:apps, :environment, 1)
307
+
308
+ when 'env-add'
309
+ usage('vmc env-add <appname> <variable[=]value>')
310
+ if @args.size == 2
311
+ set_cmd(:apps, :environment_add, 2)
312
+ elsif @args.size == 3
313
+ set_cmd(:apps, :environment_add, 3)
314
+ end
315
+
316
+ when 'env-del'
317
+ usage('vmc env-del <appname> <variable>')
318
+ set_cmd(:apps, :environment_del, 2)
319
+
292
320
  when 'create-service', 'create_service'
293
321
  usage('vmc create-service [service] [servicename] [appname] [--name servicename] [--bind appname]')
294
322
  set_cmd(:services, :create_service) if @args.size == 0
@@ -387,8 +415,8 @@ class VMC::Cli::Runner
387
415
  @options[:colorize] = false unless STDOUT.tty?
388
416
 
389
417
  VMC::Cli::Config.colorize = @options.delete(:colorize)
390
- VMC::Cli::Config.trace = @options.delete(:trace)
391
418
  VMC::Cli::Config.nozip = @options.delete(:nozip)
419
+ VMC::Cli::Config.trace = @options.delete(:trace)
392
420
  VMC::Cli::Config.output ||= STDOUT unless @options[:quiet]
393
421
 
394
422
  process_aliases!
@@ -432,6 +460,10 @@ class VMC::Cli::Runner
432
460
  @exit_status = false
433
461
  rescue SystemExit => e
434
462
  @exit_status = e.success?
463
+ rescue SyntaxError => e
464
+ puts e.message.red
465
+ puts e.backtrace
466
+ @exit_status = false
435
467
  rescue => e
436
468
  puts e.message.red
437
469
  puts e.backtrace
data/lib/cli/usage.rb CHANGED
@@ -62,6 +62,11 @@ Currently available vmc commands are:
62
62
  stats <appname> Display resource usage for the application
63
63
  instances <appname> List application instances
64
64
 
65
+ Application Environment
66
+ env <appname> List application environment variables
67
+ env-add <appname> <variable[=]value> Add an environment variable to an application
68
+ env-del <appname> <variable> Delete an environment variable to an application
69
+
65
70
  Services
66
71
  services Lists of services available and provisioned
67
72
  create-service <service> [--name,--bind] Create a provisioned service
@@ -79,6 +84,10 @@ Currently available vmc commands are:
79
84
  add-user [--email, --passwd] Register a new user (requires admin privileges)
80
85
  delete-user <user> Delete a user and all apps and services (requires admin privileges)
81
86
 
87
+ System
88
+ runtimes Display the supported runtimes of the target system
89
+ frameworks Display the recognized frameworks of the target system
90
+
82
91
  Misc
83
92
  aliases List aliases
84
93
  alias <alias[=]command> Create an alias for a command
data/lib/cli/version.rb CHANGED
@@ -2,6 +2,6 @@ module VMC
2
2
  module Cli
3
3
  # This version number is used as the RubyGem release version.
4
4
  # The internal VMC version number is VMC::VERSION.
5
- VERSION = '0.2.11'
5
+ VERSION = '0.3.6'
6
6
  end
7
7
  end
data/lib/cli/zip_util.rb CHANGED
@@ -51,7 +51,7 @@ module VMC::Cli
51
51
  excludes = PACK_EXCLUSION_GLOBS.map { |e| "\\#{e}" }
52
52
  excludes = excludes.join(' ')
53
53
  Dir.chdir(dir) do
54
- `zip -q -r #{zipfile} . -x #{excludes} 2> /dev/null`
54
+ `zip -y -q -r #{zipfile} . -x #{excludes} 2> /dev/null`
55
55
  return unless $? != 0
56
56
  end
57
57
  end
data/lib/vmc/client.rb CHANGED
@@ -367,13 +367,19 @@ class VMC::Client
367
367
  def perform_http_request(req)
368
368
  RestClient.proxy = ENV['https_proxy'] || ENV['http_proxy']
369
369
 
370
+ # Setup tracing if needed
371
+ unless trace.nil?
372
+ req[:headers]['X-VCAP-Trace'] = (trace == true ? '22' : trace)
373
+ end
374
+
370
375
  result = nil
371
376
  RestClient::Request.execute(req) do |response, request|
372
377
  result = [ response.code, response.body, response.headers ]
373
- if trace
378
+ unless trace.nil?
374
379
  puts '>>>'
375
380
  puts "PROXY: #{RestClient.proxy}" if RestClient.proxy
376
381
  puts "REQUEST: #{req[:method]} #{req[:url]}"
382
+ puts "RESPONSE_HEADERS: #{response.headers}"
377
383
  puts "REQUEST_BODY: #{req[:payload]}" if req[:payload]
378
384
  puts "RESPONSE: [#{response.code}] #{response.body}"
379
385
  puts '<<<'
data/lib/vmc/const.rb CHANGED
@@ -2,7 +2,7 @@ module VMC
2
2
 
3
3
  # This is the internal VMC version number, and is not necessarily
4
4
  # the same as the RubyGem version (VMC::Cli::VERSION).
5
- VERSION = '0.2.8'
5
+ VERSION = '0.3.0'
6
6
 
7
7
  # Targets
8
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: 1
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 11
10
- version: 0.2.11
5
+ version: 0.3.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-04-04 00:00:00 -05:00
13
+ date: 2011-04-07 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,18 +171,12 @@ 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