mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
(MAINT) Reduce redis Calls in API
The return values from most redis calls inform the caller of whether a key or hash value exists. Several exists() calls can be removed in favor of this approach. Updated spec tests to account for a removal of exists() and ismember() calls in API tests.
This commit is contained in:
parent
5789d2c708
commit
acb95d34c8
2 changed files with 10 additions and 24 deletions
|
|
@ -385,12 +385,11 @@ module Vmpooler
|
|||
|
||||
params[:hostname] = hostname_shorten(params[:hostname], config['domain'])
|
||||
|
||||
if backend.exists('vmpooler__vm__' + params[:hostname])
|
||||
rdata = backend.hgetall('vmpooler__vm__' + params[:hostname])
|
||||
unless rdata.empty?
|
||||
status 200
|
||||
result['ok'] = true
|
||||
|
||||
rdata = backend.hgetall('vmpooler__vm__' + params[:hostname])
|
||||
|
||||
result[params[:hostname]] = {}
|
||||
|
||||
result[params[:hostname]]['template'] = rdata['template']
|
||||
|
|
@ -438,13 +437,11 @@ module Vmpooler
|
|||
|
||||
params[:hostname] = hostname_shorten(params[:hostname], config['domain'])
|
||||
|
||||
if backend.exists('vmpooler__vm__' + params[:hostname])
|
||||
rdata = backend.hgetall('vmpooler__vm__' + params[:hostname])
|
||||
|
||||
rdata = backend.hgetall('vmpooler__vm__' + params[:hostname])
|
||||
unless rdata.empty?
|
||||
need_token! if rdata['token:token']
|
||||
|
||||
if backend.sismember('vmpooler__running__' + rdata['template'], params[:hostname])
|
||||
backend.srem('vmpooler__running__' + rdata['template'], params[:hostname])
|
||||
if backend.srem('vmpooler__running__' + rdata['template'], params[:hostname])
|
||||
backend.sadd('vmpooler__completed__' + rdata['template'], params[:hostname])
|
||||
|
||||
status 200
|
||||
|
|
@ -554,7 +551,7 @@ module Vmpooler
|
|||
|
||||
params[:hostname] = hostname_shorten(params[:hostname], config['domain'])
|
||||
|
||||
if backend.exists('vmpooler__vm__' + params[:hostname]) and backend.hget('vmpooler__vm__' + params[:hostname], 'snapshot:' + params[:snapshot])
|
||||
unless backend.hget('vmpooler__vm__' + params[:hostname], 'snapshot:' + params[:snapshot]).to_i.zero?
|
||||
backend.sadd('vmpooler__tasks__snapshot-revert', params[:hostname] + ':' + params[:snapshot])
|
||||
|
||||
status 202
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue