mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Allow VM metadata to be queryable via 'GET'
This commit is contained in:
parent
4363d8e067
commit
4035114152
1 changed files with 32 additions and 10 deletions
|
|
@ -228,16 +228,6 @@ module Vmpooler
|
||||||
JSON.pretty_generate(result)
|
JSON.pretty_generate(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/vm/:template/?' do
|
|
||||||
content_type :json
|
|
||||||
|
|
||||||
result = {}
|
|
||||||
result[params[:template]] = {}
|
|
||||||
result[params[:template]]['hosts'] = $redis.smembers('vmpooler__ready__'+params[:template])
|
|
||||||
|
|
||||||
JSON.pretty_generate(result)
|
|
||||||
end
|
|
||||||
|
|
||||||
post '/vm/:template/?' do
|
post '/vm/:template/?' do
|
||||||
content_type :json
|
content_type :json
|
||||||
|
|
||||||
|
|
@ -296,6 +286,34 @@ module Vmpooler
|
||||||
JSON.pretty_generate(result)
|
JSON.pretty_generate(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get '/vm/:hostname/?' do
|
||||||
|
content_type :json
|
||||||
|
|
||||||
|
result = {}
|
||||||
|
|
||||||
|
result['ok'] = false
|
||||||
|
|
||||||
|
if ( $config[:config]['domain'] and params[:hostname] =~ /^\w+\.#{$config[:config]['domain']}$/ )
|
||||||
|
params[:hostname] = params[:hostname][/[^\.]+/]
|
||||||
|
end
|
||||||
|
|
||||||
|
if $redis.exists('vmpooler__vm__'+params[:hostname])
|
||||||
|
result['ok'] = true
|
||||||
|
|
||||||
|
result[params[:hostname]] = {}
|
||||||
|
|
||||||
|
result[params[:hostname]]['template'] = $redis.hget('vmpooler__vm__'+params[:hostname], 'template')
|
||||||
|
result[params[:hostname]]['lifetime'] = $redis.hget('vmpooler__vm__'+params[:hostname], 'lifetime') || $config[:config]['vm_lifetime']
|
||||||
|
result[params[:hostname]]['running'] = ((Time.now - Time.parse($redis.hget('vmpooler__active__'+result[params[:hostname]]['template'], params[:hostname])))/60/60).round(2)
|
||||||
|
|
||||||
|
if ( $config[:config]['domain'] )
|
||||||
|
result[params[:hostname]]['domain'] = $config[:config]['domain']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
JSON.pretty_generate(result)
|
||||||
|
end
|
||||||
|
|
||||||
delete '/vm/:hostname/?' do
|
delete '/vm/:hostname/?' do
|
||||||
content_type :json
|
content_type :json
|
||||||
|
|
||||||
|
|
@ -325,6 +343,10 @@ module Vmpooler
|
||||||
|
|
||||||
result['ok'] = false
|
result['ok'] = false
|
||||||
|
|
||||||
|
if ( $config[:config]['domain'] and params[:hostname] =~ /^\w+\.#{$config[:config]['domain']}$/ )
|
||||||
|
params[:hostname] = params[:hostname][/[^\.]+/]
|
||||||
|
end
|
||||||
|
|
||||||
if $redis.exists('vmpooler__vm__'+params[:hostname])
|
if $redis.exists('vmpooler__vm__'+params[:hostname])
|
||||||
jdata = JSON.parse(request.body.read)
|
jdata = JSON.parse(request.body.read)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue