tac 0.6.0

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.
Files changed (43) hide show
  1. data/LICENSE +24 -0
  2. data/README.md +102 -0
  3. data/Rakefile +101 -0
  4. data/bin/tac +6 -0
  5. data/caldecott_helper/Gemfile +10 -0
  6. data/caldecott_helper/Gemfile.lock +48 -0
  7. data/caldecott_helper/server.rb +43 -0
  8. data/config/clients.yml +17 -0
  9. data/config/micro/offline.conf +2 -0
  10. data/config/micro/paths.yml +22 -0
  11. data/config/micro/refresh_ip.rb +20 -0
  12. data/lib/cli/commands/admin.rb +108 -0
  13. data/lib/cli/commands/apps.rb +1133 -0
  14. data/lib/cli/commands/base.rb +232 -0
  15. data/lib/cli/commands/manifest.rb +56 -0
  16. data/lib/cli/commands/micro.rb +115 -0
  17. data/lib/cli/commands/misc.rb +129 -0
  18. data/lib/cli/commands/services.rb +242 -0
  19. data/lib/cli/commands/user.rb +65 -0
  20. data/lib/cli/config.rb +173 -0
  21. data/lib/cli/console_helper.rb +160 -0
  22. data/lib/cli/core_ext.rb +122 -0
  23. data/lib/cli/errors.rb +19 -0
  24. data/lib/cli/frameworks.rb +276 -0
  25. data/lib/cli/manifest_helper.rb +341 -0
  26. data/lib/cli/runner.rb +547 -0
  27. data/lib/cli/services_helper.rb +92 -0
  28. data/lib/cli/tunnel_helper.rb +332 -0
  29. data/lib/cli/usage.rb +115 -0
  30. data/lib/cli/version.rb +7 -0
  31. data/lib/cli/zip_util.rb +77 -0
  32. data/lib/cli.rb +47 -0
  33. data/lib/vmc/client.rb +573 -0
  34. data/lib/vmc/const.rb +24 -0
  35. data/lib/vmc/micro/switcher/base.rb +97 -0
  36. data/lib/vmc/micro/switcher/darwin.rb +19 -0
  37. data/lib/vmc/micro/switcher/dummy.rb +15 -0
  38. data/lib/vmc/micro/switcher/linux.rb +16 -0
  39. data/lib/vmc/micro/switcher/windows.rb +31 -0
  40. data/lib/vmc/micro/vmrun.rb +158 -0
  41. data/lib/vmc/micro.rb +56 -0
  42. data/lib/vmc.rb +3 -0
  43. metadata +295 -0
data/lib/cli/runner.rb ADDED
@@ -0,0 +1,547 @@
1
+
2
+ require 'optparse'
3
+
4
+ require File.dirname(__FILE__) + '/usage'
5
+
6
+ class VMC::Cli::Runner
7
+
8
+ attr_reader :namespace
9
+ attr_reader :action
10
+ attr_reader :args
11
+ attr_reader :options
12
+
13
+ def self.run(args)
14
+ new(args).run
15
+ end
16
+
17
+ def initialize(args=[])
18
+ @args = args
19
+ @options = { :colorize => true }
20
+ @exit_status = true
21
+ end
22
+
23
+ # Collect all the available options for all commands
24
+ # Some duplicates exists to capture all scenarios
25
+ def parse_options!
26
+ opts_parser = OptionParser.new do |opts|
27
+ opts.banner = "\nAvailable options:\n\n"
28
+
29
+ opts.on('--email EMAIL') { |email| @options[:email] = email }
30
+ opts.on('--user EMAIL') { |email| @options[:email] = email }
31
+ opts.on('--passwd PASS') { |pass| @options[:password] = pass }
32
+ opts.on('--pass PASS') { |pass| @options[:password] = pass }
33
+ opts.on('--password PASS') { |pass| @options[:password] = pass }
34
+ opts.on('--token-file TOKEN_FILE') { |token_file| @options[:token_file] = token_file }
35
+ opts.on('--app NAME') { |name| @options[:name] = name }
36
+ opts.on('--name NAME') { |name| @options[:name] = name }
37
+ opts.on('--bind BIND') { |bind| @options[:bind] = bind }
38
+ opts.on('--instance INST') { |inst| @options[:instance] = inst }
39
+ opts.on('--instances INST') { |inst| @options[:instances] = inst }
40
+ opts.on('--url URL') { |url| @options[:url] = url }
41
+ opts.on('--mem MEM') { |mem| @options[:mem] = mem }
42
+ opts.on('--path PATH') { |path| @options[:path] = path }
43
+ opts.on('--no-start') { @options[:nostart] = true }
44
+ opts.on('--nostart') { @options[:nostart] = true }
45
+ opts.on('--force') { @options[:force] = true }
46
+ opts.on('--all') { @options[:all] = true }
47
+
48
+ # generic tracing and debugging
49
+ opts.on('-t [TKEY]') { |tkey| @options[:trace] = tkey || true }
50
+ opts.on('--trace [TKEY]') { |tkey| @options[:trace] = tkey || true }
51
+
52
+ # start application in debug mode
53
+ opts.on('-d [MODE]') { |mode| @options[:debug] = mode || "run" }
54
+ opts.on('--debug [MODE]') { |mode| @options[:debug] = mode || "run" }
55
+
56
+ # override manifest file
57
+ opts.on('-m FILE') { |file| @options[:manifest] = file }
58
+ opts.on('--manifest FILE') { |file| @options[:manifest] = file }
59
+
60
+ opts.on('-q', '--quiet') { @options[:quiet] = true }
61
+
62
+ # micro cloud options
63
+ opts.on('--vmx FILE') { |file| @options[:vmx] = file }
64
+ opts.on('--vmrun FILE') { |file| @options[:vmrun] = file }
65
+ opts.on('--save') { @options[:save] = true }
66
+
67
+ # Don't use builtin zip
68
+ opts.on('--no-zip') { @options[:nozip] = true }
69
+ opts.on('--nozip') { @options[:nozip] = true }
70
+
71
+ opts.on('--no-resources') { @options[:noresources] = true }
72
+ opts.on('--noresources') { @options[:noresources] = true }
73
+
74
+ opts.on('--no-color') { @options[:colorize] = false }
75
+ opts.on('--verbose') { @options[:verbose] = true }
76
+
77
+ opts.on('-n','--no-prompt') { @options[:noprompts] = true }
78
+ opts.on('--noprompt') { @options[:noprompts] = true }
79
+ opts.on('--non-interactive') { @options[:noprompts] = true }
80
+
81
+ opts.on('--prefix') { @options[:prefixlogs] = true }
82
+ opts.on('--prefix-logs') { @options[:prefixlogs] = true }
83
+ opts.on('--prefixlogs') { @options[:prefixlogs] = true }
84
+
85
+ opts.on('--json') { @options[:json] = true }
86
+
87
+ opts.on('-v', '--version') { set_cmd(:misc, :version) }
88
+ opts.on('-h', '--help') { puts "#{command_usage}\n"; exit }
89
+
90
+ opts.on('--port PORT') { |port| @options[:port] = port }
91
+
92
+ opts.on('--runtime RUNTIME') { |rt| @options[:runtime] = rt }
93
+
94
+ # deprecated
95
+ opts.on('--exec EXEC') { |exec| @options[:exec] = exec }
96
+ opts.on('--noframework') { @options[:noframework] = true }
97
+ opts.on('--canary') { @options[:canary] = true }
98
+
99
+ # Proxying for another user, requires admin privileges
100
+ opts.on('-u PROXY') { |proxy| @options[:proxy] = proxy }
101
+
102
+ opts.on_tail('--options') { puts "#{opts}\n"; exit }
103
+ end
104
+ instances_delta_arg = check_instances_delta!
105
+ @args = opts_parser.parse!(@args)
106
+ @args.concat instances_delta_arg
107
+ convert_options!
108
+ self
109
+ end
110
+
111
+ def check_instances_delta!
112
+ return unless @args
113
+ instance_args = @args.select { |arg| /^[-]\d+$/ =~ arg } || []
114
+ @args.delete_if { |arg| instance_args.include? arg}
115
+ instance_args
116
+ end
117
+
118
+ def display_help
119
+ puts command_usage
120
+ exit
121
+ end
122
+
123
+ def convert_options!
124
+ # make sure certain options are valid and in correct form.
125
+ @options[:instances] = Integer(@options[:instances]) if @options[:instances]
126
+ end
127
+
128
+ def set_cmd(namespace, action, args_range=0)
129
+ return if @help_only
130
+ unless args_range == "*" || args_range.is_a?(Range)
131
+ args_range = (args_range.to_i..args_range.to_i)
132
+ end
133
+
134
+ if args_range == "*" || args_range.include?(@args.size)
135
+ @namespace = namespace
136
+ @action = action
137
+ else
138
+ @exit_status = false
139
+ if @args.size > args_range.last
140
+ usage_error("Too many arguments for [#{action}]: %s" % [ @args[args_range.last..-1].map{|a| "'#{a}'"}.join(', ') ])
141
+ else
142
+ usage_error("Not enough arguments for [#{action}]")
143
+ end
144
+ end
145
+ end
146
+
147
+ def parse_command!
148
+ # just return if already set, happends with -v, -h
149
+ return if @namespace && @action
150
+
151
+ verb = @args.shift
152
+ case verb
153
+
154
+ when 'version'
155
+ usage('vmc version')
156
+ set_cmd(:misc, :version)
157
+
158
+ when 'target'
159
+ usage('vmc target [url] [--url]')
160
+ if @args.size == 1
161
+ set_cmd(:misc, :set_target, 1)
162
+ else
163
+ set_cmd(:misc, :target)
164
+ end
165
+
166
+ when 'targets'
167
+ usage('vmc targets')
168
+ set_cmd(:misc, :targets)
169
+
170
+ when 'tokens'
171
+ usage('vmc tokens')
172
+ set_cmd(:misc, :tokens)
173
+
174
+ when 'info'
175
+ usage('vmc info')
176
+ set_cmd(:misc, :info)
177
+
178
+ when 'runtimes'
179
+ usage('vmc runtimes')
180
+ set_cmd(:misc, :runtimes)
181
+
182
+ when 'frameworks'
183
+ usage('vmc frameworks')
184
+ set_cmd(:misc, :frameworks)
185
+
186
+ when 'user'
187
+ usage('vmc user')
188
+ set_cmd(:user, :info)
189
+
190
+ when 'login'
191
+ usage('vmc login [email] [--email EMAIL] [--passwd PASS]')
192
+ if @args.size == 1
193
+ set_cmd(:user, :login, 1)
194
+ else
195
+ set_cmd(:user, :login)
196
+ end
197
+
198
+ when 'logout'
199
+ usage('vmc logout')
200
+ set_cmd(:user, :logout)
201
+
202
+ when 'passwd'
203
+ usage('vmc passwd')
204
+ if @args.size == 1
205
+ set_cmd(:user, :change_password, 1)
206
+ else
207
+ set_cmd(:user, :change_password)
208
+ end
209
+
210
+ when 'quota'
211
+ usage('vmc quota')
212
+ if @args.size == 1
213
+ set_cmd(:admin, :change_quota, 1)
214
+ else
215
+ set_cmd(:admin, :change_quota)
216
+ end
217
+
218
+ when 'add-user', 'add_user', 'create_user', 'create-user', 'register'
219
+ usage('vmc add-user [user] [--email EMAIL] [--passwd PASS]')
220
+ if @args.size == 1
221
+ set_cmd(:admin, :add_user, 1)
222
+ else
223
+ set_cmd(:admin, :add_user)
224
+ end
225
+
226
+ when 'delete-user', 'delete_user', 'unregister'
227
+ usage('vmc delete-user <user>')
228
+ set_cmd(:admin, :delete_user, 1)
229
+
230
+ when 'users'
231
+ usage('vmc users')
232
+ set_cmd(:admin, :users)
233
+
234
+ when 'apps'
235
+ usage('vmc apps')
236
+ set_cmd(:apps, :apps)
237
+
238
+ when 'list'
239
+ usage('vmc list')
240
+ set_cmd(:apps, :list)
241
+
242
+ when 'start'
243
+ usage('vmc start <appname>')
244
+ set_cmd(:apps, :start, @args.size == 1 ? 1 : 0)
245
+
246
+ when 'stop'
247
+ usage('vmc stop <appname>')
248
+ set_cmd(:apps, :stop, @args.size == 1 ? 1 : 0)
249
+
250
+ when 'restart'
251
+ usage('vmc restart <appname>')
252
+ set_cmd(:apps, :restart, @args.size == 1 ? 1 : 0)
253
+
254
+ when 'mem'
255
+ usage('vmc mem <appname> [memsize]')
256
+ if @args.size == 2
257
+ set_cmd(:apps, :mem, 2)
258
+ else
259
+ set_cmd(:apps, :mem, 1)
260
+ end
261
+
262
+ when 'stats'
263
+ usage('vmc stats <appname>')
264
+ set_cmd(:apps, :stats, @args.size == 1 ? 1 : 0)
265
+
266
+ when 'map'
267
+ usage('vmc map <appname> <url>')
268
+ set_cmd(:apps, :map, 2)
269
+
270
+ when 'unmap'
271
+ usage('vmc unmap <appname> <url>')
272
+ set_cmd(:apps, :unmap, 2)
273
+
274
+ when 'delete'
275
+ usage('vmc delete <appname>')
276
+ if @options[:all] && @args.size == 0
277
+ set_cmd(:apps, :delete)
278
+ else
279
+ set_cmd(:apps, :delete, 1)
280
+ end
281
+
282
+ when 'files'
283
+ usage('vmc files <appname> [path] [--instance N] [--all] [--prefix]')
284
+ if @args.size == 1
285
+ set_cmd(:apps, :files, 1)
286
+ else
287
+ set_cmd(:apps, :files, 2)
288
+ end
289
+
290
+ when 'logs'
291
+ usage('vmc logs <appname> [--instance N] [--all] [--prefix]')
292
+ set_cmd(:apps, :logs, 1)
293
+
294
+ when 'instances', 'scale'
295
+ if @args.size > 1
296
+ usage('vmc instances <appname> <num|delta>')
297
+ set_cmd(:apps, :instances, 2)
298
+ else
299
+ usage('vmc instances <appname>')
300
+ set_cmd(:apps, :instances, 1)
301
+ end
302
+
303
+ when 'crashes'
304
+ usage('vmc crashes <appname>')
305
+ set_cmd(:apps, :crashes, 1)
306
+
307
+ when 'crashlogs'
308
+ usage('vmc crashlogs <appname>')
309
+ set_cmd(:apps, :crashlogs, 1)
310
+
311
+ when 'push'
312
+ usage('vmc push [appname] [--path PATH] [--url URL] [--instances N] [--mem] [--runtime RUNTIME] [--no-start]')
313
+ if @args.size == 1
314
+ set_cmd(:apps, :push, 1)
315
+ else
316
+ set_cmd(:apps, :push, 0)
317
+ end
318
+
319
+ when 'update'
320
+ usage('vmc update <appname> [--path PATH]')
321
+ set_cmd(:apps, :update, @args.size == 1 ? 1 : 0)
322
+
323
+ when 'services'
324
+ usage('vmc services')
325
+ set_cmd(:services, :services)
326
+
327
+ when 'env'
328
+ usage('vmc env <appname>')
329
+ set_cmd(:apps, :environment, 1)
330
+
331
+ when 'env-add'
332
+ usage('vmc env-add <appname> <variable[=]value>')
333
+ if @args.size == 2
334
+ set_cmd(:apps, :environment_add, 2)
335
+ elsif @args.size == 3
336
+ set_cmd(:apps, :environment_add, 3)
337
+ end
338
+
339
+ when 'env-del'
340
+ usage('vmc env-del <appname> <variable>')
341
+ set_cmd(:apps, :environment_del, 2)
342
+
343
+ when 'create-service', 'create_service'
344
+ usage('vmc create-service [service] [servicename] [appname] [--name servicename] [--bind appname]')
345
+ set_cmd(:services, :create_service) if @args.size == 0
346
+ set_cmd(:services, :create_service, 1) if @args.size == 1
347
+ set_cmd(:services, :create_service, 2) if @args.size == 2
348
+ set_cmd(:services, :create_service, 3) if @args.size == 3
349
+
350
+ when 'delete-service', 'delete_service'
351
+ usage('vmc delete-service <service>')
352
+ if @args.size == 1
353
+ set_cmd(:services, :delete_service, 1)
354
+ else
355
+ set_cmd(:services, :delete_service)
356
+ end
357
+
358
+ when 'quota-service', 'quota_service'
359
+ usage('vmc quota_service <service>')
360
+ if @args.size == 1
361
+ set_cmd(:services, :quota_service, 1)
362
+ else
363
+ set_cmd(:services, :quota_service)
364
+ end
365
+
366
+ when 'bind-service', 'bind_service'
367
+ usage('vmc bind-service <servicename> <appname>')
368
+ set_cmd(:services, :bind_service, 2)
369
+
370
+ when 'unbind-service', 'unbind_service'
371
+ usage('vmc unbind-service <servicename> <appname>')
372
+ set_cmd(:services, :unbind_service, 2)
373
+
374
+ when 'clone-services'
375
+ usage('vmc clone-services <src-app> <dest-app>')
376
+ set_cmd(:services, :clone_services, 2)
377
+
378
+ when 'aliases'
379
+ usage('vmc aliases')
380
+ set_cmd(:misc, :aliases)
381
+
382
+ when 'alias'
383
+ usage('vmc alias <alias[=]command>')
384
+ if @args.size == 1
385
+ set_cmd(:misc, :alias, 1)
386
+ elsif @args.size == 2
387
+ set_cmd(:misc, :alias, 2)
388
+ end
389
+
390
+ when 'unalias'
391
+ usage('vmc unalias <alias>')
392
+ set_cmd(:misc, :unalias, 1)
393
+
394
+ when 'tunnel'
395
+ usage('vmc tunnel [servicename] [clientcmd] [--port port]')
396
+ set_cmd(:services, :tunnel, 0) if @args.size == 0
397
+ set_cmd(:services, :tunnel, 1) if @args.size == 1
398
+ set_cmd(:services, :tunnel, 2) if @args.size == 2
399
+
400
+ when 'rails-console'
401
+ usage('vmc rails-console <appname>')
402
+ set_cmd(:apps, :console, 1)
403
+
404
+ when 'micro'
405
+ usage('vmc micro <online|offline|status> [--password password] [--save] [--vmx file] [--vmrun executable]')
406
+ if %w[online offline status].include?(@args[0])
407
+ set_cmd(:micro, @args[0].to_sym, 1)
408
+ end
409
+
410
+ when 'help'
411
+ display_help if @args.size == 0
412
+ @help_only = true
413
+ parse_command!
414
+
415
+ when 'usage'
416
+ display basic_usage
417
+ exit(true)
418
+
419
+ when 'options'
420
+ # Simulate --options
421
+ @args = @args.unshift('--options')
422
+ parse_options!
423
+
424
+ when 'manifest'
425
+ usage('vmc manifest')
426
+ set_cmd(:manifest, :edit)
427
+
428
+ when 'extend-manifest'
429
+ usage('vmc extend-manifest')
430
+ set_cmd(:manifest, :extend, 1)
431
+
432
+ else
433
+ if verb
434
+ display "vmc: Unknown command [#{verb}]"
435
+ display basic_usage
436
+ exit(false)
437
+ end
438
+ end
439
+ end
440
+
441
+ def process_aliases!
442
+ return if @args.empty?
443
+ aliases = VMC::Cli::Config.aliases
444
+ aliases.each_pair do |k,v|
445
+ if @args[0] == k
446
+ display "[#{@args[0]} aliased to #{aliases.invert[key]}]" if @options[:verbose]
447
+ @args[0] = v
448
+ break;
449
+ end
450
+ end
451
+ end
452
+
453
+ def usage(msg = nil)
454
+ @usage = msg if msg
455
+ @usage
456
+ end
457
+
458
+ def usage_error(msg = nil)
459
+ @usage_error = msg if msg
460
+ @usage_error
461
+ end
462
+
463
+ def run
464
+
465
+ trap('TERM') { print "\nTerminated\n"; exit(false)}
466
+
467
+ parse_options!
468
+
469
+ @options[:colorize] = false unless STDOUT.tty?
470
+
471
+ VMC::Cli::Config.colorize = @options.delete(:colorize)
472
+ VMC::Cli::Config.nozip = @options.delete(:nozip)
473
+ VMC::Cli::Config.trace = @options.delete(:trace)
474
+ VMC::Cli::Config.output ||= STDOUT unless @options[:quiet]
475
+
476
+ process_aliases!
477
+ parse_command!
478
+
479
+ if @namespace && @action
480
+ cmd = VMC::Cli::Command.const_get(@namespace.to_s.capitalize)
481
+ cmd.new(@options).send(@action, *@args.collect(&:dup))
482
+ elsif @help_only || @usage
483
+ display_usage
484
+ else
485
+ display basic_usage
486
+ exit(false)
487
+ end
488
+
489
+ rescue OptionParser::InvalidOption => e
490
+ puts(e.message.red)
491
+ puts("\n")
492
+ puts(basic_usage)
493
+ @exit_status = false
494
+ rescue OptionParser::AmbiguousOption => e
495
+ puts(e.message.red)
496
+ puts("\n")
497
+ puts(basic_usage)
498
+ @exit_status = false
499
+ rescue VMC::Client::AuthError => e
500
+ if VMC::Cli::Config.auth_token.nil?
501
+ puts "Login Required".red
502
+ else
503
+ puts "Not Authorized".red
504
+ end
505
+ @exit_status = false
506
+ rescue VMC::Client::TargetError, VMC::Client::NotFound, VMC::Client::BadTarget => e
507
+ puts e.message.red
508
+ @exit_status = false
509
+ rescue VMC::Client::HTTPException => e
510
+ puts e.message.red
511
+ @exit_status = false
512
+ rescue VMC::Cli::GracefulExit => e
513
+ # Redirected commands end up generating this exception (kind of goto)
514
+ rescue VMC::Cli::CliExit => e
515
+ puts e.message.red
516
+ @exit_status = false
517
+ rescue VMC::Cli::CliError => e
518
+ say("Error #{e.error_code}: #{e.message}".red)
519
+ @exit_status = false
520
+ rescue SystemExit => e
521
+ @exit_status = e.success?
522
+ rescue SyntaxError => e
523
+ puts e.message.red
524
+ puts e.backtrace
525
+ @exit_status = false
526
+ rescue Interrupt => e
527
+ say("\nInterrupted".red)
528
+ @exit_status = false
529
+ rescue Exception => e
530
+ puts e.message.red
531
+ puts e.backtrace
532
+ @exit_status = false
533
+ ensure
534
+ say("\n")
535
+ @exit_status == true if @exit_status.nil?
536
+ if @options[:verbose]
537
+ if @exit_status
538
+ puts "[#{@namespace}:#{@action}] SUCCEEDED".green
539
+ else
540
+ puts "[#{@namespace}:#{@action}] FAILED".red
541
+ end
542
+ say("\n")
543
+ end
544
+ exit(@exit_status)
545
+ end
546
+
547
+ end
@@ -0,0 +1,92 @@
1
+
2
+ module VMC::Cli
3
+ module ServicesHelper
4
+ def display_system_services(services=nil)
5
+ services ||= client.services_info
6
+
7
+ display "\n============== System Services ==============\n\n"
8
+
9
+ return display "No system services available" if services.empty?
10
+
11
+ displayed_services = []
12
+ services.each do |service_type, value|
13
+ value.each do |vendor, version|
14
+ version.each do |version_str, service|
15
+ displayed_services << [ vendor, version_str, service[:description] ]
16
+ end
17
+ end
18
+ end
19
+ displayed_services.sort! { |a, b| a.first.to_s <=> b.first.to_s}
20
+
21
+ services_table = table do |t|
22
+ t.headings = 'Service', 'Version', 'Description'
23
+ displayed_services.each { |s| t << s }
24
+ end
25
+ display services_table
26
+ end
27
+
28
+ def display_provisioned_services(services=nil)
29
+ services ||= client.services
30
+ display "\n=========== Provisioned Services ============\n\n"
31
+ display_provisioned_services_table(services)
32
+ end
33
+
34
+ def display_provisioned_services_table(services)
35
+ return unless services && !services.empty?
36
+ services_table = table do |t|
37
+ t.headings = 'Name', 'Service'
38
+ services.each do |service|
39
+ t << [ service[:name], service[:vendor] ]
40
+ end
41
+ end
42
+ display services_table
43
+ end
44
+ =begin
45
+ def create_service_banner(service, name, display_name=false)
46
+ sn = " [#{name}]" if display_name
47
+ display "Creating Service#{sn}: ", false
48
+ client.create_service(service, name)
49
+ display 'OK'.green
50
+ end
51
+ =end
52
+
53
+ def create_service_banner(service, name, dbflag , dbjndi, dbusername, dbpasswd, dburl, dbsize, display_name=false)
54
+ sn = " [#{name}]" if display_name
55
+ display "Creating Service#{sn}: ", false
56
+ client.create_service(service, name, dbflag , dbjndi, dbusername, dbpasswd, dburl, dbsize)
57
+ display 'OK'.green
58
+ end
59
+
60
+ def bind_service_banner(service, appname, check_restart=true)
61
+ display "Binding Service [#{service}]: ", false
62
+ client.bind_service(service, appname)
63
+ display 'OK'.green
64
+ check_app_for_restart(appname) if check_restart
65
+ end
66
+
67
+ def unbind_service_banner(service, appname, check_restart=true)
68
+ display "Unbinding Service [#{service}]: ", false
69
+ client.unbind_service(service, appname)
70
+ display 'OK'.green
71
+ check_app_for_restart(appname) if check_restart
72
+ end
73
+
74
+ def delete_service_banner(service)
75
+ display "Deleting service [#{service}]: ", false
76
+ client.delete_service(service)
77
+ display 'OK'.green
78
+ end
79
+
80
+ def random_service_name(service)
81
+ r = "%04x" % [rand(0x0100000)]
82
+ "#{service.to_s}-#{r}"
83
+ end
84
+
85
+ def check_app_for_restart(appname)
86
+ app = client.app_info(appname)
87
+ cmd = VMC::Cli::Command::Apps.new(@options)
88
+ cmd.restart(appname) if app[:state] == 'STARTED'
89
+ end
90
+
91
+ end
92
+ end