vmc 0.4.0.beta.49 → 0.4.0.beta.50

Sign up to get free protection for your applications and to get access to all the features.
@@ -146,105 +146,14 @@ module VMC
146
146
  ask "Bind other services to application?", :default => false
147
147
  }
148
148
  def push
149
- path = File.expand_path(input[:path])
150
-
151
149
  name = input[:name]
150
+ path = File.expand_path(input[:path])
152
151
 
153
- if exists = client.app_by_name(name)
154
- upload_app(exists, path)
155
-
156
- if input[:restart] && exists.started?
157
- invoke :restart, :app => exists
158
- end
159
-
160
- return
161
- end
162
-
163
- app = client.app
164
- app.name = name
165
- app.space = client.current_space if client.current_space
166
- app.total_instances = input[:instances]
167
- app.production = input[:plan] =~ /^p/i if v2?
168
-
169
- detector = Detector.new(client, path)
170
- frameworks = detector.all_frameworks
171
- detected, default = detector.frameworks
172
-
173
- if detected.empty?
174
- framework = input[:framework, frameworks]
152
+ if app = client.app_by_name(name)
153
+ sync_app(app, path)
175
154
  else
176
- detected_names = detected.collect(&:name).sort
177
- framework = input[:framework, detected, default, :other]
178
-
179
- if framework == :other
180
- input.forget(:framework)
181
- framework = input[:framework, frameworks]
182
- end
155
+ create_app(name, path)
183
156
  end
184
-
185
- runtimes = framework.runtimes || client.runtimes
186
- runtime = input[:runtime, runtimes]
187
-
188
- fail "Invalid framework '#{input[:framework]}'" unless framework
189
- fail "Invalid runtime '#{input[:runtime]}'" unless runtime
190
-
191
- app.framework = framework
192
- app.runtime = runtime
193
-
194
- app.command = input[:command] if framework.name == "standalone"
195
-
196
- url =
197
- if framework.name == "standalone"
198
- if (given = input[:url, "none"]) != "none"
199
- given
200
- end
201
- else
202
- input[:url, "#{name}.#{target_base}"]
203
- end
204
-
205
- app.urls = [url] if url && !v2?
206
-
207
- app.memory = megabytes(input[:memory, framework, runtime])
208
-
209
- app = filter(:create_app, app)
210
-
211
- with_progress("Creating #{c(app.name, :name)}") do
212
- app.create!
213
- end
214
-
215
- invoke :map, :app => app, :url => url if url && v2?
216
-
217
- bindings = []
218
-
219
- if input[:create_services] && !force?
220
- while true
221
- invoke :create_service, :app => app
222
- break unless ask "Create another service?", :default => false
223
- end
224
- end
225
-
226
- if input[:bind_services] && !force?
227
- instances = client.service_instances
228
-
229
- while true
230
- invoke :bind_service, :app => app
231
-
232
- break if (instances - app.services).empty?
233
-
234
- break unless ask("Bind another service?", :default => false)
235
- end
236
- end
237
-
238
- app = filter(:push_app, app)
239
-
240
- begin
241
- upload_app(app, path)
242
- rescue
243
- err "Upload failed. Try again with 'vmc push'."
244
- raise
245
- end
246
-
247
- invoke :start, :app => app if input[:start]
248
157
  end
249
158
 
250
159
 
@@ -442,7 +351,7 @@ module VMC
442
351
  if plan_name
443
352
  fail "Plans not supported on target cloud." unless v2?
444
353
 
445
- production = plan_name =~ /^p/i
354
+ production = !!(plan_name =~ /^p/i)
446
355
  plan_changed = production != app.production
447
356
  end
448
357
 
@@ -854,6 +763,173 @@ module VMC
854
763
  end
855
764
  end
856
765
 
