vmc 0.4.0.beta.10 → 0.4.0.beta.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -74,7 +74,7 @@ module VMC
74
74
  def push(name = nil)
75
75
  path = File.expand_path(input(:path) || ".")
76
76
 
77
- name ||= input(:name)
77
+ name = input(:name) if input(:name)
78
78
 
79
79
  detector = Detector.new(client, path)
80
80
  frameworks = detector.all_frameworks
@@ -175,6 +175,8 @@ module VMC
175
175
 
176
176
  app.services = bindings
177
177
 
178
+ app = filter(:push_app, app)
179
+
178
180
  with_progress("Creating #{c(name, :name)}") do
179
181
  app.create!
180
182
  end
@@ -205,6 +207,8 @@ module VMC
205
207
 
206
208
  fail "Unknown application." unless app.exists?
207
209
 
210
+ app = filter(:start_app, app)
211
+
208
212
  switch_mode(app, input(:debug_mode))
209
213
 
210
214
  with_progress("Starting #{c(name, :name)}") do |s|
@@ -305,6 +309,7 @@ module VMC
305
309
  names = [input(:name, apps.collect(&:name).sort)]
306
310
  end
307
311
 
312
+ # TODO: handle invalid app name
308
313
  to_delete = names.collect { |n| apps.find { |a| a.name == n } }
309
314
  orphaned = find_orphaned_services(to_delete)
310
315
 
@@ -361,6 +366,7 @@ module VMC
361
366
  :default => human_size(default * 1024 * 1024, 0),
362
367
  :choices => MEM_CHOICES)
363
368
  }
369
+ flag :restart, :default => true
364
370
  def scale(name = nil)
365
371
  name ||= input(:name)
366
372
 
@@ -374,11 +380,24 @@ module VMC
374
380
  memory = input(:memory, app.memory)
375
381
  end
376
382
 
383
+ megs = megabytes(memory)
384
+
385
+ memory_changed = megs != app.memory
386
+ instances_changed = instances != app.total_instances
387
+
388
+ return unless memory_changed || instances_changed
389
+
377
390
  with_progress("Scaling #{c(name, :name)}") do
378
391
  app.total_instances = instances.to_i if instances
379
- app.memory = megabytes(memory) if memory
392
+ app.memory = megs if memory
380
393
  app.update!
381
394
  end
395
+
396
+ if memory_changed && app.started? && input(:restart)
397
+ with_progress("Restarting #{c(name, :name)}") do
398
+ app.restart!
399
+ end
400
+ end
382
401
  end
383
402
 
384
403
  desc "logs APP", "Print out an app's logs"
@@ -564,6 +583,7 @@ module VMC
564
583
 
565
584
  desc "set APP [NAME] [VALUE]", "Set an environment variable"
566
585
  group :apps, :info, :hidden => true
586
+ flag :restart, :default => true
567
587
  def set(appname, name, value)
568
588
  unless name =~ VALID_NAME
569
589
  fail "Invalid variable name; must match #{VALID_NAME.inspect}"
@@ -578,10 +598,17 @@ module VMC
578
598
  v.start_with?("#{name}=")
579
599
  }.push("#{name}=#{value}"))
580
600
  end
601
+
602
+ if app.started? && input(:restart)
603
+ with_progress("Restarting #{c(app.name, :name)}") do
604
+ app.restart!
605
+ end
606
+ end
581
607
  end
582
608
 
583
609
  desc "unset APP [NAME]", "Remove an environment variable"
584
610
  group :apps, :info, :hidden => true
611
+ flag :restart, :default => true
585
612
  def unset(appname, name)
586
613
  app = client.app(appname)
587
614
  fail "Unknown application." unless app.exists?
@@ -592,6 +619,12 @@ module VMC
592
619
  v.start_with?("#{name}=")
593
620
  })
594
621
  end
622
+
623
+ if app.started? && input(:restart)
624
+ with_progress("Restarting #{c(app.ame, :name)}") do
625
+ app.restart!
626
+ end
627
+ end
595
628
  end
596
629
 
597
630
  desc "list APP", "Show all environment variables set for an app"
@@ -215,6 +215,10 @@ module VMC
215
215
  add_callback(:around, task, callback)
216
216
  end
217
217
 
218
+ def self.filter(task, &callback)
219
+ add_callback(:filter, task, callback)
220
+ end
221
+
218
222
  private
219
223
 
220
224
  def callbacks_for(what)
@@ -296,6 +300,18 @@ module VMC
296
300
  $exit_status = 1
297
301
  end
298
302
 
303
+ def with_filters(new)
304
+ new.each do |task, callback|
305
+ self.class.callbacks[:filter][task] << callback
306
+ end
307
+
308
+ yield
309
+ ensure
310
+ new.each do |task, _|
311
+ self.class.callbacks[:filter][task].pop
312
+ end
313
+ end
314
+
299
315
  def with_inputs(new)
300
316
  return yield if !new || new.empty?
301
317
 
@@ -322,6 +338,14 @@ module VMC
322
338
  raise UserError, msg
323
339
  end
324
340
 
341
+ def filter(name, val)
342
+ callbacks_for(:filter)[name].each do |f|
343
+ val = f.call val
344
+ end
345
+
346
+ val
347
+ end
348
+
325
349
  def invoke_task(task, args)
326
350
  callbacks_for(:before)[task.name.to_sym].each do |c|
327
351
  c.call
@@ -370,7 +394,7 @@ module VMC
370
394
  puts ""
371
395
  puts c("Not authenticated! Try logging in:", :warning)
372
396
 
373
- VMC::CLI.start(["login"])
397
+ invoke :login
374
398
  @client = nil
375
399
 
376
400
  retry
@@ -522,6 +546,8 @@ module VMC
522
546
  str.to_i
523
547
  elsif str =~ /K$/i
524
548
  str.to_i / 1024
549
+ else # assume megabytes
550
+ str.to_i
525
551
  end
526
552
  end
527
553
 
@@ -1,3 +1,3 @@
1
1
  module VMC
2
- VERSION = "0.4.0.beta.10"
2
+ VERSION = "0.4.0.beta.11"
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: 62196471
4
+ hash: 62196469
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
9
  - 0
10
10
  - beta
11
- - 10
12
- version: 0.4.0.beta.10
11
+ - 11
12
+ version: 0.4.0.beta.11
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-06-15 00:00:00 Z
20
+ date: 2012-06-21 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: json_pure
@@ -281,12 +281,12 @@ dependencies:
281
281
  requirements:
282
282
  - - ~>
283
283
  - !ruby/object:Gem::Version
284
- hash: 19
284
+ hash: 17
285
285
  segments:
286
286
  - 0
287
287
  - 2
288
- - 2
289
- version: 0.2.2
288
+ - 3
289
+ version: 0.2.3
290
290
  type: :runtime
291
291
  version_requirements: *id016
292
292
  description: