mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 13:28:42 -05:00
(#11) Provide a way to delete all vms acquired by token
This commit adds a way for a user to delete all vms that were obtained by a specific token. It will ask the user if they are sure before deleting everything.
This commit is contained in:
parent
bc4cff5363
commit
a0ba604006
3 changed files with 34 additions and 3 deletions
|
|
@ -140,6 +140,7 @@ class Vmfloaty
|
|||
c.description = ''
|
||||
c.example 'Schedules the deletion of a host or hosts', 'floaty delete myhost1,myhost2 --url http://vmpooler.example.com'
|
||||
c.option '--verbose', 'Enables verbose output'
|
||||
c.option '--all', 'Deletes all vms acquired by a token'
|
||||
c.option '--token STRING', String, 'Token for vmpooler'
|
||||
c.option '--url STRING', String, 'URL of vmpooler'
|
||||
c.action do |args, options|
|
||||
|
|
@ -147,6 +148,36 @@ class Vmfloaty
|
|||
hostnames = args[0]
|
||||
token = options.token || config['token']
|
||||
url = options.url ||= config['url']
|
||||
delete_all = options.all
|
||||
|
||||
if delete_all
|
||||
# get vms with token
|
||||
status = Auth.token_status(verbose, url, token)
|
||||
# print vms
|
||||
vms = status[token]['vms']
|
||||
if vms.nil?
|
||||
STDERR.puts "You have no running vms"
|
||||
exit 0
|
||||
end
|
||||
|
||||
running_vms = vms['running']
|
||||
|
||||
if ! running_vms.nil?
|
||||
puts "Running VMs:"
|
||||
running_vms.each do |vm|
|
||||
puts "- #{vm}"
|
||||
end
|
||||
# query y/n
|
||||
puts ""
|
||||
ans = agree("Delete all VMs associated with token #{token}? [y/N]")
|
||||
if ans
|
||||
# delete vms
|
||||
Pooler.delete(verbose, url, running_vms, token)
|
||||
end
|
||||
end
|
||||
|
||||
exit 0
|
||||
end
|
||||
|
||||
if hostnames.nil?
|
||||
STDERR.puts "You did not provide any hosts to delete"
|
||||
|
|
@ -254,7 +285,7 @@ class Vmfloaty
|
|||
pass = password "Enter your password please:", '*'
|
||||
Auth.delete_token(verbose, url, user, pass, token)
|
||||
when "status"
|
||||
Auth.token_status(verbose, url, token)
|
||||
puts Auth.token_status(verbose, url, token)
|
||||
when nil
|
||||
STDERR.puts "No action provided"
|
||||
else
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class Auth
|
|||
res_body = JSON.parse(response.body)
|
||||
|
||||
if res_body["ok"]
|
||||
puts res_body
|
||||
res_body
|
||||
else
|
||||
STDERR.puts "There was a problem with your request:"
|
||||
puts res_body
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ describe Pooler do
|
|||
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Faraday v0.9.1'}).
|
||||
to_return(:status => 200, :body => @token_status_response, :headers => {})
|
||||
|
||||
expect(Auth.token_status(false, @vmpooler_url, @token)).to eq @get_token_response
|
||||
expect(Auth.token_status(false, @vmpooler_url, @token)).to eq JSON.parse(@token_status_response)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue