Skip to content

Commit 7ee7308

Browse files
committed
Show the status of pools with floaty status
Previously, `floaty status` would simply pretty-print the JSON output of the status request to the pooler. That data requires additional parsing, either human or machine, in order to be able to deduce any meaningful information about the state of the pooler. This commit updates `floaty status` to visually represent the state of pools, indicating which pools have nodes missing or being built. It also prints the status summary message returned by the pooler, providing an easy way to tell if everything is okay. By default, this command will only show the state of pools that aren't full. If `--verbose` is passed, it will show all pools. If the complete status information provided by the API is desired, the `--json` option will print the raw JSON output, preserving the previous functionality. This also updates the status command to exit non-zero if the status is not ok.
1 parent a6ff051 commit 7ee7308

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ source 'https://rubygems.org'
22

33
gem 'commander'
44
gem 'faraday', '0.9.2'
5+
gem 'colorize', '~> 0.8'
56

67
gem 'rspec'
78
gem 'webmock', '1.21.0'

lib/vmfloaty.rb

+30-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
require 'rubygems'
44
require 'commander'
5+
require 'colorize'
6+
require 'json'
57
require 'pp'
68
require 'vmfloaty/auth'
79
require 'vmfloaty/pooler'
@@ -413,12 +415,39 @@ def run
413415
c.example 'Gets the current vmpooler status', 'floaty status --url http://vmpooler.example.com'
414416
c.option '--verbose', 'Enables verbose output'
415417
c.option '--url STRING', String, 'URL of vmpooler'
418+
c.option '--json', 'Prints status in JSON format'
416419
c.action do |args, options|
417420
verbose = options.verbose || config['verbose']
418421
url = options.url ||= config['url']
419422

420423
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']
422451
end
423452
end
424453

0 commit comments

Comments
 (0)