Skip to content

Commit 97e188c

Browse files
committed
(#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.
1 parent 586f4f5 commit 97e188c

File tree

1 file changed

+73
-14
lines changed

1 file changed

+73
-14
lines changed

lib/vmfloaty.rb

+73-14
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,43 @@ def run
172172
token = options.token || config['token']
173173
modify_all = options.all
174174

175+
running_vms = nil
176+
177+
if modify_all
178+
begin
179+
running_vms = Utils.get_all_token_vms(verbose, url, token)
180+
rescue Exception => e
181+
STDERR.puts e
182+
end
183+
elsif hostname.include? ","
184+
running_vms = hostname.split(",")
185+
end
186+
175187
if lifetime || tags
176-
# All Vs
177-
if modify_all
188+
# all vms
189+
if !running_vms.nil?
190+
begin
191+
modify_hash = {}
192+
modify_flag = true
178193

194+
running_vms.each do |vm|
195+
modify_hash[vm] = Pooler.modify(verbose, url, vm, token, lifetime, tags)
196+
end
197+
198+
modify_hash.each do |hostname,status|
199+
if status == false
200+
STDERR.puts "Could not modify #{hostname}."
201+
modify_flag = false
202+
end
203+
end
204+
205+
if modify_flag
206+
puts "Successfully modified all vms. Use `floaty list --active` to see the results."
207+
end
208+
rescue Exception => e
209+
STDERR.puts e
210+
exit 1
211+
end
179212
else
180213
# Single Vm
181214
begin
@@ -196,21 +229,47 @@ def run
196229
end
197230

198231
if disk
199-
begin
200-
disk_req = Pooler.disk(verbose, url, hostname, token, disk)
201-
rescue TokenError => e
202-
STDERR.puts e
203-
exit 1
204-
end
232+
# all vms
233+
if !running_vms.nil?
234+
begin
235+
modify_hash = {}
236+
modify_flag = true
237+
238+
running_vms.each do |vm|
239+
modify_hash[vm] = Pooler.disk(verbose, url, vm, token, disk)
240+
end
241+
242+
modify_hash.each do |hostname,status|
243+
if status == false
244+
STDERR.puts "Could not update disk space on #{hostname}."
245+
modify_flag = false
246+
end
247+
end
205248

206-
if disk_req["ok"]
207-
puts "Successfully updated disk space of vm #{hostname}."
249+
if modify_flag
250+
puts "Successfully made request to update disk space on all vms."
251+
end
252+
rescue Exception => e
253+
STDERR.puts e
254+
exit 1
255+
end
208256
else
209-
STDERR.puts "Could not modify given host #{hostname} at #{url}."
210-
puts disk_req
211-
exit 1
257+
# single vm
258+
begin
259+
disk_req = Pooler.disk(verbose, url, hostname, token, disk)
260+
rescue TokenError => e
261+
STDERR.puts e
262+
exit 1
263+
end
264+
265+
if disk_req["ok"]
266+
puts "Successfully made request to update disk space of vm #{hostname}."
267+
else
268+
STDERR.puts "Could not modify given host #{hostname} at #{url}."
269+
puts disk_req
270+
exit 1
271+
end
212272
end
213-
else
214273
end
215274
end
216275
end

0 commit comments

Comments
 (0)