vmc 0.4.0.beta.16 → 0.4.0.beta.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -226,6 +226,10 @@ module VMC
226
226
  save_targets(ts)
227
227
  end
228
228
 
229
+ def no_v2
230
+ fail "Not implemented for v2." if v2?
231
+ end
232
+
229
233
  def v2?
230
234
  client.is_a?(CFoundry::V2::Client)
231
235
  end
@@ -33,6 +33,14 @@ module VMC
33
33
  }
34
34
 
35
35
 
36
+ def self.find_by_name(what)
37
+ proc { |name, choices|
38
+ choices.find { |c| c.name == name } ||
39
+ fail("Unknown #{what} '#{name}'")
40
+ }
41
+ end
42
+
43
+
36
44
  desc "List your applications"
37
45
  group :apps
38
46
  input :name, :desc => "Filter by name regexp"
@@ -86,14 +94,29 @@ module VMC
86
94
  :desc => "Number of instances to run") {
87
95
  ask("Instances", :default => 1)
88
96
  }
89
- input(:framework, :desc => "Framework to use") { |choices, default|
90
- opts = {:choices => choices}
97
+ input(:framework, :desc => "Framework to use",
98
+ :from_given => find_by_name("framework")) { |choices, default, other|
99
+ choices = choices.sort_by(&:name)
100
+ choices << other if other
101
+
102
+ opts = {
103
+ :choices => choices,
104
+ :display => proc { |f|
105
+ if f == other
106
+ "other"
107
+ else
108
+ f.name
109
+ end
110
+ }
111
+ }
112
+
91
113
  opts[:default] = default if default
92
114
 
93
115
  ask("Framework", opts)
94
116
  }
95
- input(:runtime, :desc => "Runtime to run it with") { |choices|
96
- ask("Runtime", :choices => choices)
117
+ input(:runtime, :desc => "Runtime to run it with",
118
+ :from_given => find_by_name("runtime")) { |choices|
119
+ ask("Runtime", :choices => choices, :display => proc(&:name))
97
120
  }
98
121
  input(:command, :desc => "Startup command for standalone app") {
99
122
  ask("Startup command")
@@ -115,14 +138,7 @@ module VMC
115
138
 
116
139
  name = input[:name] if input[:name]
117
140
 
118
- exists =
119
- if v2?
120
- client.current_space.apps.find { |a| a.name == name }
121
- elsif client.app(name).exists?
122
- client.app(name)
123
- end
124
-
125
- if exists
141
+ if exists = client.app_by_name(name)
126
142
  upload_app(exists, path)
127
143
  invoke :restart, :name => exists.name if input[:restart]
128
144
  return
@@ -137,28 +153,22 @@ module VMC
137
153
  app.space = client.current_space if v2?
138
154
  app.total_instances = input[:instances]
139
155
 
140
- framework_names = frameworks.collect(&:name).sort
141
156
  if detected.empty?
142
- framework_name = input[:framework, framework_names, nil]
157
+ framework = input[:framework, frameworks, nil, false]
143
158
  else
144
159
  detected_names = detected.collect(&:name).sort
145
- framework_name =
146
- input[:framework, detected_names + ["other"], default && default.name]
160
+ framework = input[:framework, detected, default, true]
147
161
 
148
- if framework_name == "other"
162
+ if framework == :other
149
163
  input.forget(:framework)
150
- framework_name = input[:framework, framework_names, nil]
164
+ framework = input[:framework, frameworks, nil, false]
151
165
  end
152
166
  end
153
167
 
154
- framework = frameworks.find { |f| f.name == framework_name }
155
-
156
168
  runtimes = v2? ? client.runtimes : framework.runtimes
157
- runtime_name = input[:runtime, runtimes.collect(&:name).sort]
158
- runtime = runtimes.find { |r| r.name == runtime_name }
169
+ runtime = input[:runtime, runtimes]
159
170
 
160
171
  fail "Invalid framework '#{input[:framework]}'" unless framework
161
-
162
172
  fail "Invalid runtime '#{input[:runtime]}'" unless runtime
163
173
 
164
174
  app.framework = framework
@@ -237,10 +247,12 @@ module VMC
237
247
  names = input[:names]
238
248
  fail "No applications given." if names.empty?
239
249
 
250
+ apps = client.apps
251
+
240
252
  names.each do |name|
241
- app = client.app(name)
253
+ app = apps.find { |a| a.name == name }
242
254
 
243
- fail "Unknown application '#{name}'" unless app.exists?
255
+ fail "Unknown application '#{name}'" unless app
244
256
 
245
257
  app = filter(:start_app, app)
246
258
 
@@ -256,6 +268,9 @@ module VMC
256
268
  app.start!
257
269
  end
258
270
 
271
+ # TODO: reenable for v2
272
+ next if v2?
273
+
259
274
  check_application(app)
260
275
 
261
276
  if app.debug_mode && !quiet?
@@ -274,16 +289,14 @@ module VMC
274
289
  names = input[:names]
275
290
  fail "No applications given." if names.empty?
276
291
 
292
+ apps = client.apps
293
+
277
294
  names.each do |name|
278
- with_progress("Stopping #{c(name, :name)}") do |s|
279
- app = client.app(name)
295
+ app = apps.find { |a| a.name == name }
280
296
 
281
- unless app.exists?
282
- s.fail do
283
- err "Unknown application '#{name}'"
284
- end
285
- end
297
+ fail "Unknown application '#{name}'" unless app
286
298
 
299
+ with_progress("Stopping #{c(name, :name)}") do |s|
287
300
  if app.stopped?
288
301
  s.skip do
289
302
  err "Application is not running."
@@ -311,12 +324,14 @@ module VMC
311
324
 
312
325
  desc "Delete an application"
313
326
  group :apps, :manage
314
- input(:really, :type => :boolean) { |name, color|
327
+ input(:really, :type => :boolean, :forget => true) { |name, color|
315
328
  force? || ask("Really delete #{c(name, color)}?", :default => false)
316
329
  }
317
- input(:names, :argument => :splat, :singular => :name,
318
- :desc => "Applications to delete") { |names|
319
- [ask("Delete which application?", :choices => names)]
330
+ input(:apps, :argument => :splat, :singular => :app,
331
+ :desc => "Applications to delete",
332
+ :from_given => find_by_name("application")) { |apps|
333
+ [ask("Delete which application?", :choices => apps.sort_by(&:name),
334
+ :display => proc(&:name))]
320
335
  }
321
336
  input :orphaned, :aliases => "-o", :type => :boolean,
322
337
  :desc => "Delete orphaned instances"
@@ -344,15 +359,7 @@ module VMC
344
359
  apps = client.apps
345
360
  fail "No applications." if apps.empty?
346
361
 
347
- names = input[:names, apps.collect(&:name).sort]
348
-
349
- to_delete = names.collect do |n|
350
- if app = apps.find { |a| a.name == n }
351
- app
352
- else
353
- fail "Unknown application '#{n}'"
354
- end
355
- end
362
+ to_delete = input[:apps, apps]
356
363
 
357
364
  deleted = []
358
365
  to_delete.each do |app|
@@ -379,13 +386,15 @@ module VMC
379
386
  input :names, :argument => :splat, :singular => :name,
380
387
  :desc => "Applications to list instances of"
381
388
  def instances(input)
389
+ no_v2
390
+
382
391
  names = input[:names]
383
392
  fail "No applications given." if names.empty?
384
393
 
385
394
  names.each do |name|
386
395
  instances =
387
396
  with_progress("Getting instances for #{c(name, :name)}") do
388
- client.app(name).instances
397
+ client.app_by_name(name).instances
389
398
  end
390
399
 
391
400
  instances.each do |i|
@@ -415,7 +424,7 @@ module VMC
415
424
  :desc => "Restart app after updating?"
416
425
  def scale(input)
417
426
  name = input[:name]
418
- app = client.app(name)
427
+ app = client.app_by_name(name)
419
428
 
420
429
  instances = input.given(:instances)
421
430
  memory = input.given(:memory)
@@ -453,9 +462,11 @@ module VMC
453
462
  input :all, :default => false,
454
463
  :desc => "Get logs for every instance"
455
464
  def logs(input)
465
+ no_v2
466
+
456
467
  name = input[:name]
457
468
 
458
- app = client.app(name)
469
+ app = client.app_by_name(name)
459
470
  fail "Unknown application '#{name}'" unless app.exists?
460
471
 
461
472
  instances =
@@ -504,6 +515,8 @@ module VMC
504
515
  input :path, :argument => true, :default => "/",
505
516
  :desc => "Path of file to read"
506
517
  def file(input)
518
+ no_v2
519
+
507
520
  file =
508
521
  with_progress("Getting file contents") do
509
522
  client.app(input[:name]).file(*input[:path].split("/"))
@@ -521,6 +534,8 @@ module VMC
521
534
  input :path, :argument => true, :default => "/",
522
535
  :desc => "Path of directory to list"
523
536
  def files(input)
537
+ no_v2
538
+
524
539
  files =
525
540
  with_progress("Getting file listing") do
526
541
  client.app(input[:name]).files(*input[:path].split("/"))
@@ -538,10 +553,12 @@ module VMC
538
553
  input :names, :argument => :splat, :singular => :name,
539
554
  :desc => "Application to check the status of"
540
555
  def health(input)
556
+ # TODO: get all apps and filter
557
+
541
558
  apps =
542
559
  with_progress("Getting application health") do
543
560
  input[:names].collect do |n|
544
- [n, app_status(client.app(n))]
561
+ [n, app_status(client.app_by_name(n))]
545
562
  end
546
563
  end
547
564
 
@@ -561,9 +578,11 @@ module VMC
561
578
  input :name, :argument => true,
562
579
  :desc => "Application to get the stats for"
563
580
  def stats(input)
581
+ no_v2
582
+
564
583
  stats =
565
584
  with_progress("Getting stats for #{c(input[:name], :name)}") do
566
- client.app(input[:name]).stats
585
+ client.app_by_name(input[:name]).stats
567
586
  end
568
587
 
569
588
  stats.sort_by { |k, _| k }.each do |idx, info|
@@ -592,11 +611,13 @@ module VMC
592
611
  input :url, :argument => true,
593
612
  :desc => "URL to route"
594
613
  def map(input)
614
+ no_v2
615
+
595
616
  name = input[:name]
596
617
  simple = input[:url].sub(/^https?:\/\/(.*)\/?/i, '\1')
597
618
 
598
619
  with_progress("Updating #{c(name, :name)}") do
599
- app = client.app(name)
620
+ app = client.app_by_name(name)
600
621
  app.urls << simple
601
622
  app.update!
602
623
  end
@@ -611,8 +632,10 @@ module VMC
611
632
  ask("Which URL?", :choices => choices)
612
633
  }
613
634
  def unmap(input)
635
+ no_v2
636
+
614
637
  name = input[:name]
615
- app = client.app(name)
638
+ app = client.app_by_name(name)
616
639
 
617
640
  url = input[:url, app.urls]
618
641
 
@@ -642,7 +665,7 @@ module VMC
642
665
 
643
666
  vars =
644
667
  with_progress("Getting env for #{c(input[:name], :name)}") do |s|
645
- app = client.app(appname)
668
+ app = client.app_by_name(appname)
646
669
 
647
670
  unless app.exists?
648
671
  s.fail do
@@ -689,7 +712,7 @@ module VMC
689
712
  fail "Invalid variable name; must match #{VALID_ENV_VAR.inspect}"
690
713
  end
691
714
 
692
- app = client.app(appname)
715
+ app = client.app_by_name(appname)
693
716
  fail "Unknown application '#{appname}'" unless app.exists?
694
717
 
695
718
  with_progress("Updating #{c(app.name, :name)}") do
@@ -721,7 +744,7 @@ module VMC
721
744
  appname = input[:name]
722
745
  name = input[:var]
723
746
 
724
- app = client.app(appname)
747
+ app = client.app_by_name(appname)
725
748
  fail "Unknown application '#{appname}'" unless app.exists?
726
749
 
727
750
  with_progress("Updating #{c(app.name, :name)}") do
@@ -752,11 +775,11 @@ module VMC
752
775
  end
753
776
 
754
777
  if runtime = options[:runtime]
755
- return false if a.runtime !~ /#{runtime}/
778
+ return false if a.runtime.name !~ /#{runtime}/
756
779
  end
757
780
 
758
781
  if framework = options[:framework]
759
- return false if a.framework !~ /#{framework}/
782
+ return false if a.framework.name !~ /#{framework}/
760
783
  end
761
784
 
762
785
  if url = options[:url]
@@ -12,9 +12,9 @@ module VMC
12
12
  end
13
13
  end
14
14
 
15
- def list_choices(choices, options)
15
+ def list_choices(choices, options = {})
16
16
  choices.each_with_index do |o, i|
17
- puts "#{c(i + 1, :number)}: #{o}"
17
+ puts "#{c(i + 1, :number)}: #{show_choice(o, options)}"
18
18
  end
19
19
  end
20
20
 
@@ -6,69 +6,87 @@ module VMC
6
6
  group :services
7
7
  input :name, :desc => "Filter by name regexp"
8
8
  input :app, :desc => "Filter by bound application regexp"
9
+ input :service, :desc => "Filter by service regexp"
10
+ # TODO: not in v2
9
11
  input :type, :desc => "Filter by service type regexp"
10
- input :vendor, :desc => "Filter by service vendor regexp"
11
12
  input :tier, :desc => "Filter by service tier regexp"
12
13
  def services(input)
13
- services =
14
+ instances =
14
15
  with_progress("Getting service instances") do
15
- client.service_instances
16
+ client.service_instances(2)
16
17
  end
17
18
 
18
- puts "" unless quiet?
19
-
20
- if services.empty? and !quiet?
19
+ if instances.empty? and !quiet?
20
+ puts ""
21
21
  puts "No services."
22
22
  end
23
23
 
24
- if app = input[:app]
25
- apps = client.apps
26
- services.reject! do |s|
27
- apps.none? { |a| a.services.include? s.name }
28
- end
29
- end
30
-
31
- services.each do |s|
32
- display_service(s) if service_matches(s, input)
24
+ instances.each.with_index do |i, n|
25
+ display_instance(i) if instance_matches(i, input)
33
26
  end
34
27
  end
35
28
 
29
+ services_from_label = proc { |label, services|
30
+ services.select { |s| s.label == label }
31
+ }
32
+
33
+ plan_from_name = proc { |name, plans|
34
+ plans.find { |p| p.name == name }
35
+ }
36
36
 
37
37
  desc "Create a service"
38
38
  group :services, :manage
39
39
  input(:service, :argument => true,
40
- :desc => "What kind of service (e.g. redis, mysql)") { |choices|
41
- ask "What kind?", :choices => choices
40
+ :desc => "What kind of service (e.g. redis, mysql)",
41
+ :from_given => services_from_label) { |services|
42
+ [ask("What kind?", :choices => services.sort_by(&:label),
43
+ :display => proc { |s| "#{c(s.label, :name)} v#{s.version}" },
44
+ :complete => proc { |s| "#{s.label} v#{s.version}" })]
42
45
  }
43
46
  input(:name, :argument => true,
44
- :desc => "Local name for the service") { |service|
47
+ :desc => "Name for your instance") { |service|
45
48
  random = sprintf("%x", rand(1000000))
46
49
  ask "Name?", :default => "#{service.label}-#{random}"
47
50
  }
48
- input(:version, :desc => "Version of the service") { |choices|
49
- ask "Which version?", :choices => choices
51
+ input(:version, :desc => "Version of the service") { |services|
52
+ ask "Which version?", :choices => services,
53
+ :display => proc(&:version)
54
+ }
55
+ input(:plan, :desc => "Service plan",
56
+ :from_given => plan_from_name) { |plans|
57
+ ask "Which plan?", :choices => plans.sort_by(&:name),
58
+ :display => proc { |p| "#{p.name}: #{p.description}" },
59
+ :complete => proc(&:name)
50
60
  }
51
61
  input :bind, :alias => "--app",
52
62
  :desc => "Application to immediately bind to"
53
63
  def create_service(input)
54
64
  services = client.services
55
65
 
56
- service_label = input[:service, services.collect(&:label).sort]
57
- services = services.select { |s| s.label == service_label }
66
+ services = input[:service, services]
58
67
 
59
68
  if services.size == 1
60
69
  service = services.first
61
70
  else
62
- version = input[:version, services.collect(&:version).sort]
63
- service = services.find { |s| s.version == version }
71
+ service = input[:version, services]
64
72
  end
65
73
 
74
+ plans = service.service_plans
75
+ plan = plans.find { |p| p.name == "D100" } || input[:plan, plans]
76
+
66
77
  instance = client.service_instance
67
78
  instance.name = input[:name, service]
68
- instance.type = service.type
69
- instance.vendor = service.label
70
- instance.version = service.version
71
- instance.tier = "free"
79
+
80
+ if v2?
81
+ instance.service_plan = plan
82
+ instance.space = client.current_space
83
+ instance.credentials = {} # TODO: ?
84
+ else
85
+ instance.type = service.type
86
+ instance.vendor = service.label
87
+ instance.version = service.version
88
+ instance.tier = "free"
89
+ end
72
90
 
73
91
  with_progress("Creating service #{c(instance.name, :name)}") do
74
92
  instance.create!
@@ -97,7 +115,7 @@ module VMC
97
115
  appname = input[:app, client.apps.collect(&:name)]
98
116
 
99
117
  with_progress("Binding #{c(name, :name)} to #{c(appname, :name)}") do
100
- client.app(appname).bind(name)
118
+ client.app_by_name(appname).bind(name)
101
119
  end
102
120
  end
103
121
 
@@ -115,7 +133,7 @@ module VMC
115
133
  def unbind_service(input)
116
134
  appname = input[:app, client.apps.collect(&:name)]
117
135
 
118
- app = client.app(appname)
136
+ app = client.app_by_name(appname)
119
137
  name = input[:name, app.services]
120
138
 
121
139
  with_progress("Unbinding #{c(name, :name)} from #{c(appname, :name)}") do
@@ -130,7 +148,7 @@ module VMC
130
148
  :desc => "Service to delete") { |choices|
131
149
  ask "Delete which service?", :choices => choices
132
150
  }
133
- input(:really, :type => :boolean) { |name, color|
151
+ input(:really, :type => :boolean, :forget => true) { |name, color|
134
152
  force? || ask("Really delete #{c(name, color)}?", :default => false)
135
153
  }
136
154
  input :all, :default => false, :desc => "Delete all services"
@@ -160,31 +178,44 @@ module VMC
160
178
 
161
179
  private
162
180
 
163
- def service_matches(s, options)
181
+ def instance_matches(i, options)
182
+ if app = options[:app]
183
+ return false if i.service_bindings.none? { |b|
184
+ b.app.name == app
185
+ }
186
+ end
187
+
164
188
  if name = options[:name]
165
- return false if s.name !~ /#{name}/
189
+ return false if i.name !~ /#{name}/
166
190
  end
167
191
 
168
- if type = options[:type]
169
- return false if s.type !~ /#{type}/
192
+ if service = options[:service]
193
+ return false if i.service_plan.service.label !~ /#{service}/
170
194
  end
171
195
 
172
- if vendor = options[:vendor]
173
- return false if s.vendor !~ /#{vendor}/
196
+ if !v2? && type = options[:type]
197
+ return false if i.type !~ /#{type}/
174
198
  end
175
199
 
176
- if tier = options[:tier]
177
- return false if s.tier !~ /#{tier}/
200
+ if !v2? && tier = options[:tier]
201
+ return false if i.tier !~ /#{tier}/
178
202
  end
179
203
 
180
204
  true
181
205
  end
182
206
 
183
- def display_service(s)
207
+ def display_instance(i)
184
208
  if quiet?
185
- puts s.name
209
+ puts i.name
186
210
  else
187
- puts "#{c(s.name, :name)}: #{s.vendor} v#{s.version}"
211
+ plan = i.service_plan
212
+ service = plan.service
213
+
214
+ puts ""
215
+ puts "#{c(i.name, :name)}: #{service.label} v#{service.version}"
216
+ puts " description: #{service.description}"
217
+ puts " plan: #{c(plan.name, :name)}"
218
+ puts " description: #{plan.description}"
188
219
  end
189
220
  end
190
221
  end
@@ -46,7 +46,7 @@ module VMC
46
46
  desc "Delete a user"
47
47
  group :admin, :user, :hidden => true
48
48
  input :email, :argument => true, :desc => "User to delete"
49
- input(:really, :type => :boolean) { |email|
49
+ input(:really, :type => :boolean, :forget => true) { |email|
50
50
  force? || ask("Really delete user #{c(email, :name)}?", :default => false)
51
51
  }
52
52
  def delete_user(input)
@@ -1,3 +1,3 @@
1
1
  module VMC
2
- VERSION = "0.4.0.beta.16"
2
+ VERSION = "0.4.0.beta.17"
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: 62196419
4
+ hash: 62196417
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
9
  - 0
10
10
  - beta
11
- - 16
12
- version: 0.4.0.beta.16
11
+ - 17
12
+ version: 0.4.0.beta.17
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-07-13 00:00:00 Z
20
+ date: 2012-07-14 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: json_pure
@@ -233,12 +233,12 @@ dependencies:
233
233
  requirements:
234
234
  - - ~>
235
235
  - !ruby/object:Gem::Version
236
- hash: 13
236
+ hash: 7
237
237
  segments:
238
238
  - 0
239
239
  - 4
240
- - 1
241
- version: 0.4.1
240
+ - 4
241
+ version: 0.4.4
242
242
  type: :runtime
243
243
  version_requirements: *id013
244
244
  - !ruby/object:Gem::Dependency
@@ -249,12 +249,12 @@ dependencies:
249
249
  requirements:
250
250
  - - ~>
251
251
  - !ruby/object:Gem::Version
252
- hash: 23
252
+ hash: 21
253
253
  segments:
254
254
  - 0
255
255
  - 3
256
- - 2
257
- version: 0.3.2
256
+ - 3
257
+ version: 0.3.3
258
258
  type: :runtime
259
259
  version_requirements: *id014
260
260
  - !ruby/object:Gem::Dependency
@@ -265,12 +265,12 @@ dependencies:
265
265
  requirements:
266
266
  - - ~>
267
267
  - !ruby/object:Gem::Version
268
- hash: 29
268
+ hash: 21
269
269
  segments:
270
270
  - 0
271
271
  - 0
272
- - 1
273
- version: 0.0.1
272
+ - 5
273
+ version: 0.0.5
274
274
  type: :runtime
275
275
  version_requirements: *id015
276
276
  - !ruby/object:Gem::Dependency