mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Wrap hostname-shortening into a [Sinatra helper] method
This commit is contained in:
parent
4035114152
commit
489abd713a
1 changed files with 13 additions and 9 deletions
|
|
@ -22,6 +22,16 @@ module Vmpooler
|
||||||
|
|
||||||
set :environment, 'production'
|
set :environment, 'production'
|
||||||
|
|
||||||
|
helpers do
|
||||||
|
def hostname_shorten hostname
|
||||||
|
if ( $config[:config]['domain'] and hostname =~ /^\w+\.#{$config[:config]['domain']}$/ )
|
||||||
|
hostname = hostname[/[^\.]+/]
|
||||||
|
end
|
||||||
|
|
||||||
|
hostname
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
get '/' do
|
get '/' do
|
||||||
erb :dashboard, locals: {
|
erb :dashboard, locals: {
|
||||||
site_name: $config[:config]['site_name'] || '<b>vmpooler</b>',
|
site_name: $config[:config]['site_name'] || '<b>vmpooler</b>',
|
||||||
|
|
@ -293,9 +303,7 @@ module Vmpooler
|
||||||
|
|
||||||
result['ok'] = false
|
result['ok'] = false
|
||||||
|
|
||||||
if ( $config[:config]['domain'] and params[:hostname] =~ /^\w+\.#{$config[:config]['domain']}$/ )
|
params[:hostname] = hostname_shorten(params[:hostname])
|
||||||
params[:hostname] = params[:hostname][/[^\.]+/]
|
|
||||||
end
|
|
||||||
|
|
||||||
if $redis.exists('vmpooler__vm__'+params[:hostname])
|
if $redis.exists('vmpooler__vm__'+params[:hostname])
|
||||||
result['ok'] = true
|
result['ok'] = true
|
||||||
|
|
@ -321,9 +329,7 @@ module Vmpooler
|
||||||
|
|
||||||
result['ok'] = false
|
result['ok'] = false
|
||||||
|
|
||||||
if ( $config[:config]['domain'] and params[:hostname] =~ /^\w+\.#{$config[:config]['domain']}$/ )
|
params[:hostname] = hostname_shorten(params[:hostname])
|
||||||
params[:hostname] = params[:hostname][/[^\.]+/]
|
|
||||||
end
|
|
||||||
|
|
||||||
$config[:pools].each do |pool|
|
$config[:pools].each do |pool|
|
||||||
if $redis.sismember('vmpooler__running__'+pool['name'], params[:hostname])
|
if $redis.sismember('vmpooler__running__'+pool['name'], params[:hostname])
|
||||||
|
|
@ -343,9 +349,7 @@ module Vmpooler
|
||||||
|
|
||||||
result['ok'] = false
|
result['ok'] = false
|
||||||
|
|
||||||
if ( $config[:config]['domain'] and params[:hostname] =~ /^\w+\.#{$config[:config]['domain']}$/ )
|
params[:hostname] = hostname_shorten(params[:hostname])
|
||||||
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