(#36) Update floaty modify command to work with multiple hosts

Prior to this commit, you could only modify 1 host at a time with the
floaty modify command. This commit updates that command to allow users
to modify either all known token vms, or vms passed in as a comma
separated list.
This commit is contained in:
Brian Cain 2016-11-12 14:25:08 -08:00
parent 586f4f5c05
commit 97e188cf6d

View file

@ -172,10 +172,43 @@ class Vmfloaty
token = options.token || config['token']
modify_all = options.all
if lifetime || tags
# All Vs
if modify_all
running_vms = nil
if modify_all
begin
running_vms = Utils.get_all_token_vms(verbose, url, token)
rescue Exception => e
STDERR.puts e
end
elsif hostname.include? ","
running_vms = hostname.split(",")
end
if lifetime || tags
# all vms
if !running_vms.nil?
begin
modify_hash = {}
modify_flag = true
running_vms.each do |vm|
modify_hash[vm] = Pooler.modify(verbose, url, vm, token, lifetime, tags)
end
modify_hash.each do |hostname,status|
if status == false
STDERR.puts "Could not modify #{hostname}."
modify_flag = false
end
end
if modify_flag
puts "Successfully modified all vms. Use `floaty list --active` to see the results."
end
rescue Exception => e
STDERR.puts e
exit 1
end
else
# Single Vm
begin
@ -196,21 +229,47 @@ class Vmfloaty
end
if disk
begin
disk_req = Pooler.disk(verbose, url, hostname, token, disk)
rescue TokenError => e
STDERR.puts e
exit 1
end
# all vms
if !running_vms.nil?
begin
modify_hash = {}
modify_flag = true
if disk_req["ok"]
puts "Successfully updated disk space of vm #{hostname}."
running_vms.each do |vm|
modify_hash[vm] = Pooler.disk(verbose, url, vm, token, disk)
end
modify_hash.each do |hostname,status|
if status == false
STDERR.puts "Could not update disk space on #{hostname}."
modify_flag = false
end
end
if modify_flag
puts "Successfully made request to update disk space on all vms."
end
rescue Exception => e
STDERR.puts e
exit 1
end
else
STDERR.puts "Could not modify given host #{hostname} at #{url}."
puts disk_req
exit 1
# single vm
begin
disk_req = Pooler.disk(verbose, url, hostname, token, disk)
rescue TokenError => e
STDERR.puts e
exit 1
end
if disk_req["ok"]
puts "Successfully made request to update disk space of vm #{hostname}."
else
STDERR.puts "Could not modify given host #{hostname} at #{url}."
puts disk_req
exit 1
end
end
else
end
end
end