vmc_knife 0.0.13 → 0.0.40

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.
@@ -93,11 +93,19 @@ class VMC::Cli::KnifeRunner < VMC::Cli::Runner
93
93
  when 'upload-applications','upload-apps'
94
94
  usage('vmc_knife upload-apps [<applications_regexp>]')
95
95
  @args.shift # consumes the argument.
96
- if @args.size <= 2
97
- set_cmd(:knifeapps, :upload_applications, @args.size)
98
- else
99
- set_cmd(:knifeapps, :upload_applications, @args.size) # too many
100
- end
96
+ set_cmd(:knifeapps, :upload_applications, @args.size)
97
+ when 'update-applications','update-apps'
98
+ usage('vmc_knife update-apps [<applications_regexp>]')
99
+ @args.shift # consumes the argument.
100
+ set_cmd(:knifeapps, :update_applications, @args.size)
101
+ when 'patch-applications','patch-apps'
102
+ usage('vmc_knife patch-apps [<applications_regexp>]')
103
+ @args.shift # consumes the argument.
104
+ set_cmd(:knifeapps, :patch_applications, @args.size)
105
+ when 'extract-deployed-apps', 'extract-apps'
106
+ usage('vmc_knife extract-deployed-apps [<applications_regexp>]')
107
+ @args.shift # consumes the argument.
108
+ set_cmd(:knifeapps, :extract_deployed_applications, @args.size)
101
109
  when 'start-applications','start-apps'
102
110
  usage('vmc_knife start-apps [<applications_regexp>]')
103
111
  @args.shift # consumes the argument.
@@ -122,14 +130,34 @@ class VMC::Cli::KnifeRunner < VMC::Cli::Runner
122
130
  else
123
131
  set_cmd(:knifeapps, :restart_applications, @args.size) # too many
124
132
  end
133
+ when 'info-applications','info-apps','version-apps'
134
+ usage('vmc_knife info-apps [<applications_regexp>]')
135
+ @args.shift # consumes the argument.
136
+ set_cmd(:knifeapps, :info_applications, @args.size)
137
+ when 'running-apps?', 'running-apps'
138
+ usage('vmc_knife running?-apps [<applications_regexp>]')
139
+ @args.shift # consumes the argument.
140
+ set_cmd(:knifeapps, :running_applications?, @args.size)
141
+ when 'wait-till-running-apps'
142
+ usage('vmc_knife wait-till-running-apps [<applications_regexp>]')
143
+ @args.shift # consumes the argument.
144
+ set_cmd(:knifeapps, :wait_till_running_applications, @args.size)
145
+ when 'info-configure','info-configure-apps'
146
+ usage('vmc_knife info-configure [<applications_regexp>]')
147
+ @args.shift # consumes the argument.
148
+ set_cmd(:knifeapps, :info_configure, @args.size)
125
149
  when 'delete-all'
126
150
  usage('vmc_knife delete-all [<applications_regexp>]')
127
151
  @args.shift # consumes the argument.
128
- if @args.size <= 2
129
- set_cmd(:knifeapps, :delete_all, @args.size)
130
- else
131
- set_cmd(:knifeapps, :delete_all, @args.size) # too many
132
- end
152
+ set_cmd(:knifeapps, :delete_all, @args.size)
153
+ when 'delete-apps'
154
+ usage('vmc_knife delete-apps [<applications_regexp>]')
155
+ @args.shift # consumes the argument.
156
+ set_cmd(:knifeapps, :delete_apps, @args.size)
157
+ when 'delete-data','delete-services'
158
+ usage('vmc_knife delete-data [<data_regexp>]')
159
+ @args.shift # consumes the argument.
160
+ set_cmd(:knifeapps, :delete_data, @args.size)
133
161
  when 'data-shell','psql','mongo'
134
162
  usage('vmc_knife data-shell [<data-service-name>] [<app-name>] [<cmd-file> or <quoted-cmd>]')
135
163
  @args.shift # consumes the argument.
@@ -173,19 +201,11 @@ class VMC::Cli::KnifeRunner < VMC::Cli::Runner
173
201
  when 'data-import'
174
202
  usage('vmc_knife data-import [<data-service-name>] [<archive-file-name>] [<tables-collection-regexp>]')
175
203
  @args.shift # consumes the argument.
176
- if @args.size <= 3
177
- set_cmd(:knifeapps, :data_import, @args.size)
178
- else
179
- set_cmd(:knifeapps, :data_import, @args.size) # too many
180
- end
204
+ set_cmd(:knifeapps, :data_import, @args.size)
181
205
  when 'data-export'
182
206
  usage('vmc_knife data-export [<data-service-name>] [<archive-file-name>] [<tables-collection-regexp>]')
183
207
  @args.shift # consumes the argument.
184
- if @args.size <= 3
185
- set_cmd(:knifeapps, :data_export, @args.size)
186
- else
187
- set_cmd(:knifeapps, :data_export, @args.size) # too many
188
- end
208
+ set_cmd(:knifeapps, :data_export, @args.size)
189
209
  when 'logs','logs-all'
190
210
  usage('vmc_knife logs-all')
191
211
  @args.shift # consumes the argument.
@@ -224,7 +244,7 @@ class VMC::Cli::KnifeRunner < VMC::Cli::Runner
224
244
  `cd /tmp; [ -d "vmc-knife" ] && rm -rf vmc-knife; git clone https://github.com/hmalphettes/vmc-knife.git; cd vmc-knife; gem build vmc_knife.gemspec; gem install vmc_knife`
225
245
  exit 0
226
246
  when 'help'
227
- display "vmc_knife expand-manifest|login|start/stop/restart-apps|upload-apps|configure-all|configure-recipes|configure-apps|configure-services|delete-all|configure-vcap|configure-vcap-mdns|configure-vcap-etc-hosts|data-shell|data-export/import/shrink/drop|logs-less|less|tail|logs-all/apps/vcap|update-self [<manifest_path>]"
247
+ display "vmc_knife expand-manifest|login|start/stop/restart-apps|upload-apps|configure-all|configure-recipes|configure-apps|configure-services|info-configure-apps|info-apps|update-apps|patch-apps|running-apps|wait-till-running-apps|delete-app/data/all|configure-vcap|configure-vcap-mdns|configure-vcap-etc-hosts|data-shell|data-export/import/shrink/drop|logs-less|less|tail|logs-all/apps/vcap|update-self [<manifest_path>]"
228
248
  else
229
249
  super
230
250
  end
@@ -213,10 +213,21 @@ module VMC::Cli::Command
213
213
  end
214
214
  configurer.execute
215
215
  end
216
-
217
216
  def upload_applications(app_names_regexp=nil,manifest_file_path=nil)
218
217
  recipe_configuror(:upload,nil,app_names_regexp,nil,manifest_file_path,
219
- {:apps_only=>true})
218
+ {:apps_only=>true, :force=>@options[:force]})
219
+ end
220
+ def update_applications(app_names_regexp=nil,manifest_file_path=nil)
221
+ recipe_configuror(:update,nil,app_names_regexp,nil,manifest_file_path,
222
+ {:apps_only=>true, :force=>@options[:force]})
223
+ end
224
+ def patch_applications(app_names_regexp=nil,manifest_file_path=nil)
225
+ recipe_configuror(:patch,nil,app_names_regexp,nil,manifest_file_path,
226
+ {:apps_only=>true, :force=>@options[:force]})
227
+ end
228
+ def extract_deployed_applications(app_names_regexp=nil,manifest_file_path=nil)
229
+ recipe_configuror(:extract_deployed,nil,app_names_regexp,nil,manifest_file_path,
230
+ {:apps_only=>true, :force=>@options[:force]})
220
231
  end
221
232
  def start_applications(app_names_regexp=nil,manifest_file_path=nil)
222
233
  recipe_configuror(:start,nil,app_names_regexp,nil,manifest_file_path,
@@ -230,9 +241,37 @@ module VMC::Cli::Command
230
241
  recipe_configuror(:restart,nil,app_names_regexp,nil,manifest_file_path,
231
242
  {:apps_only=>true})
232
243
  end
244
+ def info_applications(app_names_regexp=nil,manifest_file_path=nil)
245
+ res=recipe_configuror(:info,nil,app_names_regexp,nil,manifest_file_path,
246
+ {:apps_only=>true})
247
+ exit 1 unless res
248
+ end
249
+ def wait_till_running_applications(app_names_regexp=nil,manifest_file_path=nil)
250
+ res=recipe_configuror(:running_applications?,nil,app_names_regexp,nil,manifest_file_path,
251
+ {:apps_only=>true, :wait=>{:interval=>30,:retries=>6}})
252
+ exit 1 unless res
253
+ end
254
+ def running_applications?(app_names_regexp=nil,manifest_file_path=nil)
255
+ res=recipe_configuror(:running_applications?,nil,app_names_regexp,nil,manifest_file_path,
256
+ {:apps_only=>true})
257
+ exit 1 unless res
258
+ end
259
+ def info_configure(app_names_regexp=nil,manifest_file_path=nil)
260
+ res=recipe_configuror(:info,nil,app_names_regexp,nil,manifest_file_path,
261
+ {:apps_only=>true, :configure_only=>true})
262
+ exit 1 unless res
263
+ end
233
264
  def delete_all(app_names_regexp=nil,manifest_file_path=nil)
234
265
  recipe_configuror(:delete,nil,app_names_regexp,nil,manifest_file_path)
235
266
  end
267
+ def delete_apps(app_names_regexp=nil,manifest_file_path=nil)
268
+ recipe_configuror(:delete,nil,app_names_regexp,nil,manifest_file_path,
269
+ {:apps_only=>true})
270
+ end
271
+ def delete_data(services_names_regexp=nil,manifest_file_path=nil)
272
+ recipe_configuror(:delete,nil,nil,services_names_regexp,manifest_file_path,
273
+ {:data_only=>true})
274
+ end
236
275
  def data_shell(data_names_regexp=nil,file_or_cmd=nil,app_name=nil,manifest_file_path=nil)
237
276
  file_name = nil
238
277
  cmd = nil
@@ -245,7 +284,9 @@ module VMC::Cli::Command
245
284
  end
246
285
  end
247
286
  recipe_configuror(:shell,nil,nil,data_names_regexp,manifest_file_path,
248
- {:file_name=>file_name, :data_cmd=>cmd, :app_name=>app_name, :data_only=>true})
287
+ {:file_name=>file_name, :data_cmd=>cmd,
288
+ :app_name=>app_name, :data_only=>true,
289
+ :single_service=>true})
249
290
  end
250
291
  def data_credentials(data_names_regexp=nil,manifest_file_path=nil)
251
292
  recipe_configuror(:credentials,nil,nil,data_names_regexp,manifest_file_path,
@@ -271,9 +312,9 @@ module VMC::Cli::Command
271
312
  recipe_configuror(:shrink,nil,nil,data_names_regexp,manifest_file_path,
272
313
  {:collection_or_table_names=>collection_or_table_names, :data_only=>true})
273
314
  end
274
- def logs_all(app_names_regexp=nil, manifest_file_path=nil)
315
+ def logs_all(app_names_regexp=nil, output_file=nil, manifest_file_path=nil)
275
316
  recipe_configuror(:logs,nil,app_names_regexp,nil,manifest_file_path,
276
- {:apps_only=>true, :log_apps=>true, :log_vcap=>true})
317
+ {:apps_only=>true, :output_file=>output_file, :log_apps=>true, :log_vcap=>true})
277
318
  end
278
319
  def logs_apps(app_names_regexp=nil, manifest_file_path=nil)
279
320
  recipe_configuror(:logs,nil,app_names_regexp,nil,manifest_file_path,
@@ -298,18 +339,25 @@ module VMC::Cli::Command
298
339
  man = load_manifest(manifest_file_path)
299
340
  recipes_regexp = as_regexp(recipes_regexp)
300
341
  app_names_regexp = as_regexp(app_names_regexp)
301
- service_names_regexp = as_regexp(service_names_regexp)
302
- configurer = VMC::KNIFE::RecipesConfigurationApplier.new(man,client,recipes_regexp,app_names_regexp,service_names_regexp,opts)
342
+ opts ||= {}
343
+ service_names_regexp = as_regexp(service_names_regexp, opts[:single_service])
344
+ configurer = VMC::KNIFE::RecipesConfigurationApplier.new(man, client,
345
+ recipes_regexp, app_names_regexp,
346
+ service_names_regexp, opts)
303
347
  method_object = configurer.method(method_sym_name)
304
348
  method_object.call
305
349
  end
306
350
 
307
- def as_regexp(arg)
351
+ def as_regexp(arg, strict=false)
308
352
  if arg != nil && arg.kind_of?(String) && !arg.strip.empty?
309
- Regexp.new(arg)
353
+ if strict && Regexp.quote(arg) == arg
354
+ Regexp.new('^'+arg+'$')
355
+ else
356
+ Regexp.new(arg)
357
+ end
310
358
  end
311
359
  end
312
360
 
313
361
  end
314
362
 
315
- end
363
+ end
@@ -30,14 +30,14 @@ module VMC
30
30
 
31
31
  def self.get_app_id(app_name)
32
32
  db=get_ccdb_credentials()
33
- app_id = `psql --username #{db['username']} --dbname #{db['database']} -c \"select id from apps where name='#{app_name}'\" #{PSQL_RAW_RES_ARGS}`
34
- app_id
33
+ app_id = `psql --username #{db['username']} --dbname #{db['database']} -c \"select id from apps where name='#{app_name}'\" #{PSQL_RAW_RES_ARGS}`.strip
34
+ app_id unless app_id.empty?
35
35
  end
36
36
  def self.get_service_config_id(service_name)
37
37
  db=get_ccdb_credentials()
38
38
  #todo add the user_id
39
- service_config_id = `psql --username #{db['username']} --dbname #{db['database']} -c \"select id from service_configs where alias='#{service_name}'\" #{PSQL_RAW_RES_ARGS}`
40
- service_config_id
39
+ service_config_id = `psql --username #{db['username']} --dbname #{db['database']} -c \"select id from service_configs where alias='#{service_name}'\" #{PSQL_RAW_RES_ARGS}`.strip
40
+ service_config_id unless service_config_id.empty?
41
41
  end
42
42
 
43
43
  # Returns a hash of the credentials for a data-service
@@ -65,11 +65,15 @@ module VMC
65
65
  def self.get_credentials(service_name, app_name=nil)
66
66
  db=get_ccdb_credentials()
67
67
  if app_name.nil?
68
- credentials_str = `psql --username #{db['username']} --dbname #{db['database']} -c \"select credentials from service_configs where alias='#{service_name}'\" #{PSQL_RAW_RES_ARGS}`
68
+ credentials_str = `psql --username #{db['username']} --dbname #{db['database']} -c \"select credentials from service_configs where alias='#{service_name}'\" #{PSQL_RAW_RES_ARGS}`.strip
69
69
  else
70
70
  app_id = get_app_id(app_name)
71
+ if app_id.nil?
72
+ puts "WARN: No application named #{app_name} exists at this point" if VMC::Cli::Config.trace
73
+ return
74
+ end
71
75
  service_config_id = get_service_config_id(service_name)
72
- credentials_str = `psql --username #{db['username']} --dbname #{db['database']} -c \"select credentials from service_bindings where app_id = '#{app_id}' and service_config_id='#{service_config_id}'\" #{PSQL_RAW_RES_ARGS}`
76
+ credentials_str = `psql --username #{db['username']} --dbname #{db['database']} -c \"select credentials from service_bindings where app_id = '#{app_id}' and service_config_id='#{service_config_id}'\" #{PSQL_RAW_RES_ARGS}`.strip
73
77
  end
74
78
  res = Hash.new
75
79
  credentials_str.split("\n").each do | line |
@@ -116,14 +120,13 @@ module VMC
116
120
  elsif exec_name == 'mongodump'
117
121
  db_arg = "" # dump all the databases including 'admin' which contains the users.
118
122
  else
119
- db_arg = "--db #{credentials_hash['db']}"
123
+ db_arg = " --db #{credentials_hash['db']}"
120
124
  end
121
- cmd = "#{mongo_shell} -u #{credentials_hash['username']} -p #{credentials_hash['password']} #{credentials_hash['hostname']}:#{credentials_hash['port']}#{db_arg}"
125
+ cmd = "#{mongo_shell} -u #{credentials_hash['username']} -p #{credentials_hash['password']} #{'-h' if(exec_name=='mongorestore')} #{credentials_hash['hostname']}:#{credentials_hash['port']}#{db_arg}"
122
126
  if commands_file
123
- if mongo_shell == 'mongo'
127
+ if exec_name == 'mongo'
124
128
  if File.exists? commands_file
125
- # not supported yet.
126
- commands_file = "--eval \"#{`cat commands_file`}"
129
+ commands_file = "--eval \"`cat #{commands_file}`\""
127
130
  else
128
131
  commands_file = "--eval \"#{commands_file}\""
129
132
  end
@@ -232,6 +235,7 @@ module VMC
232
235
  include Interactive
233
236
 
234
237
  # The credentials hash for this data-service
238
+ # param app_name The favored app usually bound to this data_service
235
239
  def credentials(app_name=nil)
236
240
  #bound_app is the name of an app bound to the dat-service and that credentials
237
241
  #should be used to access the data-service.
@@ -267,7 +271,11 @@ module VMC
267
271
  file=File.expand_path(file,current_wd)
268
272
  basename = File.basename(file).to_s
269
273
  end
270
- if Dir.entries(Dir.pwd).size == 2
274
+
275
+ unless File.exists?(basename)
276
+ Dir.foreach(Dir.pwd) { |f|
277
+ File.delete(f) unless f == '.' || f == '..'
278
+ }
271
279
  if file =~ /^https?:\/\// || file =~ /^ftp:\/\//
272
280
  wget_args = @wrapped['director']['wget_args']
273
281
  if wget_args.nil?
@@ -279,11 +287,11 @@ module VMC
279
287
  end
280
288
  `wget #{wget_args_str} --output-document=#{basename} #{file}`
281
289
  if $? != 0
282
- `rm #{data_download_dir}/#{basename}`
290
+ File.delete("#{data_download_dir}/#{basename}")
283
291
  raise "Unable to successfully download #{file}"
284
292
  end
285
293
  else
286
- `cp #{file} #{basename}`
294
+ FileUtils.cp(file, basename)
287
295
  end
288
296
  end
289
297
  #unzip if necessary (in progress)
@@ -302,7 +310,7 @@ module VMC
302
310
  if is_unzipped
303
311
  #`rm #{basename}`
304
312
  files = Dir.glob("*.sql") if is_postgresql
305
- files = Dir.glob("*.bson") if is_mongodb
313
+ files = Dir.glob("**/*.bson") if is_mongodb
306
314
  files ||= Dir.glob("*")
307
315
  raise "Can't find the db-dump file." if files.empty?
308
316
  file = files.first
@@ -310,10 +318,11 @@ module VMC
310
318
  file = basename
311
319
  end
312
320
 
321
+ creds=credentials(app_name)
322
+
313
323
  if is_postgresql
314
324
  p "chmod o+w #{file}"
315
325
  `chmod o+w #{file}`
316
- creds=credentials(app_name)
317
326
  if /\.sql$/ =~ file
318
327
  other_params="--file #{file} --quiet"
319
328
  cmd = VMC::KNIFE.pg_connect_cmd(creds, 'psql',as_admin=false, other_params)
@@ -324,7 +333,7 @@ module VMC
324
333
  #`pg_restore --dbname=#{dbname} --username=#{username} --no-acl --no-privileges --no-owner #{file}`
325
334
  end
326
335
  puts cmd
327
- puts `#{cmd}`
336
+ puts `#{cmd}`.strip
328
337
  `chmod o-w #{file}`
329
338
  elsif is_mongodb
330
339
 
@@ -338,7 +347,7 @@ module VMC
338
347
  if File.exists?(mongod_lock) && File.size(mongod_lock)>0
339
348
  # the mongodb instance is currently working. connect to it and do the work.
340
349
  # in that case import the 'db' alone. don't do the 'admin'
341
- VMC::KNIFE.data_service_console(creds, File.dirname(file),false,'mongorestore')
350
+ VMC::KNIFE.data_service_console(creds, File.dirname(file), false, 'mongorestore')
342
351
  else
343
352
  # the mongodb instance is not currently working
344
353
  # go directly on the filesystem
@@ -442,14 +451,15 @@ module VMC
442
451
  # Another workaround though really not perfect so it will stay in vmc_knife:
443
452
  # the ownership of the SQL functions.
444
453
  def apply_privileges(app_name=nil)
454
+ return if credentials(app_name).nil?
445
455
  if is_postgresql()
446
456
  cmd_acl="GRANT CREATE ON SCHEMA PUBLIC TO PUBLIC;\
447
- GRANT ALL ON ALL TABLES IN SCHEMA PUBLIC TO PUBLIC;\
448
- GRANT ALL ON ALL FUNCTIONS IN SCHEMA PUBLIC TO PUBLIC;\
449
- GRANT ALL ON ALL SEQUENCES IN SCHEMA PUBLIC TO PUBLIC;\
450
- ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO PUBLIC;\
451
- ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO PUBLIC;\
452
- ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON FUNCTIONS TO PUBLIC;"
457
+ GRANT ALL ON ALL TABLES IN SCHEMA PUBLIC TO PUBLIC;\
458
+ GRANT ALL ON ALL FUNCTIONS IN SCHEMA PUBLIC TO PUBLIC;\
459
+ GRANT ALL ON ALL SEQUENCES IN SCHEMA PUBLIC TO PUBLIC;\
460
+ ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO PUBLIC;\
461
+ ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO PUBLIC;\
462
+ ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON FUNCTIONS TO PUBLIC;"
453
463
  # shell(cmd_acl,true)
454
464
 
455
465
  # reset the owner of the functions to the current user
@@ -465,14 +475,18 @@ module VMC
465
475
  return
466
476
  end
467
477
  fcts_name=shell(cmd_select_fcts,true,true)
468
- fcts = fcts_name.split("\n").collect do |line|
469
- line.strip!
470
- "'#{line}'"
471
- end.join(',')
472
- cmd_change_fcts_owner="UPDATE pg_catalog.pg_proc \
473
- SET proowner = (SELECT oid FROM pg_roles WHERE rolname = '#{current_owner}')\
474
- WHERE pg_proc.proname IN (#{fcts})"
475
- puts `sudo -u postgres psql --dbname #{credentials()['name']} -c \"#{cmd_change_fcts_owner}\" #{PSQL_RAW_RES_ARGS}`
478
+ if fcts_name.empty?
479
+ puts "No need to re-assign the ownership of the functions in #{credentials()['name']}; the DB does not define its own functions." if VMC::Cli::Config.trace
480
+ else
481
+ fcts = fcts_name.split("\n").collect do |line|
482
+ line.strip!
483
+ "'#{line}'"
484
+ end.join(',')
485
+ cmd_change_fcts_owner="UPDATE pg_catalog.pg_proc \
486
+ SET proowner = (SELECT oid FROM pg_roles WHERE rolname = '#{current_owner}')\
487
+ WHERE pg_proc.proname IN (#{fcts})"
488
+ puts `sudo -u postgres psql --dbname #{credentials()['name']} -c \"#{cmd_change_fcts_owner}\" #{PSQL_RAW_RES_ARGS}`
489
+ end
476
490
  end
477
491
  end
478
492
  end
@@ -509,7 +523,7 @@ module VMC
509
523
  if collection_or_table_names
510
524
  sel_tables = "#{sel_tables} AND table_name LIKE '#{collection_or_table_names}'"
511
525
  end
512
- tables = shell(sel_tables)
526
+ tables = shell(sel_tables, false, true)
513
527
  tables_arr = Array.new
514
528
  tables.split("\n").each do | line |
515
529
  line.strip!
@@ -1,4 +1,8 @@
1
1
  require 'json'
2
+ require 'cli/frameworks'
3
+ # add java_start our own framework to the array of well known frameworks
4
+ VMC::Cli::Framework::FRAMEWORKS['JavaGen'] = ['java_start',{ :mem => '512M', :description => 'Java Custom Application'}]
5
+
2
6
  module VMC
3
7
  module KNIFE
4
8
  module HELPER
@@ -303,7 +303,6 @@ module VMC
303
303
  # if we did bind to a database; let's re-assign the ownership of the sql functions
304
304
  # to the favorite app if there is such a thing.
305
305
  if updates && updates['services'] && updates['services']['add']
306
- puts "THE ONE WE ARE DEBUGGING #{JSON.pretty_generate updates['services']}"
307
306
  list_services_name=updates['services']['add']
308
307
  list_services_name.each do |cf_service_name|
309
308
  @data_services.each do |data_service|
@@ -311,7 +310,6 @@ module VMC
311
310
  # is this the privileged app?
312
311
  priv_app_name = data_service.wrapped['director']['bound_app'] if data_service.wrapped['director']
313
312
  if priv_app_name == application.name
314
- puts "GOT THE PRIVILEGED APP #{application.name} for the service #{data_service.role_name}"
315
313
  data_service.apply_privileges(priv_app_name)
316
314
  end
317
315
  end
@@ -329,14 +327,52 @@ module VMC
329
327
  def upload()
330
328
  @applications.each do |application|
331
329
  application_updater = ApplicationManifestApplier.new application, @client
332
- application_updater.upload
330
+ application_updater.upload(@opts[:force])
333
331
  end
334
332
  end
333
+ def update()
334
+ @applications.each do |application|
335
+ application_updater = ApplicationManifestApplier.new application, @client
336
+ application_updater.update(@opts[:force])
337
+ end
338
+ end
339
+ def patch()
340
+ @applications.each do |application|
341
+ application_updater = ApplicationManifestApplier.new application, @client
342
+ application_updater.patch(@opts[:force])
343
+ end
344
+ end
345
+ def extract_deployed()
346
+ @applications.each do |application|
347
+ application_updater = ApplicationManifestApplier.new application, @client
348
+ application_updater.extract_deployed(@opts[:force])
349
+ end
350
+ end
351
+ def info()
352
+ configure_only=@opts[:configure_only] || false
353
+ if configure_only
354
+ if updates_pending().empty?
355
+ puts "All configuration up to date: true"
356
+ return true
357
+ else
358
+ puts "All configuration up to data: false"
359
+ return false
360
+ end
361
+ end
362
+ up_to_date=true
363
+ @applications.each do |application|
364
+ application_updater = ApplicationManifestApplier.new application, @client
365
+ app_up_to_date = application_updater.info()
366
+ up_to_date = false unless app_up_to_date
367
+ end
368
+ puts "All up to date: #{up_to_date}"
369
+ return up_to_date
370
+ end
335
371
  def delete()
336
372
  @applications.each do |application|
337
373
  application_updater = ApplicationManifestApplier.new application, @client
338
374
  application_updater.delete
339
- end
375
+ end
340
376
  @data_services.each do |data_service|
341
377
  data_service_updater = DataServiceManifestApplier.new data_service, @client, @current_services, @current_services_info
342
378
  data_service_updater.delete
@@ -352,6 +388,57 @@ module VMC
352
388
  application_updater.stop
353
389
  end
354
390
  end
391
+ def running_applications?()
392
+ if @opts && @opts[:wait]
393
+ tries = @opts[:wait][:retries]
394
+ tries = tries.to_i if tries
395
+ interval = @opts[:wait][:interval]
396
+ interval = interval.to_i if interval
397
+ end
398
+ tries ||= 1
399
+ interval ||= 30
400
+ curr_iteration = 0
401
+ already_running = {}
402
+ @applications.each do |application|
403
+ already_running[application.name] = "false"
404
+ end
405
+ vmc_apps = Array.new
406
+ while (curr_iteration <= tries)
407
+ # brute approach: cmd-line.
408
+ vmc_apps = ENV['TEST_VMC_APPS_STRING'] # this is for testing.
409
+ unless vmc_apps
410
+ vmc_apps = `vmc apps`.strip.split("\n")
411
+ raise "Unable to run vmc" unless $?.exitstatus == 0
412
+ end
413
+ current_healths = Hash.new
414
+ vmc_apps.each do |line|
415
+ if line =~ /^\| (\S*)\s*\|\s*\d*\s*\|\s*(\S*)\s*\|/
416
+ app = $1
417
+ health = $2
418
+ current_healths[app] = health
419
+ end
420
+ end
421
+ not_running = Array.new
422
+ @applications.each do |application|
423
+ #health = `echo "#{vmc_apps}" | grep \|\ #{application.name}\ | cut -d '|' -f4`
424
+ health = current_healths[application.name]
425
+ already_running[application.name] = health
426
+ not_running << application.name unless health == 'RUNNING'
427
+ end
428
+ all_running = not_running.empty?
429
+ curr_iteration = curr_iteration + 1
430
+ break if not_running.empty? || curr_iteration == tries
431
+ p "Sleeping #{interval}s as #{not_running.join(' ')} #{not_running.size == 1 ? 'is' : 'are' } not running yet."
432
+ sleep(interval)
433
+ end
434
+ p "Success: all apps are running" if all_running
435
+ return true if all_running
436
+ p "At least one app is not running"
437
+ vmc_apps.each do |line|
438
+ p line
439
+ end
440
+ return false
441
+ end
355
442
  def start()
356
443
  @applications.each do |application|
357
444
  application_updater = ApplicationManifestApplier.new application, @client
@@ -388,6 +475,7 @@ module VMC
388
475
  logs_base_url=man_logs['logs_base_url']
389
476
  # TODO: clean the old files and folders if there are too many of them.
390
477
  end
478
+ other_logs = man_logs['other_logs']
391
479
  end
392
480
  name_prefix||="cflogs-"
393
481
  parent_output_folder||="/tmp"
@@ -417,6 +505,16 @@ module VMC
417
505
  FileUtils.cp_r Dir.glob(File.join(vcap_log_folder,"*")), File.join(output_folder, 'vcap')
418
506
  end
419
507
  end
508
+ if other_logs
509
+ other_logs_dir=File.join(output_folder, 'other_logs')
510
+ FileUtils.mkdir other_logs_dir
511
+ other_logs.each do |name,glob|
512
+ other_dir=File.join(other_logs_dir, name)
513
+ FileUtils.mkdir other_dir
514
+ FileUtils.cp_r Dir.glob(glob), other_dir
515
+ end
516
+ end
517
+
420
518
  curr_dir=Dir.pwd
421
519
  destination=parent_output_folder||curr_dir
422
520
  copy_or_move=("/tmp" == parent_output_folder)?"mv":"cp"
@@ -425,7 +523,8 @@ module VMC
425
523
  else
426
524
  if logs_base_url
427
525
  hostname=`hostname`.strip
428
- puts "Logs available at http://#{hostname}.local#{logs_base_url}/#{name} and in the current directory."
526
+ complete_base_url= logs_base_url =~ /:\/\// ? logs_base_url : "http://#{hostname}.local#{logs_base_url}"
527
+ puts "Logs available at #{complete_base_url}/#{name} and in #{parent_output_folder}/#{name}"
429
528
  end
430
529
  end
431
530
  `cd #{File.dirname(output_folder)}; zip -r #{output_file} #{File.basename(output_folder)}; #{copy_or_move} #{output_file} #{curr_dir}`
@@ -434,6 +533,10 @@ module VMC
434
533
  else
435
534
  `mv #{parent_output_folder}/#{output_file} #{parent_output_folder}/#{name}`
436
535
  end
536
+ if logs_base_url
537
+ # not the most elegant code to cp then delete:
538
+ `rm #{output_file}` unless @opts[:output_file]
539
+ end
437
540
  end
438
541
  end
439
542
  class DataServiceManifestApplier
@@ -481,8 +584,11 @@ module VMC
481
584
  client.create_service @data_service_json['vendor'], @data_service_json['name']
482
585
  end
483
586
  def delete()
484
- raise "The service #{@data_service_json['name']} does not exist." if current().empty?
485
- client.delete_service(@data_service_json['name'])
587
+ if current().empty?
588
+ puts "The service #{@data_service_json['name']} does not exist." if VMC::Cli::Config.trace
589
+ else
590
+ client.delete_service(@data_service_json['name'])
591
+ end
486
592
  end
487
593
 
488
594
  # Returns the service manifest for the vendor.
@@ -565,18 +671,250 @@ module VMC
565
671
  end
566
672
  end
567
673
 
568
- def upload()
674
+ def version_available()
675
+ return unless @application_json['repository']
676
+ if @application_json['repository']['version_available'] && @application_json['repository']['version_available']['url']
677
+ version_available_url=@application_json['repository']['version_available']['url']
678
+ url = @application_json['repository']['url']
679
+ cmd=@application_json['repository']['version_available']['cmd']
680
+ if version_available_url.start_with?("./")
681
+ version_available_url.slice!(0)
682
+ version_available_url.slice!(0)
683
+ end
684
+ unless /:\/\// =~ version_available_url || version_available_url.start_with?("/")
685
+ rel_url=File.dirname(url)
686
+ version_available_file||=version_available_file
687
+ version_available_url="#{rel_url}/#{version_available_url}"
688
+ p "version_available_url: #{version_available_url}" if VMC::Cli::Config.trace
689
+ p "extract with #{cmd}" if VMC::Cli::Config.trace
690
+ end
691
+ ## This will find out the available version.
692
+ `version_built_download=/tmp/version_built_download
693
+ wget #{wget_args()} --output-document=$version_built_download #{version_available_url} --output-file=/tmp/wget_#{@application_json['name']}_available`
694
+ available_version=`version_built_download=/tmp/version_built_download;#{cmd}`.strip
695
+ available_version.gsub(/^["']|["']$/, '')
696
+ end
697
+ end
698
+
699
+ # returns the internal id of the app in the cloud_controller database
700
+ def ccdb_app_id()
701
+ KNIFE::get_app_id(@current_name)
702
+ end
703
+ # the sha1 of the staged package
704
+ def ccdb_staged_hash()
705
+ ccdb_app_hash('staged_package_hash')
706
+ end
707
+ # The sha1 of the package; not staged
708
+ def ccdb_package_hash()
709
+ ccdb_app_hash('package_hash')
710
+ end
711
+
712
+ # hash_type: 'staged_package_hash' or 'package_hash'
713
+ def ccdb_app_hash(hash_type='staged_package_hash')
714
+ db=KNIFE::get_ccdb_credentials()
715
+ # todo: add the id of the current vcap user. not a problem unless we have multiple vcap users.
716
+ app_id = `psql --username #{db['username']} --dbname #{db['database']} -c \"select id from apps where name='#{@current_name}'\" #{PSQL_RAW_RES_ARGS}`.strip
717
+ unless app_id
718
+ raise "Can't find the app #{@current_name} amongst the deployed apps in the cloud_controller."
719
+ end
720
+ staged_hash=`psql --username #{db['username']} --dbname #{db['database']} -c \"select #{hash_type} from apps where id='#{app_id}'\" #{PSQL_RAW_RES_ARGS}`.strip
721
+ unless app_id
722
+ raise "The app #{@current_name} is not staged yet."
723
+ end
724
+ staged_hash.strip! if staged_hash
725
+ staged_hash
726
+ end
727
+
728
+ def version_available_file_path(prefix_app_by_default=true)
729
+ # extract the file that contains the version from that tar.gz
730
+ version_available_file=@application_json['repository']['version_installed']['staged_entry'] if @application_json['repository']['version_installed']
731
+ unless version_available_file
732
+ # default on the available url prefixed by the 'app' folder
733
+ if @application_json['repository']['version_available'] && @application_json['repository']['version_available']['url']
734
+ version_available_url=@application_json['repository']['version_available']['url']
735
+ if version_available_url.start_with?("./")
736
+ version_available_url.slice!(0)
737
+ version_available_url.slice!(0)
738
+ version_available_file= prefix_app_by_default ? "app/#{version_available_url}" : version_available_url
739
+ elsif !(/:\/\// =~ version_available_url) && !(version_available_url.start_with?("/"))
740
+ version_available_file= prefix_app_by_default ? "app/#{version_available_url}" : version_available_url
741
+ end
742
+ end
743
+ else
744
+ if version_available_file.start_with?('app/') && !prefix_app_by_default
745
+ version_available_file=version_available_file['app/'.length..-1]
746
+ elsif version_available_file.start_with?('tomcat/webapp/ROOT/') && !prefix_app_by_default
747
+ version_available_file=version_available_file['tomcat/webapp/ROOT/'.length..-1]
748
+ end
749
+ end
750
+ version_available_file
751
+ end
752
+
753
+ def cmd_read_version_installed()
754
+ cmd=@application_json['repository']['version_installed']['cmd'] if @application_json['repository']['version_installed']
755
+ cmd||=@application_json['repository']['version_available']['cmd'] if @application_json['repository']['version_available']
756
+ cmd
757
+ end
758
+
759
+ def read_version(droplet_dot_version,cmd)
760
+ if File.exists? droplet_dot_version
761
+ installed_version=`version_built_download=#{droplet_dot_version};#{cmd}`.strip
762
+ raise "could not read the installed version in \
763
+ #{File.expand_path(version_available_file)} with version_built_download=#{droplet_dot_version};#{cmd}" unless installed_version
764
+ installed_version.gsub!(/^["']|["']$/, '')
765
+ puts "#{@current_name} is staged with version installed_version #{installed_version}" if VMC::Cli::Config.trace
766
+ return installed_version
767
+ end
768
+ end
769
+
770
+ def droplet_file_path()
771
+ return unless @application_json['repository']
772
+ return unless ccdb_app_id()
773
+ # go into the cloud_controller db, find out the staged_hash
774
+ staged_hash=ccdb_staged_hash()
775
+ return unless staged_hash && !staged_hash.empty?
776
+ droplet="/var/vcap/shared/droplets/#{staged_hash}"
777
+ raise "Can't find the staged droplet file #{droplet}." unless File.exist?(droplet)
778
+ return droplet
779
+ end
780
+
781
+ # Reads the version installed
782
+ def version_installed()
783
+ droplet=droplet_file_path()
784
+ return unless droplet
785
+ version_available_file = version_available_file_path()
786
+ unless version_available_file
787
+ puts "Don't know what file stores the version installed of #{@current_name}" if VMC::Cli::Config.trace
788
+ return
789
+ end
790
+ cmd = cmd_read_version_installed()
791
+ unless cmd
792
+ puts "Don't know how to read the version installed with a cmd." if VMC::Cli::Config.trace
793
+ return
794
+ end
795
+ puts "Looking for the installed version here #{droplet} // #{version_available_file}" if VMC::Cli::Config.trace
796
+ puts " with cmd #{cmd}" if VMC::Cli::Config.trace
797
+ droplet_dot_version="#{droplet}.version"
798
+ unless File.exists? droplet_dot_version
799
+ Dir.chdir("/tmp") do
800
+ `[ -f #{version_available_file} ] && rm #{version_available_file}`
801
+ `tar -xzf #{droplet} #{version_available_file}`
802
+ if File.exist?(version_available_file)
803
+ `cp #{version_available_file} #{droplet_dot_version}`
804
+ else
805
+ put "Could not find the installed version file here: here #{droplet} // #{version_available_file}" if VMC::Cli::Config.trace
806
+ end
807
+ end
808
+ end
809
+ installed_version=read_version(droplet_dot_version,cmd)
810
+ end
811
+
812
+ def info()
813
+ app_id=ccdb_app_id()
814
+ if app_id
815
+ staged_hash=ccdb_staged_hash()||"deployed; not staged"
816
+ installed_v=version_installed()||"deployed; can't read installed version"
817
+ else
818
+ installed_v="not uploaded"
819
+ staged_hash="not staged"
820
+ end
821
+ available_v=version_available()||"none"
822
+ puts "Application #{@application_json['name']}"
823
+ puts " Version installed: #{installed_v}; Staged hash: #{staged_hash}"
824
+ puts " Version available: #{available_v}"
825
+ return installed_v == available_v if installed_v && available_v
826
+ return false
827
+ end
828
+
829
+ def wget_args()
830
+ _wget_args = @application_json['repository']['wget_args']
831
+ if _wget_args.nil?
832
+ wget_args_str = ""
833
+ elsif _wget_args.kind_of? Array
834
+ wget_args_str = wget_args.join(' ')
835
+ elsif _wget_args.kind_of? String
836
+ wget_args_str = wget_args
837
+ end
838
+ wget_args_str
839
+ end
840
+
841
+ def update(force=false)
842
+ raise "The application #{@application_json['name']} does not exist yet" if current().empty?
843
+ do_delete_download=false
844
+ begin
845
+ installed_version=version_installed()
846
+ p "#{@current_name} installed_version #{installed_version}"
847
+ available_version=version_available()
848
+ p "#{@current_name} available_version #{available_version}"
849
+ if installed_version == available_version
850
+ puts "The staged version of #{@current_name} is the same than the one on the remote repository"
851
+ return unless force
852
+ puts "Forced download"
853
+ end
854
+ do_delete_download=true
855
+ rescue => e
856
+ p "Trying to read the installed and available version crashed. #{e}"
857
+ p e.backtrace.join("\n") if VMC::Cli::Config.trace
858
+ end
859
+ upload(force,do_delete_download)
860
+ end
861
+
862
+ def app_download_dir_path()
863
+ "#{ENV['HOME']}/vmc_knife_downloads/#{@application_json['name']}"
864
+ end
865
+ def extract_deployed(force=false)
866
+ installed_v=version_installed()
867
+ unless installed_v
868
+ puts "No deployed app #{@application_json['name']}. Not extracting it"
869
+ return
870
+ end
871
+ do_extract=false
872
+ app_download_dir=app_download_dir_path()
873
+ if force
874
+ FileUtils.rm_rf app_download_dir if File.exists?(app_download_dir)
875
+ do_extract=true
876
+ elsif File.exists?(app_download_dir)
877
+ version_file_in_download = File.join(app_download_dir, version_available_file_path(false))
878
+ p "Reading the version of the downloaded app folder in file #{version_file_in_download}"
879
+ cmd_to_read=cmd_read_version_installed()
880
+ version_downloaded=read_version(version_file_in_download,cmd_to_read)
881
+ if installed_v != version_downloaded
882
+ p "The version installed is #{installed_v} and the version ready to be deployed is #{version_downloaded}"
883
+ p "Would you like to replace the app to deploy by the one already deployed?"
884
+ ans = STDIN.gets.chomp
885
+ if ans && ans.capitalize.start_with?('Y')
886
+ FileUtils.rm_rf app_download_dir if File.exists?(app_download_dir)
887
+ do_extract=true
888
+ end
889
+ else
890
+ p "The version installed and the version ready to deploy are identical: #{installed_v}"
891
+ end
892
+ else
893
+ do_extract = true
894
+ end
895
+ if do_extract
896
+ FileUtils.mkdir_p app_download_dir
897
+ drop_f_p=droplet_file_path()
898
+ p "tar -xzvf #{drop_f_p}"
899
+ `cd /tmp; [ -d drop_app ] && rm -rf drop_app; mkdir drop_app; cd drop_app; tar -xzvf #{drop_f_p}; [ -d app ] && mv app/* #{app_download_dir} || mv tomcat/webapps/ROOT/* #{app_download_dir}`
900
+ p "Done. ls -la #{app_download_dir}"
901
+ `ls -la #{app_download_dir}`
902
+ end
903
+ end
904
+ def upload(force=false,do_delete_download=false)
569
905
  raise "The application #{@application_json['name']} does not exist yet" if current().empty?
570
906
  return unless @application_json['repository']
571
907
  url = @application_json['repository']['url']
908
+
572
909
  Dir.chdir(ENV['HOME']) do
573
910
  tmp_download_filename="_download_.zip"
574
- app_download_dir="vmc_knife_downloads/#{@application_json['name']}"
911
+ app_download_dir=app_download_dir_path()
912
+ `rm -rf #{app_download_dir}` if File.exist?("#{app_download_dir}") && do_delete_download
575
913
  `rm -rf #{app_download_dir}` if File.exist? "#{app_download_dir}/#{tmp_download_filename}"
914
+
576
915
  FileUtils.mkdir_p app_download_dir
577
916
  Dir.chdir(app_download_dir) do
578
- if Dir.entries(Dir.pwd).size == 2
579
- #empty directory.
917
+ if Dir.entries(Dir.pwd).size == 2 #empty directory ?
580
918
  if /\.git$/ =~ url
581
919
  `git clone #{url} --depth 1`
582
920
  branch = @application_json['repository']['branch']
@@ -586,17 +924,13 @@ module VMC
586
924
  branch='master'
587
925
  end
588
926
  `git pull origin #{branch}`
589
- else
927
+ else
590
928
  begin
591
- wget_args = @application_json['repository']['wget_args']
592
- if wget_args.nil?
593
- wget_args_str = ""
594
- elsif wget_args.kind_of? Array
595
- wget_args_str = wget_args.join(' ')
596
- elsif wget_args.kind_of? String
597
- wget_args_str = wget_args
598
- end
599
- `wget #{wget_args_str} --output-document=#{tmp_download_filename} #{url}`
929
+ wget_args_str = wget_args()
930
+ #`wget #{wget_args_str} --output-document=#{tmp_download_filename} #{url}`
931
+ #TODO: find the same file in the installed apps.
932
+ `touch /tmp/wget_#{@application_json['name']};\
933
+ wget #{wget_args_str} --output-document=#{tmp_download_filename} #{url} --output-file=/tmp/wget_#{@application_json['name']}`
600
934
  raise "Unable to download #{url}" unless $? == 0
601
935
  if /\.tgz$/ =~ url || /\.tar\.gz$/ =~ url
602
936
  `tar zxvf #{tmp_download_filename}`
@@ -606,34 +940,79 @@ module VMC
606
940
  `unzip #{tmp_download_filename}`
607
941
  end
608
942
  ensure
609
- `rm #{tmp_download_filename}`
943
+ `[ -f #{tmp_download_filename} ] && rm #{tmp_download_filename}`
610
944
  end
945
+ =begin else
946
+ if /\.git$/ =~ url
947
+ branch = @application_json['repository']['branch']||"master"
948
+ `git checkout #{branch}`
949
+ `git pull origin #{branch}`
950
+ =end
611
951
  end
612
952
  end
613
- Dir.chdir(@application_json['repository']['sub_dir']) if @application_json['repository']['sub_dir']
614
- `rm -rf .git` if File.exists? ".git"
615
- VMC::KNIFE::HELPER.static_upload_app_bits(@client,@application_json['name'],Dir.pwd)
953
+ post_download_script = @application_json['repository']['post_download_script']
954
+ if post_download_script
955
+ curr_dir=Dir.pwd
956
+ post_download_script = post_download_script.join("\n") if post_download_script.kind_of?(Array)
957
+ p "Executing the post_download script : #{post_download_script}"
958
+ success = system(post_download_script)
959
+ p "Done executing the post_download script succcess #{success}"
960
+ exit unless success
961
+ Dir.chdir(curr_dir)
962
+ end
963
+ upload_app_bits()
616
964
  end
617
965
  end
618
966
  end
619
-
967
+
968
+ def upload_app_bits()
969
+ Dir.chdir(app_download_dir_path()) do
970
+ puts "upload_app_bits in #{app_download_dir_path()}"
971
+ Dir.chdir(@application_json['repository']['sub_dir']) if @application_json['repository']['sub_dir']
972
+ tmp_git = "/tmp/#{@application_json['name']}.git"
973
+ if File.exists? ".git"
974
+ # don't deploy the .git repo
975
+ FileUtils.rm_rf(tmp_git) if File.exists?(tmp_git)
976
+ FileUtils.mv(".git", tmp_git)
977
+ end
978
+ begin
979
+ VMC::KNIFE::HELPER.static_upload_app_bits(@client,@application_json['name'],Dir.pwd)
980
+ rescue
981
+ FileUtils.mv(tmp_git, ".git") if File.exists?(tmp_git)
982
+ end
983
+ end
984
+ end
985
+
986
+ def patch(force=false)
987
+ extract_deployed(force)
988
+ app_download_dir=app_download_dir_path()
989
+ p "Application ready to be patched in #{app_download_dir}"
990
+ p "Type y when ready to update. Anything else will stop."
991
+ ans = STDIN.gets.chomp
992
+ return unless ans && ans.capitalize.start_with?('Y')
993
+ upload_app_bits()
994
+ end
995
+
620
996
  def start()
621
- raise "The application #{@application_json['name']} does not exist yet" if current().empty?
622
- return if current[:state] == 'STARTED'
997
+ #raise "The application #{@application_json['name']} does not exist yet" if current().empty?
998
+ return if current().empty? || current[:state] == 'STARTED'
623
999
  current[:state] = 'STARTED'
624
1000
  client.update_app(@application_json['name'], current())
625
1001
  end
626
1002
 
627
1003
  def stop()
628
- raise "The application #{@application_json['name']} does not exist yet" if current().empty?
629
- return if current[:state] == 'STOPPED'
1004
+ #raise "The application #{@application_json['name']} does not exist yet" if current().empty?
1005
+ return if current().empty? || current[:state] == 'STOPPED'
630
1006
  current[:state] = 'STOPPED'
631
1007
  client.update_app(@application_json['name'], current())
632
1008
  end
633
1009
 
634
1010
  def delete()
635
- raise "The application #{@application_json['name']} does not exist yet" if current().empty?
636
- client.delete_app(@application_json['name'])
1011
+ if current().empty?
1012
+ puts "The application #{@application_json['name']} does not exist yet" if VMC::Cli::Config.trace
1013
+ else
1014
+ client.delete_app(@application_json['name']) unless current().empty?
1015
+ end
637
1016
  end
638
1017
 
639
1018
  # Generate the updated application manifest:
@@ -693,7 +1072,9 @@ module VMC
693
1072
  def update_memory_pending()
694
1073
  old_mem = current[:resources][:memory] if current[:resources]
695
1074
  old_mem ||= current['resources']['memory'] if current['resources']
1075
+ old_mem = old_mem.to_i if old_mem && old_mem.kind_of?(String)
696
1076
  new_mem = @application_json['resources']['memory'] unless @application_json['resources'].nil?
1077
+ new_mem = new_mem.to_i if new_mem && new_mem.kind_of?(String)
697
1078
  if old_mem != new_mem
698
1079
  return "#{old_mem} => #{new_mem}"
699
1080
  end
metadata CHANGED
@@ -1,151 +1,108 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: vmc_knife
3
- version: !ruby/object:Gem::Version
4
- hash: 5
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.40
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 13
10
- version: 0.0.13
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Intalio Pte
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-02-08 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-08-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: vmc
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &28784440 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
18
+ requirements:
26
19
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 62196459
29
- segments:
30
- - 0
31
- - 3
32
- - 14
33
- - beta
34
- - 4
35
- version: 0.3.14.beta4
20
+ - !ruby/object:Gem::Version
21
+ version: 0.3.18
36
22
  type: :runtime
37
- version_requirements: *id001
38
- - !ruby/object:Gem::Dependency
39
- name: rest-client
40
23
  prerelease: false
41
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *28784440
25
+ - !ruby/object:Gem::Dependency
26
+ name: rest-client
27
+ requirement: &28783860 !ruby/object:Gem::Requirement
42
28
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- hash: 13
47
- segments:
48
- - 1
49
- - 6
50
- - 1
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
51
32
  version: 1.6.1
52
33
  - - <
53
- - !ruby/object:Gem::Version
54
- hash: 11
55
- segments:
56
- - 1
57
- - 7
58
- - 0
34
+ - !ruby/object:Gem::Version
59
35
  version: 1.7.0
60
36
  type: :runtime
61
- version_requirements: *id002
62
- - !ruby/object:Gem::Dependency
63
- name: rspec
64
37
  prerelease: false
65
- requirement: &id003 !ruby/object:Gem::Requirement
38
+ version_requirements: *28783860
39
+ - !ruby/object:Gem::Dependency
40
+ name: rspec
41
+ requirement: &29208120 !ruby/object:Gem::Requirement
66
42
  none: false
67
- requirements:
43
+ requirements:
68
44
  - - ~>
69
- - !ruby/object:Gem::Version
70
- hash: 27
71
- segments:
72
- - 1
73
- - 3
74
- - 0
45
+ - !ruby/object:Gem::Version
75
46
  version: 1.3.0
76
47
  type: :development
77
- version_requirements: *id003
78
- - !ruby/object:Gem::Dependency
79
- name: webmock
80
48
  prerelease: false
81
- requirement: &id004 !ruby/object:Gem::Requirement
49
+ version_requirements: *29208120
50
+ - !ruby/object:Gem::Dependency
51
+ name: webmock
52
+ requirement: &29206780 !ruby/object:Gem::Requirement
82
53
  none: false
83
- requirements:
84
- - - "="
85
- - !ruby/object:Gem::Version
86
- hash: 3
87
- segments:
88
- - 1
89
- - 5
90
- - 0
54
+ requirements:
55
+ - - =
56
+ - !ruby/object:Gem::Version
91
57
  version: 1.5.0
92
58
  type: :development
93
- version_requirements: *id004
59
+ prerelease: false
60
+ version_requirements: *29206780
94
61
  description: Extensions for VMC the CLI of VMWare's Cloud Foundry
95
62
  email: hmalphettes@gmail.com
96
- executables:
63
+ executables:
97
64
  - vmc_knife
98
65
  extensions: []
99
-
100
- extra_rdoc_files:
66
+ extra_rdoc_files:
101
67
  - README.md
102
68
  - LICENSE
103
- files:
69
+ files:
104
70
  - LICENSE
105
71
  - README.md
106
72
  - lib/restclient/restclient_add_timeout.rb
107
- - lib/vmc_knife/cli_extensions.rb
108
- - lib/vmc_knife/commands/knife_cmds.rb
109
- - lib/vmc_knife/data_services.rb
110
73
  - lib/vmc_knife/json_expander.rb
74
+ - lib/vmc_knife/data_services.rb
75
+ - lib/vmc_knife/commands/knife_cmds.rb
76
+ - lib/vmc_knife/vmc_knife.rb
77
+ - lib/vmc_knife/cli_extensions.rb
111
78
  - lib/vmc_knife/mongo/mongo_cmd.js.erb
112
79
  - lib/vmc_knife/version.rb
113
80
  - lib/vmc_knife/vmc_helper.rb
114
- - lib/vmc_knife/vmc_knife.rb
115
81
  - lib/vmc_knife.rb
116
- - bin/vmc_knife
82
+ - !binary |-
83
+ YmluL3ZtY19rbmlmZQ==
117
84
  homepage: http://intalio.com
118
85
  licenses: []
119
-
120
86
  post_install_message:
121
87
  rdoc_options: []
122
-
123
- require_paths:
88
+ require_paths:
124
89
  - lib
125
- required_ruby_version: !ruby/object:Gem::Requirement
90
+ required_ruby_version: !ruby/object:Gem::Requirement
126
91
  none: false
127
- requirements:
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- hash: 3
131
- segments:
132
- - 0
133
- version: "0"
134
- required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
97
  none: false
136
- requirements:
137
- - - ">="
138
- - !ruby/object:Gem::Version
139
- hash: 3
140
- segments:
141
- - 0
142
- version: "0"
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
143
102
  requirements: []
144
-
145
103
  rubyforge_project:
146
- rubygems_version: 1.8.11
104
+ rubygems_version: 1.8.15
147
105
  signing_key:
148
106
  specification_version: 3
149
107
  summary: Extensions for VMC the CLI of VMWare's Cloud Foundry
150
108
  test_files: []
151
-