From 12ee91df3eca8b06bb31e87f1ddd477e40225c8e Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 12 Nov 2014 22:26:31 -0800 Subject: [PATCH] Pretty print obtained hosts and add init host manager functions --- README.md | 2 -- lib/vmfloaty.rb | 2 +- lib/vmfloaty/cli.rb | 20 +++++++++++++++++--- lib/vmfloaty/hosts.rb | 26 +++++++++++++++++++++++++- 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ec79dff..74e49a5 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,6 @@ vmfloaty A CLI helper tool for Puppet Labs vmpooler to help you stay afloat. -_NOTE:_ Hack day(s?) project... we'll see where this goes :) - ## Install __note:__ this doesn't work yet. Have not published this to ruby gems diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index d531a7a..da12900 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -6,7 +6,7 @@ class Vmfloaty def initialize(env) $vmpooler_url = env['VMPOOLER_URL'] - unless @vmpooler_url + unless $vmpooler_url $vmpooler_url = 'http://vcloud.delivery.puppetlabs.net' end end diff --git a/lib/vmfloaty/cli.rb b/lib/vmfloaty/cli.rb index 4a4dd0b..5b41181 100644 --- a/lib/vmfloaty/cli.rb +++ b/lib/vmfloaty/cli.rb @@ -13,9 +13,23 @@ class CLI < Thor request = Net::HTTP::Post.new(uri.request_uri) response = http.request(request) - host_res = JSON.parse(response.body) + if response.code.to_i == 200 + hosts = JSON.parse(response.body) - puts host_res + # puts hosts + + save_hosts = {} + hosts.each do |k,v| + unless k == 'ok' || k == 'domain' + save_hosts[k] = v['hostname'] + end + end + + puts 'New Hosts:' + puts save_hosts + + #hosts.add_host save_hosts + end # parse host names/os's and save end @@ -27,7 +41,7 @@ class CLI < Thor desc "status", "List status of all active VMs" def status - say 'List of active VMs' + #$hosts.print_host_list end desc "list [PATTERN]", "List all open VMs" diff --git a/lib/vmfloaty/hosts.rb b/lib/vmfloaty/hosts.rb index 6e4f3f8..5ca90a5 100644 --- a/lib/vmfloaty/hosts.rb +++ b/lib/vmfloaty/hosts.rb @@ -1,5 +1,29 @@ # manage hosts used from vm pooler -class HOSTS +class Hosts def initialize + @host_list = {} + end + + def add_host(host_hash) + host_hash.each do |k,v| + if @host_list[k] + @host_list[k].push(v) + else + if v.is_a?(Array) + @host_list[k] = v + else + @host_list[k] = [v] + end + end + end + + puts @host_list + end + + def remove_host(host_id) + end + + def print_host_list + puts @host_list end end