Pretty print obtained hosts and add init host manager functions

This commit is contained in:
Brian Cain 2014-11-12 22:26:31 -08:00
parent f40291706a
commit 12ee91df3e
4 changed files with 43 additions and 7 deletions

View file

@ -3,8 +3,6 @@ vmfloaty
A CLI helper tool for Puppet Labs vmpooler to help you stay afloat. 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 ## Install
__note:__ this doesn't work yet. Have not published this to ruby gems __note:__ this doesn't work yet. Have not published this to ruby gems

View file

@ -6,7 +6,7 @@ class Vmfloaty
def initialize(env) def initialize(env)
$vmpooler_url = env['VMPOOLER_URL'] $vmpooler_url = env['VMPOOLER_URL']
unless @vmpooler_url unless $vmpooler_url
$vmpooler_url = 'http://vcloud.delivery.puppetlabs.net' $vmpooler_url = 'http://vcloud.delivery.puppetlabs.net'
end end
end end

View file

@ -13,9 +13,23 @@ class CLI < Thor
request = Net::HTTP::Post.new(uri.request_uri) request = Net::HTTP::Post.new(uri.request_uri)
response = http.request(request) 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 # parse host names/os's and save
end end
@ -27,7 +41,7 @@ class CLI < Thor
desc "status", "List status of all active VMs" desc "status", "List status of all active VMs"
def status def status
say 'List of active VMs' #$hosts.print_host_list
end end
desc "list [PATTERN]", "List all open VMs" desc "list [PATTERN]", "List all open VMs"

View file

@ -1,5 +1,29 @@
# manage hosts used from vm pooler # manage hosts used from vm pooler
class HOSTS class Hosts
def initialize 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
end end