mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 13:28:42 -05:00
Cleanup vmfloaty library and command line functions
This commit is contained in:
parent
c1689da3c4
commit
c6cf86669a
5 changed files with 87 additions and 67 deletions
50
lib/vmfloaty/utils.rb
Normal file
50
lib/vmfloaty/utils.rb
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue