mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 05:28:40 -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
|
|
@ -1,19 +0,0 @@
|
|||
|
||||
class Format
|
||||
# TODO: Takes the json response body from an HTTP GET
|
||||
# request and "pretty prints" it
|
||||
def self.get_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
|
||||
end
|
||||
|
|
@ -34,8 +34,7 @@ class Pooler
|
|||
os_string = os_string.chomp("+")
|
||||
|
||||
if os_string.size == 0
|
||||
STDERR.puts "No request was made, os hash specified no vms #{os_type}"
|
||||
exit 1
|
||||
raise "No operating systems provided to obtain. See `floaty get --help` for more information on how to get VMs."
|
||||
end
|
||||
|
||||
response = conn.post "/vm/#{os_string}"
|
||||
|
|
@ -44,9 +43,7 @@ class Pooler
|
|||
if res_body["ok"]
|
||||
res_body
|
||||
else
|
||||
STDERR.puts "There was a problem with your request"
|
||||
STDERR.puts res_body
|
||||
exit 1
|
||||
raise "Failed to obtain VMs from the pooler at #{url}/vm/#{os_string}. #{res_body}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -85,7 +82,8 @@ class Pooler
|
|||
if res_body['ok']
|
||||
puts "Deletion for vm #{host} successfully scheduled"
|
||||
else
|
||||
STDERR.puts "There was a problem with your request for vm #{host}"
|
||||
STDERR.puts "There was a problem with your request for vm #{host}."
|
||||
STDERR.puts res_body
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
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