Merge pull request #38 from nicklewis/improved-status-command

Show the status of pools with `floaty status`
This commit is contained in:
Brian Cain 2016-12-05 08:42:21 -08:00 committed by GitHub
commit 5cfac377ee
2 changed files with 31 additions and 1 deletions

View file

@ -2,6 +2,7 @@ source 'https://rubygems.org'
gem 'commander'
gem 'faraday', '0.9.2'
gem 'colorize', '~> 0.8'
gem 'rspec'
gem 'webmock', '1.21.0'

View file

@ -2,6 +2,8 @@
require 'rubygems'
require 'commander'
require 'colorize'
require 'json'
require 'pp'
require 'vmfloaty/auth'
require 'vmfloaty/pooler'
@ -413,12 +415,39 @@ class Vmfloaty
c.example 'Gets the current vmpooler status', 'floaty status --url http://vmpooler.example.com'
c.option '--verbose', 'Enables verbose output'
c.option '--url STRING', String, 'URL of vmpooler'
c.option '--json', 'Prints status in JSON format'
c.action do |args, options|
verbose = options.verbose || config['verbose']
url = options.url ||= config['url']
status = Pooler.status(verbose, url)
message = status['status']['message']
pools = status['pools']
if options.json
pp status
else
pools.select! {|name,pool| pool['ready'] < pool['max']} if ! verbose
width = pools.keys.map(&:length).max
pools.each do |name,pool|
begin
max = pool['max']
ready = pool['ready']
pending = pool['pending']
missing = max - ready - pending
char = 'o'
puts "#{name.ljust(width)} #{(char*ready).green}#{(char*pending).yellow}#{(char*missing).red}"
rescue => e
puts "#{name.ljust(width)} #{e.red}"
end
end
puts
puts message.colorize(status['status']['ok'] ? :default : :red)
end
exit status['status']['ok']
end
end