766
+ def sync_app(app, path)
767
+ upload_app(app, path)
768
+
769
+ diff = {}
770
+
771
+ if input.given?(:memory)
772
+ mem = megabytes(input[:memory])
773
+
774
+ if mem != app.memory
775
+ diff[:memory] = [app.memory, mem]
776
+ app.memory = mem
777
+ end
778
+ end
779
+
780
+ if input.given?(:instances)
781
+ instances = input[:instances]
782
+
783
+ if instances != app.total_instances
784
+ diff[:instances] = [app.total_instances, instances]
785
+ app.total_instances = instances
786
+ end
787
+ end
788
+
789
+ if input.given?(:framework)
790
+ framework = input[:framework, client.frameworks]
791
+
792
+ if framework != app.framework
793
+ diff[:framework] = [app.framework.name, framework.name]
794
+ app.framework = framework
795
+ end
796
+ end
797
+
798
+ if input.given?(:runtime)
799
+ runtime = input[:runtime, client.runtimes]
800
+
801
+ if runtime != app.runtime
802
+ diff[:runtime] = [app.runtime.name, runtime.name]
803
+ app.runtime = runtime
804
+ end
805
+ end
806
+
807
+ if input.given?(:command) && input[:command] != app.command
808
+ command = input[:command]
809
+
810
+ if command != app.command
811
+ diff[:command] = [app.command, command]
812
+ app.command = command
813
+ end
814
+ end
815
+
816
+ if input.given?(:plan) && v2?
817
+ production = !!(input[:plan] =~ /^p/i)
818
+
819
+ if production != app.production
820
+ diff[:production] = [bool(app.production), bool(production)]
821
+ app.production = production
822
+ end
823
+ end
824
+
825
+ unless diff.empty?
826
+ line "Changes:"
827
+
828
+ indented do
829
+ diff.each do |name, change|
830
+ old, new = change
831
+ line "#{c(name, :name)}: #{old} #{c("->", :dim)} #{new}"
832
+ end
833
+ end
834
+
835
+ with_progress("Updating #{c(app.name, :name)}") do
836
+ app.update!
837
+ end
838
+ end
839
+
840
+ if input[:restart] && app.started?
841
+ invoke :restart, :app => app
842
+ end
843
+ end
844
+
845
+ def create_app(name, path)
846
+ app = client.app
847
+ app.name = name
848
+ app.space = client.current_space if client.current_space
849
+ app.total_instances = input[:instances]
850
+ app.production = !!(input[:plan] =~ /^p/i) if v2?
851
+
852
+ detector = Detector.new(client, path)
853
+ frameworks = detector.all_frameworks
854
+ detected, default = detector.frameworks
855
+
856
+ if detected.empty?
857
+ framework = input[:framework, frameworks]
858
+ else
859
+ detected_names = detected.collect(&:name).sort
860
+ framework = input[:framework, detected, default, :other]
861
+
862
+ if framework == :other
863
+ input.forget(:framework)
864
+ framework = input[:framework, frameworks]
865
+ end
866
+ end
867
+
868
+ runtimes = framework.runtimes || client.runtimes
869
+ runtime = input[:runtime, runtimes]
870
+
871
+ fail "Invalid framework '#{input[:framework]}'" unless framework
872
+ fail "Invalid runtime '#{input[:runtime]}'" unless runtime
873
+
874
+ app.framework = framework
875
+ app.runtime = runtime
876
+
877
+ app.command = input[:command] if framework.name == "standalone"
878
+
879
+ url =
880
+ if framework.name == "standalone"
881
+ if (given = input[:url, "none"]) != "none"
882
+ given
883
+ end
884
+ else
885
+ input[:url, "#{name}.#{target_base}"]
886
+ end
887
+
888
+ app.urls = [url] if url && !v2?
889
+
890
+ app.memory = megabytes(input[:memory, framework, runtime])
891
+
892
+ app = filter(:create_app, app)
893
+
894
+ with_progress("Creating #{c(app.name, :name)}") do
895
+ app.create!
896
+ end
897
+
898
+ invoke :map, :app => app, :url => url if url && v2?
899
+
900
+ bindings = []
901
+
902
+ if input[:create_services] && !force?
903
+ while true
904
+ invoke :create_service, :app => app
905
+ break unless ask "Create another service?", :default => false
906
+ end
907
+ end
908
+
909
+ if input[:bind_services] && !force?
910
+ instances = client.service_instances
911
+
912
+ while true
913
+ invoke :bind_service, :app => app
914
+
915
+ break if (instances - app.services).empty?
916
+
917
+ break unless ask("Bind another service?", :default => false)
918
+ end
919
+ end
920
+
921
+ app = filter(:push_app, app)
922
+
923
+ begin
924
+ upload_app(app, path)
925
+ rescue
926
+ err "Upload failed. Try again with 'vmc push'."
927
+ raise
928
+ end
929
+
930
+ invoke :start, :app => app if input[:start]
931
+ end
932
+
857
933
  def upload_app(app, path)
858
934
  with_progress("Uploading #{c(app.name, :name)}") do
859
935
  app.upload(path)
@@ -1051,5 +1127,13 @@ module VMC
1051
1127
 
1052
1128
  choices
1053
1129
  end
1130
+
1131
+ def bool(b)
1132
+ if b
1133
+ c("true", :yes)
1134
+ else
1135
+ c("false", :no)
1136
+ end
1137
+ end
1054
1138
  end
1055
1139
  end
@@ -1,3 +1,3 @@
1
1
  module VMC
2
- VERSION = "0.4.0.beta.49"
2
+ VERSION = "0.4.0.beta.50"
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: -3173992204
4
+ hash: -1152463690
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
9
  - 0
10
10
  - beta
11
- - 49
12
- version: 0.4.0.beta.49
11
+ - 50
12
+ version: 0.4.0.beta.50
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-10 00:00:00 Z
20
+ date: 2012-09-12 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: json_pure
@@ -265,12 +265,12 @@ dependencies:
265
265
  requirements:
266
266
  - - ~>
267
267
  - !ruby/object:Gem::Version
268
- hash: 45
268
+ hash: 83
269
269
  segments:
270
270
  - 0
271
271
  - 3
272
- - 31
273
- version: 0.3.31
272
+ - 32
273
+ version: 0.3.32
274
274
  type: :runtime
275
275
  version_requirements: *id015
276
276
  - !ruby/object:Gem::Dependency
@@ -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
  - 1
288
- - 4
289
- version: 0.1.4
288
+ - 5
289
+ version: 0.1.5
290
290
  type: :runtime
291
291
  version_requirements: *id016
292
292
  - !ruby/object:Gem::Dependency
@@ -297,12 +297,12 @@ dependencies:
297
297
  requirements:
298
298
  - - ~>
299
299
  - !ruby/object:Gem::Version
300
- hash: 7
300
+ hash: 5
301
301
  segments:
302
302
  - 0
303
303
  - 4
304
- - 4
305
- version: 0.4.4
304
+ - 5
305
+ version: 0.4.5
306
306
  type: :runtime
307
307
  version_requirements: *id017
308
308
  - !ruby/object:Gem::Dependency