vmc 0.4.0.beta.55 → 0.4.0.beta.56

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.
@@ -5,34 +5,6 @@ require "vmc/detect"
5
5
 
6
6
  module VMC
7
7
  class App < CLI
8
- # TODO: don't hardcode; bring in from remote
9
- MEM_DEFAULTS_FRAMEWORK = {
10
- "rails3" => "256M",
11
- "spring" => "512M",
12
- "grails" => "512M",
13
- "lift" => "512M",
14
- "java_web" => "512M",
15
- "standalone" => "64M",
16
- "sinatra" => "128M",
17
- "node" => "64M",
18
- "php" => "128M",
19
- "otp_rebar" => "64M",
20
- "wsgi" => "64M",
21
- "django" => "128M",
22
- "dotNet" => "128M",
23
- "rack" => "128M",
24
- "play" => "256M"
25
- }
26
-
27
- MEM_DEFAULTS_RUNTIME = {
28
- "java7" => "512M",
29
- "java" => "512M",
30
- "php" => "128M",
31
- "ruby" => "128M",
32
- "ruby19" => "128M"
33
- }
34
-
35
-
36
8
  desc "List your applications"
37
9
  group :apps
38
10
  input :space, :desc => "Show apps in given space",
@@ -110,42 +82,23 @@ module VMC
110
82
  input(:url, :desc => "URL bound to app") { |default|
111
83
  ask("URL", :default => default)
112
84
  }
113
- input(:memory, :desc => "Memory limit") { |framework, runtime|
85
+ input(:memory, :desc => "Memory limit") { |default|
114
86
  ask("Memory Limit",
115
87
  :choices => memory_choices,
116
88
  :allow_other => true,
117
- :default =>
118
- MEM_DEFAULTS_RUNTIME[runtime] ||
119
- MEM_DEFAULTS_FRAMEWORK[framework] ||
120
- "64M")
89
+ :default => default || "64M")
121
90
  }
122
91
  input(:instances, :type => :integer,
123
92
  :desc => "Number of instances to run") {
124
93
  ask("Instances", :default => 1)
125
94
  }
126
95
  input(:framework, :from_given => find_by_name("framework"),
127
- :desc => "Framework to use") { |choices, default, other|
128
- choices = choices.sort_by(&:name)
129
- choices << other if other
130
-
131
- opts = {
132
- :choices => choices,
133
- :display => proc { |f|
134
- if f == other
135
- "other"
136
- else
137
- f.name
138
- end
139
- }
140
- }
141
-
142
- opts[:default] = default if default
143
-
144
- ask("Framework", opts)
96
+ :desc => "Framework to use") { |choices, default, all, other|
97
+ ask_with_other("Framework", choices, default, all, other)
145
98
  }
146
- input(:runtime, :desc => "Runtime to run it with",
147
- :from_given => find_by_name("runtime")) { |choices|
148
- ask("Runtime", :choices => choices, :display => proc(&:name))
99
+ input(:runtime, :from_given => find_by_name("runtime"),
100
+ :desc => "Runtime to use") { |choices, default, all, other|
101
+ ask_with_other("Runtime", choices, default, all, other)
149
102
  }
150
103
  input(:command, :desc => "Startup command for standalone app") {
151
104
  ask("Startup command")
@@ -891,23 +844,50 @@ module VMC
891
844
  app.production = !!(input[:plan] =~ /^p/i) if v2?
892
845
 
893
846
  detector = Detector.new(client, path)
894
- frameworks = detector.all_frameworks
895
- detected, default = detector.frameworks
847
+ all_frameworks = detector.all_frameworks
848
+ all_runtimes = detector.all_runtimes
849
+
850
+ detected_frameworks = detector.detected_frameworks
851
+
852
+ if detected_frameworks.size == 1
853
+ default_framework = detected_frameworks.first
854
+ end
896
855
 
897
- if detected.empty?
898
- framework = input[:framework, frameworks]
856
+ if detected_frameworks.empty?
857
+ framework = input[:framework, all_frameworks]
899
858
  else
900
- detected_names = detected.collect(&:name).sort
901
- framework = input[:framework, detected, default, :other]
859
+ framework = input[
860
+ :framework,
861
+ detected_frameworks,
862
+ default_framework,
863
+ all_frameworks,
864
+ :other
865
+ ]
866
+ end
902
867
 
903
- if framework == :other
904
- input.forget(:framework)
905
- framework = input[:framework, frameworks]
906
- end
868
+
869
+ if framework.name == "standalone"
870
+ detected_runtimes = detector.detected_runtimes
871
+ else
872
+ detected_runtimes = detector.runtimes(framework)
873
+ end
874
+
875
+ if detected_runtimes.size == 1
876
+ default_runtime = detected_runtimes.first
877
+ end
878
+
879
+ if detected_runtimes.empty?
880
+ runtime = input[:runtime, all_runtimes]
881
+ else
882
+ runtime = input[
883
+ :runtime,
884
+ detected_runtimes,
885
+ default_runtime,
886
+ all_runtimes,
887
+ :other
888
+ ]
907
889
  end
908
890
 
909
- runtimes = framework.runtimes || client.runtimes
910
- runtime = input[:runtime, runtimes]
911
891
 
912
892
  fail "Invalid framework '#{input[:framework]}'" unless framework
913
893
  fail "Invalid runtime '#{input[:runtime]}'" unless runtime
@@ -928,7 +908,8 @@ module VMC
928
908
 
929
909
  app.urls = [url] if url && !v2?
930
910
 
931
- app.memory = megabytes(input[:memory, framework, runtime])
911
+ default_memory = detector.suggested_memory(framework) || 64
912
+ app.memory = megabytes(input[:memory, human_mb(default_memory)])
932
913
 
933
914
  app = filter(:create_app, app)
934
915
 
@@ -1105,6 +1086,32 @@ module VMC
1105
1086
  end
1106
1087
  end
1107
1088
 
1089
+ def ask_with_other(message, choices, default, all, other)
1090
+ choices = choices.sort_by(&:name)
1091
+ choices << other if other
1092
+
1093
+ opts = {
1094
+ :choices => choices,
1095
+ :display => proc { |x|
1096
+ if other && x == other
1097
+ "other"
1098
+ else
1099
+ x.name
1100
+ end
1101
+ }
1102
+ }
1103
+
1104
+ opts[:default] = default if default
1105
+
1106
+ res = ask(message, opts)
1107
+
1108
+ if other && res == other
1109
+ opts[:choices] = all
1110
+ res = ask(message, opts)
1111
+ end
1112
+
1113
+ res
1114
+ end
1108
1115
  def usage(used, limit)
1109
1116
  "#{b(human_size(used))} of #{b(human_size(limit, 0))}"
1110
1117
  end
@@ -1,5 +1,36 @@
1
+ require "set"
2
+
3
+ require "clouseau"
4
+
1
5
  module VMC
2
6
  class Detector
7
+ # "Basic" framework names for a detected language
8
+ PSEUDO_FRAMEWORKS = {
9
+ :node => "node",
10
+ :python => "wsgi",
11
+ :java => "java_web",
12
+ :php => "php",
13
+ :erlang => "otp_rebar",
14
+ :dotnet => "dotNet"
15
+ }
16
+
17
+ # Clouseau language symbol => matching runtime names
18
+ LANGUAGE_RUNTIMES = {
19
+ :ruby => /^ruby.*/,
20
+ :java => /^java.*/,
21
+ :node => /^node.*/,
22
+ :erlang => /^erlang.*/,
23
+ :dotnet => /^dotNet.*/,
24
+ :python => /^python.*/,
25
+ :php => /^php.*/
26
+ }
27
+
28
+ # [Framework]
29
+ attr_reader :matches
30
+
31
+ # Framework
32
+ attr_reader :default
33
+
3
34
  def initialize(client, path)
4
35
  @client = client
5
36
  @path = path
@@ -10,89 +41,81 @@ module VMC
10
41
  end
11
42
 
12
43
  def all_runtimes
13
- @all_runtiems ||= @client.runtimes
44
+ @all_runtimes ||= @client.runtimes
14
45
  end
15
46
 
16
47
  def all_frameworks
17
48
  @all_frameworks ||= @client.frameworks
49
+ end
50
+
51
+ def matches
52
+ return @matches if @matches
18
53
 
19
- @all_frameworks.each do |f|
20
- next if f.detection && f.runtimes
54
+ frameworks = all_frameworks
21
55
 
22
- if info = framework_info[f.name.to_sym]
23
- f.detection = info[:detection]
56
+ @matches = {}
24
57
 
25
- runtime_names = info[:runtimes].collect { |r| r[:name] }
26
- f.runtimes = all_runtimes.select { |r|
27
- runtime_names.include?(r.name)
58
+ Clouseau.matches(@path).each do |detected|
59
+ if name = detected.framework_name
60
+ framework = frameworks.find { |f|
61
+ f.name == name.to_s
28
62
  }
29
63
  end
64
+
65
+ if !framework && lang = detected.language_name
66
+ framework = frameworks.find { |f|
67
+ f.name == PSEUDO_FRAMEWORKS[lang]
68
+ }
69
+ end
70
+
71
+ next unless framework
72
+
73
+ @matches[framework] = detected
30
74
  end
31
75
 
32
- @all_frameworks
76
+ @matches
33
77
  end
34
78
 
35
- def frameworks
36
- matches = []
37
- all_frameworks.each do |framework|
38
- matched = false
39
-
40
- # e.g. standalone has no detection
41
- next if framework.detection.nil? || framework.detection.empty?
42
-
43
- framework.detection.first.each do |file, match|
44
- files =
45
- if File.file? @path
46
- if File.fnmatch(file, @path)
47
- [@path]
48
- elsif @path =~ /\.(zip|jar|war)/
49
- lines = CFoundry::Zip.entry_lines(@path)
50
- top = find_top(lines)
51
-
52
- lines.collect(&:name).select do |path|
53
- File.fnmatch(file, path) ||
54
- top && File.fnmatch(top + file, path)
55
- end
56
- else
57
- []
58
- end
59
- else
60
- Dir.glob("#@path/#{file}")
61
- end
62
-
63
- unless files.empty?
64
- if match == true
65
- matched = true
66
- elsif match == false
67
- matched = false
68
- break
69
- else
70
- begin
71
- files.each do |f|
72
- contents = File.open(f, &:read)
73
- if contents =~ Regexp.new(match)
74
- matched = true
75
- end
76
- end
77
- rescue RegexpError
78
- # some regexps may fail on 1.8 as the server runs 1.9
79
- end
80
- end
81
- end
79
+ def detected_frameworks
80
+ matches.keys
81
+ end
82
+
83
+ def detected_runtimes
84
+ langs = Set.new
85
+
86
+ Clouseau.matches(@path).each do |detected|
87
+ if lang = detected.language_name
88
+ langs << lang
82
89
  end
90
+ end
91
+
92
+ runtimes = []
83
93
 
84
- matches << framework if matched
94
+ langs.each do |lang|
95
+ runtimes += runtimes_for(lang)
85
96
  end
86
97
 
87
- if matches.size == 1
88
- default = matches.first
98
+ runtimes
99
+ end
100
+
101
+ def runtimes(framework)
102
+ if matches[framework] && lang = matches[framework].language_name
103
+ runtimes_for(lang)
89
104
  end
105
+ end
90
106
 
91
- [matches, default]
107
+ def suggested_memory(framework)
108
+ matches[framework] && mem = matches[framework].memory_suggestion
92
109
  end
93
110
 
94
111
  private
95
112
 
113
+ def runtimes_for(language)
114
+ all_runtimes.select do |r|
115
+ LANGUAGE_RUNTIMES[language] === r.name
116
+ end
117
+ end
118
+
96
119
  def find_top(entries)
97
120
  found = false
98
121
 
@@ -1,3 +1,3 @@
1
1
  module VMC
2
- VERSION = "0.4.0.beta.55"
2
+ VERSION = "0.4.0.beta.56"
3
3
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vmc
3
3
  version: !ruby/object:Gem::Version
4
- hash: -3856277458
4
+ hash: -4198322296
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
9
  - 0
10
10
  - beta
11
- - 55
12
- version: 0.4.0.beta.55
11
+ - 56
12
+ version: 0.4.0.beta.56
13
13
  platform: ruby
14
14
  authors:
15
15
  - VMware
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2012-09-24 00:00:00 Z
20
+ date: 2012-09-26 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: json_pure
@@ -274,9 +274,25 @@ dependencies:
274
274
  type: :runtime
275
275
  version_requirements: *id015
276
276
  - !ruby/object:Gem::Dependency
277
- name: mothership
277
+ name: clouseau
278
278
  prerelease: false
279
279
  requirement: &id016 !ruby/object:Gem::Requirement
280
+ none: false
281
+ requirements:
282
+ - - ~>
283
+ - !ruby/object:Gem::Version
284
+ hash: 29
285
+ segments:
286
+ - 0
287
+ - 0
288
+ - 1
289
+ version: 0.0.1
290
+ type: :runtime
291
+ version_requirements: *id016
292
+ - !ruby/object:Gem::Dependency
293
+ name: mothership
294
+ prerelease: false
295
+ requirement: &id017 !ruby/object:Gem::Requirement
280
296
  none: false
281
297
  requirements:
282
298
  - - ~>
@@ -288,11 +304,11 @@ dependencies:
288
304
  - 5
289
305
  version: 0.1.5
290
306
  type: :runtime
291
- version_requirements: *id016
307
+ version_requirements: *id017
292
308
  - !ruby/object:Gem::Dependency
293
309
  name: manifests-vmc-plugin
294
310
  prerelease: false
295
- requirement: &id017 !ruby/object:Gem::Requirement
311
+ requirement: &id018 !ruby/object:Gem::Requirement
296
312
  none: false
297
313
  requirements:
298
314
  - - ~>
@@ -304,11 +320,11 @@ dependencies:
304
320
  - 7
305
321
  version: 0.4.7
306
322
  type: :runtime
307
- version_requirements: *id017
323
+ version_requirements: *id018
308
324
  - !ruby/object:Gem::Dependency
309
325
  name: tunnel-dummy-vmc-plugin
310
326
  prerelease: false
311
- requirement: &id018 !ruby/object:Gem::Requirement
327
+ requirement: &id019 !ruby/object:Gem::Requirement
312
328
  none: false
313
329
  requirements:
314
330
  - - ~>
@@ -320,11 +336,11 @@ dependencies:
320
336
  - 1
321
337
  version: 0.0.1
322
338
  type: :runtime
323
- version_requirements: *id018
339
+ version_requirements: *id019
324
340
  - !ruby/object:Gem::Dependency
325
341
  name: multi_json
326
342
  prerelease: false
327
- requirement: &id019 !ruby/object:Gem::Requirement
343
+ requirement: &id020 !ruby/object:Gem::Requirement
328
344
  none: false
329
345
  requirements:
330
346
  - - ~>
@@ -336,11 +352,11 @@ dependencies:
336
352
  - 6
337
353
  version: 1.3.6
338
354
  type: :runtime
339
- version_requirements: *id019
355
+ version_requirements: *id020
340
356
  - !ruby/object:Gem::Dependency
341
357
  name: rake
342
358
  prerelease: false
343
- requirement: &id020 !ruby/object:Gem::Requirement
359
+ requirement: &id021 !ruby/object:Gem::Requirement
344
360
  none: false
345
361
  requirements:
346
362
  - - ~>
@@ -353,11 +369,11 @@ dependencies:
353
369
  - 2
354
370
  version: 0.9.2.2
355
371
  type: :development
356
- version_requirements: *id020
372
+ version_requirements: *id021
357
373
  - !ruby/object:Gem::Dependency
358
374
  name: rspec
359
375
  prerelease: false
360
- requirement: &id021 !ruby/object:Gem::Requirement
376
+ requirement: &id022 !ruby/object:Gem::Requirement
361
377
  none: false
362
378
  requirements:
363
379
  - - ~>
@@ -369,11 +385,11 @@ dependencies:
369
385
  - 0
370
386
  version: 2.11.0
371
387
  type: :development
372
- version_requirements: *id021
388
+ version_requirements: *id022
373
389
  - !ruby/object:Gem::Dependency
374
390
  name: simplecov
375
391
  prerelease: false
376
- requirement: &id022 !ruby/object:Gem::Requirement
392
+ requirement: &id023 !ruby/object:Gem::Requirement
377
393
  none: false
378
394
  requirements:
379
395
  - - ~>
@@ -385,7 +401,7 @@ dependencies:
385
401
  - 4
386
402
  version: 0.6.4
387
403
  type: :development
388
- version_requirements: *id022
404
+ version_requirements: *id023
389
405
  description:
390
406
  email: support@vmware.com
391
407
  executables: