Cleanup vmfloaty library and command line functions

This commit is contained in:
Brian Cain 2015-11-15 14:24:24 -08:00
parent c1689da3c4
commit c6cf86669a
5 changed files with 87 additions and 67 deletions

50
lib/vmfloaty/utils.rb Normal file
View file

@ -0,0 +1,50 @@
require 'vmfloaty/pooler'
class Utils
# TODO: Takes the json response body from an HTTP GET
# request and "pretty prints" it
def self.format_hosts(hostname_hash)
host_hash = {}
hostname_hash.delete("ok")
hostname_hash.each do |type, hosts|
if type == "domain"
host_hash[type] = hosts
else
host_hash[type] = hosts["hostname"]
end
end
host_hash.to_json
end
def self.generate_os_hash(os_args)
# expects args to look like:
# ["centos", "debian=5", "windows=1"]
# Build vm hash where
#
# [operating_system_type1 -> total,
# operating_system_type2 -> total,
# ...]
os_types = {}
os_args.each do |arg|
os_arr = arg.split("=")
if os_arr.size == 1
# assume they didn't specify an = sign if split returns 1 size
os_types[os_arr[0]] = 1
else
os_types[os_arr[0]] = os_arr[1].to_i
end
end
os_types
end
def self.prettyprint_hosts(hosts)
puts "Running VMs:"
running_vms.each do |vm|
puts "- #{vm}"
end
end
end