|
2 | 2 |
|
3 | 3 | require 'rubygems'
|
4 | 4 | require 'commander'
|
| 5 | +require 'colorize' |
| 6 | +require 'json' |
5 | 7 | require 'pp'
|
6 | 8 | require 'vmfloaty/auth'
|
7 | 9 | require 'vmfloaty/pooler'
|
@@ -413,12 +415,39 @@ def run
|
413 | 415 | c.example 'Gets the current vmpooler status', 'floaty status --url http://vmpooler.example.com'
|
414 | 416 | c.option '--verbose', 'Enables verbose output'
|
415 | 417 | c.option '--url STRING', String, 'URL of vmpooler'
|
| 418 | + c.option '--json', 'Prints status in JSON format' |
416 | 419 | c.action do |args, options|
|
417 | 420 | verbose = options.verbose || config['verbose']
|
418 | 421 | url = options.url ||= config['url']
|
419 | 422 |
|
420 | 423 | status = Pooler.status(verbose, url)
|
421 |
| - pp status |
| 424 | + message = status['status']['message'] |
| 425 | + pools = status['pools'] |
| 426 | + |
| 427 | + if options.json |
| 428 | + pp status |
| 429 | + else |
| 430 | + pools.select! {|name,pool| pool['ready'] < pool['max']} if ! verbose |
| 431 | + |
| 432 | + width = pools.keys.map(&:length).max |
| 433 | + pools.each do |name,pool| |
| 434 | + begin |
| 435 | + max = pool['max'] |
| 436 | + ready = pool['ready'] |
| 437 | + pending = pool['pending'] |
| 438 | + missing = max - ready - pending |
| 439 | + char = 'o' |
| 440 | + puts "#{name.ljust(width)} #{(char*ready).green}#{(char*pending).yellow}#{(char*missing).red}" |
| 441 | + rescue => e |
| 442 | + puts "#{name.ljust(width)} #{e.red}" |
| 443 | + end |
| 444 | + end |
| 445 | + |
| 446 | + puts |
| 447 | + puts message.colorize(status['status']['ok'] ? :default : :red) |
| 448 | + end |
| 449 | + |
| 450 | + exit status['status']['ok'] |
422 | 451 | end
|
423 | 452 | end
|
424 | 453 |
|
|
0 commit comments