mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-27 02:18:41 -05:00
(POOLER-153) Add endpoint for resetting a pool
This commit adds a capability to vmpooler to reset a pool, deleting its ready and pending instances and replacing them with fresh ones. Without this change vmpooler does not offer a mechanism to reset a pool without also changing its template.
This commit is contained in:
parent
3732ed750e
commit
52b60b074c
5 changed files with 237 additions and 1 deletions
|
|
@ -200,6 +200,17 @@ module Vmpooler
|
|||
result
|
||||
end
|
||||
|
||||
def reset_pool(payload)
|
||||
result = { 'ok' => false }
|
||||
|
||||
payload.each do |poolname, count|
|
||||
backend.sadd('vmpooler__poolreset', poolname)
|
||||
end
|
||||
status 201
|
||||
result['ok'] = true
|
||||
result
|
||||
end
|
||||
|
||||
def update_clone_target(payload)
|
||||
result = { 'ok' => false }
|
||||
|
||||
|
|
@ -1063,6 +1074,44 @@ module Vmpooler
|
|||
JSON.pretty_generate(result)
|
||||
end
|
||||
|
||||
post "#{api_prefix}/poolreset/?" do
|
||||
content_type :json
|
||||
result = { 'ok' => false }
|
||||
|
||||
if config['experimental_features']
|
||||
need_token! if Vmpooler::API.settings.config[:auth]
|
||||
|
||||
begin
|
||||
payload = JSON.parse(request.body.read)
|
||||
if payload
|
||||
invalid = invalid_templates(payload)
|
||||
if invalid.empty?
|
||||
result = reset_pool(payload)
|
||||
else
|
||||
invalid.each do |bad_pool|
|
||||
metrics.increment("poolreset.invalid.#{bad_pool}")
|
||||
end
|
||||
result[:bad_pools] = invalid
|
||||
status 400
|
||||
end
|
||||
else
|
||||
metrics.increment('poolreset.invalid.unknown')
|
||||
status 404
|
||||
end
|
||||
rescue JSON::ParserError
|
||||
status 400
|
||||
result = {
|
||||
'ok' => false,
|
||||
'message' => 'JSON payload could not be parsed'
|
||||
}
|
||||
end
|
||||
else
|
||||
status 405
|
||||
end
|
||||
|
||||
JSON.pretty_generate(result)
|
||||
end
|
||||
|
||||
post "#{api_prefix}/config/clonetarget/?" do
|
||||
content_type :json
|
||||
result = { 'ok' => false }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue