From c9b718b3790abeb997678483f98ffbac9cbe72de Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Thu, 8 Dec 2016 21:26:14 -0800 Subject: [PATCH] (#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. --- lib/vmfloaty.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/vmfloaty.rb b/lib/vmfloaty.rb index 2825a26..5e0621c 100644 --- a/lib/vmfloaty.rb +++ b/lib/vmfloaty.rb @@ -31,12 +31,14 @@ class Vmfloaty c.option '--url STRING', String, 'URL of vmpooler' c.option '--token STRING', String, 'Token for vmpooler' c.option '--notoken', 'Makes a request without a token' + c.option '--force', 'Forces vmfloaty to get requested vms' c.action do |args, options| verbose = options.verbose || config['verbose'] token = options.token || config['token'] user = options.user ||= config['user'] url = options.url ||= config['url'] no_token = options.notoken + force = options.force if args.empty? 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) + 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? if no_token begin