mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-27 02:18:41 -05:00
(maint) Fix rubocop violations
This commit fixes minor rubocopy violations in eleven source files. Minor violations are those that include formatting, single quotes, and recently added classes.
This commit is contained in:
parent
42b7d2d222
commit
06100ddea6
11 changed files with 204 additions and 210 deletions
|
|
@ -1,146 +1,143 @@
|
|||
module Vmpooler
|
||||
class API
|
||||
class Dashboard < Sinatra::Base
|
||||
|
||||
# handle to the App's configuration information
|
||||
def config
|
||||
@config ||= Vmpooler::API.settings.config
|
||||
end
|
||||
|
||||
# configuration setting for server hosting graph URLs to view
|
||||
def graph_server
|
||||
return @graph_server if @graph_server
|
||||
|
||||
if config[:graphs]
|
||||
return false unless config[:graphs]['server']
|
||||
@graph_server = config[:graphs]['server']
|
||||
elsif config[:graphite]
|
||||
return false unless config[:graphite]['server']
|
||||
@graph_server = config[:graphite]['server']
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
# configuration setting for URL prefix for graphs to view
|
||||
def graph_prefix
|
||||
return @graph_prefix if @graph_prefix
|
||||
|
||||
if config[:graphs]
|
||||
return "vmpooler" unless config[:graphs]['prefix']
|
||||
@graph_prefix = config[:graphs]['prefix']
|
||||
elsif config[:graphite]
|
||||
return false unless config[:graphite]['prefix']
|
||||
@graph_prefix = config[:graphite]['prefix']
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
# what is the base URL for viewable graphs?
|
||||
def graph_url
|
||||
return false unless graph_server && graph_prefix
|
||||
@graph_url ||= "http://#{graph_server}/render?target=#{graph_prefix}"
|
||||
end
|
||||
|
||||
# return a full URL to a viewable graph for a given metrics target (graphite syntax)
|
||||
def graph_link(target = "")
|
||||
return "" unless graph_url
|
||||
graph_url + target
|
||||
end
|
||||
|
||||
|
||||
get '/dashboard/stats/vmpooler/pool/?' do
|
||||
content_type :json
|
||||
result = {}
|
||||
|
||||
Vmpooler::API.settings.config[:pools].each do |pool|
|
||||
result[pool['name']] ||= {}
|
||||
result[pool['name']]['size'] = pool['size']
|
||||
result[pool['name']]['ready'] = Vmpooler::API.settings.redis.scard('vmpooler__ready__' + pool['name'])
|
||||
class Dashboard < Sinatra::Base
|
||||
# handle to the App's configuration information
|
||||
def config
|
||||
@config ||= Vmpooler::API.settings.config
|
||||
end
|
||||
|
||||
if params[:history]
|
||||
if graph_url
|
||||
history ||= {}
|
||||
# configuration setting for server hosting graph URLs to view
|
||||
def graph_server
|
||||
return @graph_server if @graph_server
|
||||
|
||||
begin
|
||||
buffer = open(graph_link('.ready.*&from=-1hour&format=json')).read
|
||||
history = JSON.parse(buffer)
|
||||
if config[:graphs]
|
||||
return false unless config[:graphs]['server']
|
||||
@graph_server = config[:graphs]['server']
|
||||
elsif config[:graphite]
|
||||
return false unless config[:graphite]['server']
|
||||
@graph_server = config[:graphite]['server']
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
history.each do |pool|
|
||||
if pool['target'] =~ /.*\.(.*)$/
|
||||
pool['name'] = Regexp.last_match[1]
|
||||
# configuration setting for URL prefix for graphs to view
|
||||
def graph_prefix
|
||||
return @graph_prefix if @graph_prefix
|
||||
|
||||
if result[pool['name']]
|
||||
pool['last'] = result[pool['name']]['size']
|
||||
result[pool['name']]['history'] ||= Array.new
|
||||
if config[:graphs]
|
||||
return 'vmpooler' unless config[:graphs]['prefix']
|
||||
@graph_prefix = config[:graphs]['prefix']
|
||||
elsif config[:graphite]
|
||||
return false unless config[:graphite]['prefix']
|
||||
@graph_prefix = config[:graphite]['prefix']
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
pool['datapoints'].each do |metric|
|
||||
8.times do |_n|
|
||||
if metric[0]
|
||||
pool['last'] = metric[0].to_i
|
||||
result[pool['name']]['history'].push(metric[0].to_i)
|
||||
else
|
||||
result[pool['name']]['history'].push(pool['last'])
|
||||
# what is the base URL for viewable graphs?
|
||||
def graph_url
|
||||
return false unless graph_server && graph_prefix
|
||||
@graph_url ||= "http://#{graph_server}/render?target=#{graph_prefix}"
|
||||
end
|
||||
|
||||
# return a full URL to a viewable graph for a given metrics target (graphite syntax)
|
||||
def graph_link(target = '')
|
||||
return '' unless graph_url
|
||||
graph_url + target
|
||||
end
|
||||
|
||||
|
||||
get '/dashboard/stats/vmpooler/pool/?' do
|
||||
content_type :json
|
||||
result = {}
|
||||
|
||||
Vmpooler::API.settings.config[:pools].each do |pool|
|
||||
result[pool['name']] ||= {}
|
||||
result[pool['name']]['size'] = pool['size']
|
||||
result[pool['name']]['ready'] = Vmpooler::API.settings.redis.scard('vmpooler__ready__' + pool['name'])
|
||||
end
|
||||
|
||||
if params[:history]
|
||||
if graph_url
|
||||
history ||= {}
|
||||
|
||||
begin
|
||||
buffer = open(graph_link('.ready.*&from=-1hour&format=json')).read
|
||||
history = JSON.parse(buffer)
|
||||
|
||||
history.each do |pool|
|
||||
if pool['target'] =~ /.*\.(.*)$/
|
||||
pool['name'] = Regexp.last_match[1]
|
||||
|
||||
if result[pool['name']]
|
||||
pool['last'] = result[pool['name']]['size']
|
||||
result[pool['name']]['history'] ||= []
|
||||
|
||||
pool['datapoints'].each do |metric|
|
||||
8.times do |_n|
|
||||
if metric[0]
|
||||
pool['last'] = metric[0].to_i
|
||||
result[pool['name']]['history'].push(metric[0].to_i)
|
||||
else
|
||||
result[pool['name']]['history'].push(pool['last'])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue
|
||||
end
|
||||
else
|
||||
Vmpooler::API.settings.config[:pools].each do |pool|
|
||||
result[pool['name']] ||= {}
|
||||
result[pool['name']]['history'] = [Vmpooler::API.settings.redis.scard('vmpooler__ready__' + pool['name'])]
|
||||
end
|
||||
rescue
|
||||
end
|
||||
else
|
||||
Vmpooler::API.settings.config[:pools].each do |pool|
|
||||
result[pool['name']] ||= {}
|
||||
result[pool['name']]['history'] = [Vmpooler::API.settings.redis.scard('vmpooler__ready__' + pool['name'])]
|
||||
end
|
||||
end
|
||||
end
|
||||
JSON.pretty_generate(result)
|
||||
end
|
||||
|
||||
get '/dashboard/stats/vmpooler/running/?' do
|
||||
content_type :json
|
||||
result = {}
|
||||
|
||||
Vmpooler::API.settings.config[:pools].each do |pool|
|
||||
running = Vmpooler::API.settings.redis.scard('vmpooler__running__' + pool['name'])
|
||||
pool['major'] = Regexp.last_match[1] if pool['name'] =~ /^(\w+)\-/
|
||||
result[pool['major']] ||= {}
|
||||
result[pool['major']]['running'] = result[pool['major']]['running'].to_i + running.to_i
|
||||
JSON.pretty_generate(result)
|
||||
end
|
||||
|
||||
if params[:history]
|
||||
if graph_url
|
||||
begin
|
||||
buffer = open(graph_link('.running.*&from=-1hour&format=json')).read
|
||||
JSON.parse(buffer).each do |pool|
|
||||
if pool['target'] =~ /.*\.(.*)$/
|
||||
pool['name'] = Regexp.last_match[1]
|
||||
pool['major'] = Regexp.last_match[1] if pool['name'] =~ /^(\w+)\-/
|
||||
result[pool['major']]['history'] ||= Array.new
|
||||
get '/dashboard/stats/vmpooler/running/?' do
|
||||
content_type :json
|
||||
result = {}
|
||||
|
||||
for i in 0..pool['datapoints'].length
|
||||
if
|
||||
pool['datapoints'][i] &&
|
||||
pool['datapoints'][i][0]
|
||||
pool['last'] = pool['datapoints'][i][0]
|
||||
result[pool['major']]['history'][i] ||= 0
|
||||
result[pool['major']]['history'][i] = result[pool['major']]['history'][i].to_i + pool['datapoints'][i][0].to_i
|
||||
else
|
||||
result[pool['major']]['history'][i] = result[pool['major']]['history'][i].to_i + pool['last'].to_i
|
||||
Vmpooler::API.settings.config[:pools].each do |pool|
|
||||
running = Vmpooler::API.settings.redis.scard('vmpooler__running__' + pool['name'])
|
||||
pool['major'] = Regexp.last_match[1] if pool['name'] =~ /^(\w+)\-/
|
||||
result[pool['major']] ||= {}
|
||||
result[pool['major']]['running'] = result[pool['major']]['running'].to_i + running.to_i
|
||||
end
|
||||
|
||||
if params[:history]
|
||||
if graph_url
|
||||
begin
|
||||
buffer = open(graph_link('.running.*&from=-1hour&format=json')).read
|
||||
JSON.parse(buffer).each do |pool|
|
||||
if pool['target'] =~ /.*\.(.*)$/
|
||||
pool['name'] = Regexp.last_match[1]
|
||||
pool['major'] = Regexp.last_match[1] if pool['name'] =~ /^(\w+)\-/
|
||||
result[pool['major']]['history'] ||= []
|
||||
|
||||
for i in 0..pool['datapoints'].length
|
||||
if pool['datapoints'][i] && pool['datapoints'][i][0]
|
||||
pool['last'] = pool['datapoints'][i][0]
|
||||
result[pool['major']]['history'][i] ||= 0
|
||||
result[pool['major']]['history'][i] = result[pool['major']]['history'][i].to_i + pool['datapoints'][i][0].to_i
|
||||
else
|
||||
result[pool['major']]['history'][i] = result[pool['major']]['history'][i].to_i + pool['last'].to_i
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue
|
||||
end
|
||||
rescue
|
||||
end
|
||||
end
|
||||
JSON.pretty_generate(result)
|
||||
end
|
||||
JSON.pretty_generate(result)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,71 +1,71 @@
|
|||
module Vmpooler
|
||||
class API
|
||||
class Reroute < Sinatra::Base
|
||||
api_version = '1'
|
||||
class Reroute < Sinatra::Base
|
||||
api_version = '1'
|
||||
|
||||
get '/status/?' do
|
||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/status")
|
||||
end
|
||||
get '/status/?' do
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/status")
|
||||
end
|
||||
|
||||
get '/summary/?' do
|
||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/summary")
|
||||
end
|
||||
get '/summary/?' do
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/summary")
|
||||
end
|
||||
|
||||
get '/summary/:route/?:key?/?' do
|
||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/summary/#{params[:route]}/#{params[:key]}")
|
||||
end
|
||||
get '/summary/:route/?:key?/?' do
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/summary/#{params[:route]}/#{params[:key]}")
|
||||
end
|
||||
|
||||
get '/token/?' do
|
||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/token")
|
||||
end
|
||||
get '/token/?' do
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/token")
|
||||
end
|
||||
|
||||
post '/token/?' do
|
||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/token")
|
||||
end
|
||||
post '/token/?' do
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/token")
|
||||
end
|
||||
|
||||
get '/token/:token/?' do
|
||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/token/#{params[:token]}")
|
||||
end
|
||||
get '/token/:token/?' do
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/token/#{params[:token]}")
|
||||
end
|
||||
|
||||
delete '/token/:token/?' do
|
||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/token/#{params[:token]}")
|
||||
end
|
||||
delete '/token/:token/?' do
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/token/#{params[:token]}")
|
||||
end
|
||||
|
||||
get '/vm/?' do
|
||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/vm")
|
||||
end
|
||||
get '/vm/?' do
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm")
|
||||
end
|
||||
|
||||
post '/vm/?' do
|
||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/vm")
|
||||
end
|
||||
post '/vm/?' do
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm")
|
||||
end
|
||||
|
||||
post '/vm/:template/?' do
|
||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/vm/#{params[:template]}")
|
||||
end
|
||||
post '/vm/:template/?' do
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm/#{params[:template]}")
|
||||
end
|
||||
|
||||
get '/vm/:hostname/?' do
|
||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/vm/#{params[:hostname]}")
|
||||
end
|
||||
get '/vm/:hostname/?' do
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm/#{params[:hostname]}")
|
||||
end
|
||||
|
||||
delete '/vm/:hostname/?' do
|
||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/vm/#{params[:hostname]}")
|
||||
end
|
||||
delete '/vm/:hostname/?' do
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm/#{params[:hostname]}")
|
||||
end
|
||||
|
||||
put '/vm/:hostname/?' do
|
||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/vm/#{params[:hostname]}")
|
||||
end
|
||||
put '/vm/:hostname/?' do
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm/#{params[:hostname]}")
|
||||
end
|
||||
|
||||
post '/vm/:hostname/snapshot/?' do
|
||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/vm/#{params[:hostname]}/snapshot")
|
||||
end
|
||||
post '/vm/:hostname/snapshot/?' do
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm/#{params[:hostname]}/snapshot")
|
||||
end
|
||||
|
||||
post '/vm/:hostname/snapshot/:snapshot/?' do
|
||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/vm/#{params[:hostname]}/snapshot/#{params[:snapshot]}")
|
||||
end
|
||||
post '/vm/:hostname/snapshot/:snapshot/?' do
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm/#{params[:hostname]}/snapshot/#{params[:snapshot]}")
|
||||
end
|
||||
|
||||
put '/vm/:hostname/disk/:size/?' do
|
||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/vm/#{params[:hostname]}/disk/#{params[:size]}")
|
||||
put '/vm/:hostname/disk/:size/?' do
|
||||
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm/#{params[:hostname]}/disk/#{params[:size]}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue