mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 13:28:42 -05:00
(#40) Require a --force flag when users request large pools
Prior to this commit, a user could easily steam roll vmpooler by accidentally adding an extra digit to their get request: $ floaty get centos=100 Accidentially hitting enter on this would completely drain a centos pool. This commit updates that bevaior to force users to use the --force flag if they really want to get more than 5 vms per template. 5 was choosen because most vm pools at Puppet were in the 5-10 range.
This commit is contained in:
parent
345300f58a
commit
c9b718b379
1 changed files with 10 additions and 0 deletions
|
|
@ -31,12 +31,14 @@ class Vmfloaty
|
||||||
c.option '--url STRING', String, 'URL of vmpooler'
|
c.option '--url STRING', String, 'URL of vmpooler'
|
||||||
c.option '--token STRING', String, 'Token for vmpooler'
|
c.option '--token STRING', String, 'Token for vmpooler'
|
||||||
c.option '--notoken', 'Makes a request without a token'
|
c.option '--notoken', 'Makes a request without a token'
|
||||||
|
c.option '--force', 'Forces vmfloaty to get requested vms'
|
||||||
c.action do |args, options|
|
c.action do |args, options|
|
||||||
verbose = options.verbose || config['verbose']
|
verbose = options.verbose || config['verbose']
|
||||||
token = options.token || config['token']
|
token = options.token || config['token']
|
||||||
user = options.user ||= config['user']
|
user = options.user ||= config['user']
|
||||||
url = options.url ||= config['url']
|
url = options.url ||= config['url']
|
||||||
no_token = options.notoken
|
no_token = options.notoken
|
||||||
|
force = options.force
|
||||||
|
|
||||||
if args.empty?
|
if args.empty?
|
||||||
STDERR.puts "No operating systems provided to obtain. See `floaty get --help` for more information on how to get VMs."
|
STDERR.puts "No operating systems provided to obtain. See `floaty get --help` for more information on how to get VMs."
|
||||||
|
|
@ -45,6 +47,14 @@ class Vmfloaty
|
||||||
|
|
||||||
os_types = Utils.generate_os_hash(args)
|
os_types = Utils.generate_os_hash(args)
|
||||||
|
|
||||||
|
max_pool_request = 5
|
||||||
|
large_pool_requests = os_types.select{|k,v| v > max_pool_request}
|
||||||
|
if ! large_pool_requests.nil? and ! force
|
||||||
|
STDERR.puts "Requesting vms over #{max_pool_request} requires a --force flag."
|
||||||
|
STDERR.puts "Try again with `floaty get --force`"
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
unless os_types.empty?
|
unless os_types.empty?
|
||||||
if no_token
|
if no_token
|
||||||
begin
|
begin
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue