vmc 0.4.0.beta.2 → 0.4.0.beta.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,33 +5,69 @@ module VMC
5
5
  class App < Command
6
6
  MEM_CHOICES = ["64M", "128M", "256M", "512M"]
7
7
 
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
+
8
36
  desc "push [NAME]", "Push an application, syncing changes if it exists"
9
37
  group :apps, :manage
10
38
  flag(:name) { ask("Name") }
11
- flag(:path) {
12
- ask("Push from...", :default => ".")
13
- }
39
+ flag(:path, :default => ".")
14
40
  flag(:url) { |name, target|
15
41
  ask("URL", :default => "#{name}.#{target}")
16
42
  }
17
- flag(:memory) {
43
+ flag(:memory) { |framework, runtime|
18
44
  ask("Memory Limit",
19
45
  :choices => MEM_CHOICES,
20
-
21
- # TODO: base this on framework choice
22
- :default => "64M")
46
+ :default =>
47
+ MEM_DEFAULTS_RUNTIME[runtime] ||
48
+ MEM_DEFAULTS_FRAMEWORK[framework] ||
49
+ "64M")
23
50
  }
24
51
  flag(:instances) {
25
52
  ask("Instances", :default => 1)
26
53
  }
27
54
  flag(:framework) { |choices, default|
28
- ask("Framework", :choices => choices, :default => default)
55
+ opts = {:choices => choices}
56
+ opts[:default] = default if default
57
+
58
+ ask("Framework", :choices => choices)
29
59
  }
30
60
  flag(:runtime) { |choices|
31
61
  ask("Runtime", :choices => choices)
32
62
  }
33
63
  flag(:start, :default => true)
34
64
  flag(:restart, :default => true)
65
+ flag(:create_services, :type => :boolean) {
66
+ ask "Create services for application?", :default => false
67
+ }
68
+ flag(:bind_services, :type => :boolean) {
69
+ ask "Bind other services to application?", :default => false
70
+ }
35
71
  def push(name = nil)
36
72
  path = File.expand_path(input(:path))
37
73
 
@@ -54,10 +90,10 @@ module VMC
54
90
  domain = client.target.sub(/^https?:\/\/api\.(.+)\/?/, '\1')
55
91
  app.urls = [input(:url, name, domain)]
56
92
 
57
- framework = input(:framework, ["other"] + detected.keys, default)
93
+ framework = input(:framework, ["other"] + detected.keys.sort, default)
58
94
  if framework == "other"
59
95
  forget(:framework)
60
- framework = input(:framework, frameworks.keys)
96
+ framework = input(:framework, frameworks.keys.sort, nil)
61
97
  end
62
98
 
63
99
  framework_runtimes =
@@ -66,12 +102,64 @@ module VMC
66
102
  end
67
103
 
68
104
  # TODO: include descriptions
69
- runtime = input(:runtime, framework_runtimes).split.first
105
+ runtime = input(:runtime, framework_runtimes.sort).split.first
70
106
 
71
107
  app.framework = framework
72
108
  app.runtime = runtime
73
109
 
74
- app.memory = megabytes(input(:memory))
110
+ app.memory = megabytes(input(:memory, framework, runtime))
111
+
112
+ bindings = []
113
+ if input(:create_services) && !force?
114
+ services = client.system_services
115
+
116
+ while true
117
+ vendor = ask "What kind?", :choices => services.keys.sort
118
+ meta = services[vendor]
119
+
120
+ if meta[:versions].size == 1
121
+ version = meta[:versions].first
122
+ else
123
+ version = ask "Which version?",
124
+ :choices => meta[:versions].sort.reverse
125
+ end
126
+
127
+ random = sprintf("%x", rand(1000000))
128
+ service_name = ask "Service name?", :default => "#{vendor}-#{random}"
129
+
130
+ service = client.service(service_name)
131
+ service.type = meta[:type]
132
+ service.vendor = meta[:vendor]
133
+ service.version = version
134
+ service.tier = "free"
135
+
136
+ with_progress("Creating service #{c(service_name, :blue)}") do
137
+ service.create!
138
+ end
139
+
140
+ bindings << service_name
141
+
142
+ break unless ask "Create another service?", :default => false
143
+ end
144
+ end
145
+
146
+ if input(:bind_services) && !force?
147
+ services = client.services.collect(&:name)
148
+
149
+ while true
150
+ choices = services - bindings
151
+ break if choices.empty?
152
+
153
+ bindings << ask("Bind which service?", :choices => choices.sort)
154
+
155
+ unless bindings.size < services.size &&
156
+ ask("Bind another service?", :default => false)
157
+ break
158
+ end
159
+ end
160
+ end
161
+
162
+ app.services = bindings
75
163
 
76
164
  with_progress("Creating #{c(name, :blue)}") do
77
165
  app.create!
@@ -189,7 +277,7 @@ module VMC
189
277
  apps = client.apps
190
278
  fail "No applications." if apps.empty?
191
279
 
192
- names = [input(:name, apps.collect(&:name))]
280
+ names = [input(:name, apps.collect(&:name).sort)]
193
281
  end
194
282
 
195
283
  names.each do |name|
@@ -139,8 +139,10 @@ module VMC
139
139
 
140
140
  class_option :proxy, :aliases => "-u", :desc => "Proxy user"
141
141
 
142
- class_option :verbose,
143
- :type => :boolean, :aliases => "-v", :desc => "Verbose"
142
+ class_option :version,
143
+ :type => :boolean, :aliases => "-v", :desc => "Print version number"
144
+
145
+ class_option :verbose, :type => :boolean, :desc => "Verbose"
144
146
 
145
147
  class_option :force,
146
148
  :type => :boolean, :aliases => "-f", :desc => "Force (no interaction)"
@@ -359,6 +361,8 @@ module VMC
359
361
  raise
360
362
  rescue UserError => e
361
363
  err e.message
364
+ rescue CFoundry::Denied => e
365
+ err NotAuthorized.new.message
362
366
  rescue Exception => e
363
367
  msg = e.class.name
364
368
  msg << ": #{e}" unless e.to_s.empty?
@@ -4,47 +4,35 @@ module VMC
4
4
  class Service < Command
5
5
  desc "create", "Create a service"
6
6
  group :services, :manage
7
- flag(:type) { |choices|
7
+ flag(:vendor) { |choices|
8
8
  ask "What kind?", :choices => choices
9
9
  }
10
+ flag(:version) { |choices|
11
+ ask "Which version?", :choices => choices
12
+ }
10
13
  flag(:name) { |vendor|
11
14
  random = sprintf("%x", rand(1000000))
12
15
  ask "Name?", :default => "#{vendor}-#{random}"
13
16
  }
14
17
  def create
15
- choices = []
16
- manifests = {}
17
- client.system_services.each do |type, vendors|
18
- vendors.each do |vendor, versions|
19
- versions.each do |version, _|
20
- choice = "#{vendor} #{version}"
21
- manifests[choice] = {
22
- :type => type,
23
- :vendor => vendor,
24
- :version => version
25
- }
26
-
27
- choices << choice
28
- end
29
- end
30
- end
18
+ services = client.system_services
31
19
 
32
- type = input(:type, choices)
33
- meta = manifests[type]
20
+ vendor = input(:vendor, services.keys)
21
+ meta = services[vendor]
34
22
 
35
- # --type redis should work, and just ignore version
36
- unless meta
37
- _, meta = manifests.find { |k, _| k.split.first == type }
38
- fail "Unknown service type." unless meta
23
+ if meta[:versions].size == 1
24
+ version = meta[:versions].first
25
+ else
26
+ version = input(:version, meta[:versions])
39
27
  end
40
28
 
41
29
  service = client.service(input(:name, meta[:vendor]))
42
30
  service.type = meta[:type]
43
31
  service.vendor = meta[:vendor]
44
- service.version = meta[:version]
32
+ service.version = version
45
33
  service.tier = "free"
46
34
 
47
- with_progress("Creating service") do
35
+ with_progress("Creating service #{c(service.name, :blue)}") do
48
36
  service.create!
49
37
  end
50
38
  end
@@ -117,6 +105,8 @@ module VMC
117
105
  with_progress("Deleting #{c(name, :blue)}") do
118
106
  client.service(name).delete!
119
107
  end
108
+ ensure
109
+ forget(:really)
120
110
  end
121
111
  end
122
112
  end
@@ -16,9 +16,8 @@ module VMC
16
16
  def create(email = nil)
17
17
  email ||= input(:email)
18
18
  password = input(:password)
19
- verify = input(:verify)
20
19
 
21
- if password != verify
20
+ if !force? && password != input(:verify)
22
21
  fail "Passwords don't match."
23
22
  end
24
23
 
@@ -67,12 +67,7 @@ module VMC
67
67
  if input(:services)
68
68
  raise NotAuthorized unless authorized
69
69
 
70
- services = {}
71
- client.system_services.each do |_, svcs|
72
- svcs.each do |name, versions|
73
- services[name] = versions.values
74
- end
75
- end
70
+ services = client.system_services
76
71
 
77
72
  if simple_output?
78
73
  services.each do |name, _|
@@ -82,12 +77,12 @@ module VMC
82
77
  return
83
78
  end
84
79
 
85
- services.each do |name, versions|
80
+ services.each do |name, meta|
86
81
  puts ""
87
82
  puts "#{c(name, :blue)}:"
88
- puts " versions: #{versions.collect { |v| v["version"] }.join ", "}"
89
- puts " description: #{versions[0]["description"]}"
90
- puts " type: #{versions[0]["type"]}"
83
+ puts " versions: #{meta[:versions].join ", "}"
84
+ puts " description: #{meta[:description]}"
85
+ puts " type: #{meta[:type]}"
91
86
  end
92
87
 
93
88
  return
@@ -208,6 +203,9 @@ module VMC
208
203
  flag(:password) {
209
204
  ask("Password", :echo => "*", :forget => true)
210
205
  }
206
+ flag(:verify_password) {
207
+ ask("Confirm Password", :echo => "*", :forget => true)
208
+ }
211
209
  flag(:no_login, :type => :boolean)
212
210
  def register(email = nil)
213
211
  unless simple_output?
@@ -216,7 +214,11 @@ module VMC
216
214
  end
217
215
 
218
216
  email ||= input(:email)
219
- password = input(:password)
217
+ password ||= input(:password)
218
+
219
+ if !force? && password != input(:verify_password)
220
+ fail "Passwords do not match."
221
+ end
220
222
 
221
223
  with_progress("Creating user") do
222
224
  client.register(email, password)
@@ -284,6 +286,11 @@ module VMC
284
286
  flag :all, :default => false
285
287
  group :start
286
288
  def help(task = nil)
289
+ if options[:version]
290
+ puts "vmc #{VERSION}"
291
+ return
292
+ end
293
+
287
294
  if task
288
295
  self.class.task_help(@shell, task)
289
296
  else
@@ -10,6 +10,25 @@ module VMC
10
10
  info["frameworks"] || {}
11
11
  end
12
12
 
13
+ def find_top(entries)
14
+ found = false
15
+
16
+ entries.each do |e|
17
+ is_toplevel =
18
+ e.ftype == :directory && e.name.index("/") + 1 == e.name.size
19
+
20
+ if is_toplevel && e.name !~ /^(\.|__MACOSX)/
21
+ if found
22
+ return false
23
+ else
24
+ found = e.name
25
+ end
26
+ end
27
+ end
28
+
29
+ found
30
+ end
31
+
13
32
  def frameworks
14
33
  info = @client.info
15
34
 
@@ -25,6 +44,14 @@ module VMC
25
44
  if File.file? @path
26
45
  if File.fnmatch(file, @path)
27
46
  [@path]
47
+ elsif @path =~ /\.(zip|jar|war)/
48
+ lines = CFoundry::Zip.entry_lines(@path)
49
+ top = find_top(lines)
50
+
51
+ lines.collect(&:name).select do |path|
52
+ File.fnmatch(file, path) ||
53
+ top && File.fnmatch(top + file, path)
54
+ end
28
55
  else
29
56
  []
30
57
  end
@@ -1,3 +1,3 @@
1
1
  module VMC
2
- VERSION = "0.1.5"
2
+ VERSION = "0.4.0.beta.3"
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: 62196455
4
+ hash: 62196453
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
9
  - 0
10
10
  - beta
11
- - 2
12
- version: 0.4.0.beta.2
11
+ - 3
12
+ version: 0.4.0.beta.3
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-05-30 00:00:00 Z
20
+ date: 2012-06-04 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: json_pure
@@ -249,12 +249,12 @@ dependencies:
249
249
  requirements:
250
250
  - - ~>
251
251
  - !ruby/object:Gem::Version
252
- hash: 31
252
+ hash: 23
253
253
  segments:
254
254
  - 0
255
- - 1
256
255
  - 2
257
- version: 0.1.2
256
+ - 0
257
+ version: 0.2.0
258
258
  type: :runtime
259
259
  version_requirements: *id014
260
260
  - !ruby/object:Gem::Dependency