From 13f5a282c7ae06dbb2cca3446f9bda9721897633 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Sun, 6 Sep 2015 11:35:42 -0700 Subject: [PATCH] (#1) Add summary command Right now it does not support timespans, and just does current day. --- README.md | 2 +- lib/vmfloaty.rb | 11 ++++++----- lib/vmfloaty/pooler.rb | 9 +++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fb4ef6c..b0f66a7 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ gem install vmfloaty revert snapshot status Prints the status of vmpooler - summary + summary Prints the summary of vmpooler GLOBAL OPTIONS: diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index 73743a6..621ba5b 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -17,7 +17,6 @@ class Vmfloaty config = read_config command :get do |c| - puts config c.syntax = 'floaty get [options]' c.summary = 'Gets a vm or vms based on the os flag' c.description = '' @@ -135,12 +134,14 @@ class Vmfloaty command :summary do |c| c.syntax = 'floaty summary [options]' - c.summary = '' + c.summary = 'Prints the summary of vmpooler' c.description = '' - c.example 'description', 'command example' - c.option '--some-switch', 'Some switch that does something' + c.example 'Gets the current day summary of vmpooler', 'floaty summary --url http://vmpooler.example.com' + c.option '--url STRING', String, 'URL of vmpooler' c.action do |args, options| - # Do something or c.when_called Floaty::Commands::Summary + url = options.url ||= config['url'] + + Pooler.summary(url) end end diff --git a/lib/vmfloaty/pooler.rb b/lib/vmfloaty/pooler.rb index 23a734c..b28f64f 100644 --- a/lib/vmfloaty/pooler.rb +++ b/lib/vmfloaty/pooler.rb @@ -62,5 +62,14 @@ class Pooler response = conn.get '/v1/status' res_body = JSON.parse(response.body) + puts res_body + end + + def self.summary(url) + conn = Http.get_conn(url) + + response = conn.get '/v1/summary' + res_body = JSON.parse(response.body) + puts res_body end end