mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 13:28:42 -05:00
(#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:
parent
586f4f5c05
commit
97e188cf6d
1 changed files with 74 additions and 15 deletions
|
|
@ -172,10 +172,43 @@ class Vmfloaty
|
||||||
token = options.token || config['token']
|
token = options.token || config['token']
|
||||||
modify_all = options.all
|
modify_all = options.all
|
||||||
|
|
||||||
if lifetime || tags
|
running_vms = nil
|
||||||
# All Vs
|
|
||||||
if modify_all
|
|
||||||
|
|
||||||
|
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
|
else
|
||||||
# Single Vm
|
# Single Vm
|
||||||
begin
|
begin
|
||||||
|
|
@ -196,6 +229,32 @@ class Vmfloaty
|
||||||
end
|
end
|
||||||
|
|
||||||
if disk
|
if disk
|
||||||
|
# all vms
|
||||||
|
if !running_vms.nil?
|
||||||
|
begin
|
||||||
|
modify_hash = {}
|
||||||
|
modify_flag = true
|
||||||
|
|
||||||
|
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
|
||||||
|
# single vm
|
||||||
begin
|
begin
|
||||||
disk_req = Pooler.disk(verbose, url, hostname, token, disk)
|
disk_req = Pooler.disk(verbose, url, hostname, token, disk)
|
||||||
rescue TokenError => e
|
rescue TokenError => e
|
||||||
|
|
@ -204,13 +263,13 @@ class Vmfloaty
|
||||||
end
|
end
|
||||||
|
|
||||||
if disk_req["ok"]
|
if disk_req["ok"]
|
||||||
puts "Successfully updated disk space of vm #{hostname}."
|
puts "Successfully made request to update disk space of vm #{hostname}."
|
||||||
else
|
else
|
||||||
STDERR.puts "Could not modify given host #{hostname} at #{url}."
|
STDERR.puts "Could not modify given host #{hostname} at #{url}."
|
||||||
puts disk_req
|
puts disk_req
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
else
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue