mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Merge pull request #208 from glennsarti/maint-rubocop
(maint) Fix rubocop violations
This commit is contained in:
commit
d4a50e5e56
13 changed files with 219 additions and 254 deletions
|
|
@ -17,6 +17,9 @@ Style/Documentation:
|
||||||
Metrics/LineLength:
|
Metrics/LineLength:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
|
# Empty method definitions over more than one line is ok
|
||||||
|
Style/EmptyMethod:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
# Due to legacy codebase
|
# Due to legacy codebase
|
||||||
# - Globals are used liberally
|
# - Globals are used liberally
|
||||||
|
|
@ -29,6 +32,8 @@ Metrics/PerceivedComplexity:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
Metrics/CyclomaticComplexity:
|
Metrics/CyclomaticComplexity:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
Metrics/BlockNesting:
|
||||||
|
Enabled: false
|
||||||
# - Long Methods, Classes, Blocks, and Modules
|
# - Long Methods, Classes, Blocks, and Modules
|
||||||
Metrics/MethodLength:
|
Metrics/MethodLength:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
@ -39,6 +44,9 @@ Metrics/BlockLength:
|
||||||
Metrics/ModuleLength:
|
Metrics/ModuleLength:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
|
# WordArray is crashing rubocop in lib/vmpooler/api/helpers.rb
|
||||||
|
Style/WordArray:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
# Either sytnax for regex is ok
|
# Either sytnax for regex is ok
|
||||||
Style/RegexpLiteral:
|
Style/RegexpLiteral:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# This configuration was generated by
|
# This configuration was generated by
|
||||||
# `rubocop --auto-gen-config`
|
# `rubocop --auto-gen-config`
|
||||||
# on 2017-03-02 20:16:29 -0800 using RuboCop version 0.47.1.
|
# on 2017-03-16 15:37:18 -0700 using RuboCop version 0.47.1.
|
||||||
# The point is for the user to remove these configuration records
|
# The point is for the user to remove these configuration records
|
||||||
# one by one as the offenses are removed from the code base.
|
# one by one as the offenses are removed from the code base.
|
||||||
# Note that changes in the inspected code, or installation of new
|
# Note that changes in the inspected code, or installation of new
|
||||||
|
|
@ -13,10 +13,9 @@ Lint/AssignmentInCondition:
|
||||||
- 'lib/vmpooler/api/helpers.rb'
|
- 'lib/vmpooler/api/helpers.rb'
|
||||||
- 'lib/vmpooler/api/v1.rb'
|
- 'lib/vmpooler/api/v1.rb'
|
||||||
|
|
||||||
# Offense count: 6
|
# Offense count: 5
|
||||||
Lint/ConditionPosition:
|
Lint/ConditionPosition:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'lib/vmpooler/api/dashboard.rb'
|
|
||||||
- 'lib/vmpooler/pool_manager.rb'
|
- 'lib/vmpooler/pool_manager.rb'
|
||||||
|
|
||||||
# Offense count: 3
|
# Offense count: 3
|
||||||
|
|
@ -30,13 +29,12 @@ Lint/ShadowingOuterLocalVariable:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'lib/vmpooler/api/helpers.rb'
|
- 'lib/vmpooler/api/helpers.rb'
|
||||||
|
|
||||||
# Offense count: 8
|
# Offense count: 3
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
|
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
|
||||||
Lint/UnusedMethodArgument:
|
Lint/UnusedMethodArgument:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'lib/vmpooler/api/helpers.rb'
|
- 'lib/vmpooler/api/helpers.rb'
|
||||||
- 'lib/vmpooler/dummy_statsd.rb'
|
|
||||||
- 'lib/vmpooler/pool_manager.rb'
|
- 'lib/vmpooler/pool_manager.rb'
|
||||||
- 'lib/vmpooler/vsphere_helper.rb'
|
- 'lib/vmpooler/vsphere_helper.rb'
|
||||||
|
|
||||||
|
|
@ -46,11 +44,6 @@ Lint/UselessAssignment:
|
||||||
- 'lib/vmpooler/api/dashboard.rb'
|
- 'lib/vmpooler/api/dashboard.rb'
|
||||||
- 'lib/vmpooler/api/helpers.rb'
|
- 'lib/vmpooler/api/helpers.rb'
|
||||||
|
|
||||||
# Offense count: 5
|
|
||||||
# Configuration parameters: CountBlocks.
|
|
||||||
Metrics/BlockNesting:
|
|
||||||
Max: 5
|
|
||||||
|
|
||||||
# Offense count: 1
|
# Offense count: 1
|
||||||
# Configuration parameters: CountKeywordArgs.
|
# Configuration parameters: CountKeywordArgs.
|
||||||
Metrics/ParameterLists:
|
Metrics/ParameterLists:
|
||||||
|
|
@ -134,13 +127,12 @@ Style/EmptyLines:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'lib/vmpooler/api/dashboard.rb'
|
- 'lib/vmpooler/api/dashboard.rb'
|
||||||
|
|
||||||
# Offense count: 2
|
# Offense count: 1
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
||||||
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
|
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
|
||||||
Style/EmptyLinesAroundClassBody:
|
Style/EmptyLinesAroundClassBody:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'lib/vmpooler/api/dashboard.rb'
|
|
||||||
- 'lib/vmpooler/api/helpers.rb'
|
- 'lib/vmpooler/api/helpers.rb'
|
||||||
|
|
||||||
# Offense count: 3
|
# Offense count: 3
|
||||||
|
|
@ -151,27 +143,12 @@ Style/EmptyLinesAroundModuleBody:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'lib/vmpooler/api/helpers.rb'
|
- 'lib/vmpooler/api/helpers.rb'
|
||||||
|
|
||||||
# Offense count: 2
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
Style/EmptyLiteral:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/vmpooler/api/dashboard.rb'
|
|
||||||
|
|
||||||
# Offense count: 1
|
# Offense count: 1
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
|
||||||
# SupportedStyles: compact, expanded
|
|
||||||
Style/EmptyMethod:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/vmpooler/dummy_statsd.rb'
|
|
||||||
|
|
||||||
# Offense count: 3
|
|
||||||
# Cop supports --auto-correct.
|
|
||||||
# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
|
# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
|
||||||
Style/ExtraSpacing:
|
Style/ExtraSpacing:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'lib/vmpooler/pool_manager.rb'
|
- 'lib/vmpooler/pool_manager.rb'
|
||||||
- 'lib/vmpooler/statsd.rb'
|
|
||||||
|
|
||||||
# Offense count: 2
|
# Offense count: 2
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
|
|
@ -244,13 +221,11 @@ Style/IndentHash:
|
||||||
- 'lib/vmpooler/api/helpers.rb'
|
- 'lib/vmpooler/api/helpers.rb'
|
||||||
- 'lib/vmpooler/api/v1.rb'
|
- 'lib/vmpooler/api/v1.rb'
|
||||||
|
|
||||||
# Offense count: 4
|
# Offense count: 2
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
# Configuration parameters: Width.
|
# Configuration parameters: Width.
|
||||||
Style/IndentationWidth:
|
Style/IndentationWidth:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'lib/vmpooler/api/dashboard.rb'
|
|
||||||
- 'lib/vmpooler/api/reroute.rb'
|
|
||||||
- 'lib/vmpooler/api/v1.rb'
|
- 'lib/vmpooler/api/v1.rb'
|
||||||
- 'lib/vmpooler/vsphere_helper.rb'
|
- 'lib/vmpooler/vsphere_helper.rb'
|
||||||
|
|
||||||
|
|
@ -412,13 +387,12 @@ Style/SpaceAroundKeyword:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'lib/vmpooler/api/v1.rb'
|
- 'lib/vmpooler/api/v1.rb'
|
||||||
|
|
||||||
# Offense count: 4
|
# Offense count: 1
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
# Configuration parameters: AllowForAlignment.
|
# Configuration parameters: AllowForAlignment.
|
||||||
Style/SpaceAroundOperators:
|
Style/SpaceAroundOperators:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'lib/vmpooler/api/v1.rb'
|
- 'lib/vmpooler/api/v1.rb'
|
||||||
- 'lib/vmpooler/statsd.rb'
|
|
||||||
|
|
||||||
# Offense count: 4
|
# Offense count: 4
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
|
|
@ -442,25 +416,14 @@ Style/SpaceInsideParens:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'lib/vmpooler/api/v1.rb'
|
- 'lib/vmpooler/api/v1.rb'
|
||||||
|
|
||||||
# Offense count: 2
|
# Offense count: 12
|
||||||
# Cop supports --auto-correct.
|
|
||||||
Style/SpaceInsidePercentLiteralDelimiters:
|
|
||||||
Exclude:
|
|
||||||
- 'lib/vmpooler/api.rb'
|
|
||||||
|
|
||||||
# Offense count: 47
|
|
||||||
# Cop supports --auto-correct.
|
# Cop supports --auto-correct.
|
||||||
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
|
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
|
||||||
# SupportedStyles: single_quotes, double_quotes
|
# SupportedStyles: single_quotes, double_quotes
|
||||||
Style/StringLiterals:
|
Style/StringLiterals:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'lib/vmpooler/api.rb'
|
|
||||||
- 'lib/vmpooler/api/dashboard.rb'
|
|
||||||
- 'lib/vmpooler/api/reroute.rb'
|
|
||||||
- 'lib/vmpooler/api/v1.rb'
|
- 'lib/vmpooler/api/v1.rb'
|
||||||
- 'lib/vmpooler/graphite.rb'
|
|
||||||
- 'lib/vmpooler/pool_manager.rb'
|
- 'lib/vmpooler/pool_manager.rb'
|
||||||
- 'lib/vmpooler/statsd.rb'
|
|
||||||
- 'lib/vmpooler/vsphere_helper.rb'
|
- 'lib/vmpooler/vsphere_helper.rb'
|
||||||
- 'vmpooler'
|
- 'vmpooler'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ module Vmpooler
|
||||||
|
|
||||||
# Load dashboard components
|
# Load dashboard components
|
||||||
begin
|
begin
|
||||||
require "dashboard"
|
require 'dashboard'
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
require File.expand_path(File.join(File.dirname(__FILE__), 'dashboard'))
|
require File.expand_path(File.join(File.dirname(__FILE__), 'dashboard'))
|
||||||
end
|
end
|
||||||
|
|
@ -30,7 +30,7 @@ module Vmpooler
|
||||||
use Vmpooler::Dashboard
|
use Vmpooler::Dashboard
|
||||||
|
|
||||||
# Load API components
|
# Load API components
|
||||||
%w( helpers dashboard reroute v1 ).each do |lib|
|
%w(helpers dashboard reroute v1).each do |lib|
|
||||||
begin
|
begin
|
||||||
require "api/#{lib}"
|
require "api/#{lib}"
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
|
|
|
||||||
|
|
@ -1,146 +1,143 @@
|
||||||
module Vmpooler
|
module Vmpooler
|
||||||
class API
|
class API
|
||||||
class Dashboard < Sinatra::Base
|
class Dashboard < Sinatra::Base
|
||||||
|
# handle to the App's configuration information
|
||||||
# handle to the App's configuration information
|
def config
|
||||||
def config
|
@config ||= Vmpooler::API.settings.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'])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:history]
|
# configuration setting for server hosting graph URLs to view
|
||||||
if graph_url
|
def graph_server
|
||||||
history ||= {}
|
return @graph_server if @graph_server
|
||||||
|
|
||||||
begin
|
if config[:graphs]
|
||||||
buffer = open(graph_link('.ready.*&from=-1hour&format=json')).read
|
return false unless config[:graphs]['server']
|
||||||
history = JSON.parse(buffer)
|
@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|
|
# configuration setting for URL prefix for graphs to view
|
||||||
if pool['target'] =~ /.*\.(.*)$/
|
def graph_prefix
|
||||||
pool['name'] = Regexp.last_match[1]
|
return @graph_prefix if @graph_prefix
|
||||||
|
|
||||||
if result[pool['name']]
|
if config[:graphs]
|
||||||
pool['last'] = result[pool['name']]['size']
|
return 'vmpooler' unless config[:graphs]['prefix']
|
||||||
result[pool['name']]['history'] ||= Array.new
|
@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|
|
# what is the base URL for viewable graphs?
|
||||||
8.times do |_n|
|
def graph_url
|
||||||
if metric[0]
|
return false unless graph_server && graph_prefix
|
||||||
pool['last'] = metric[0].to_i
|
@graph_url ||= "http://#{graph_server}/render?target=#{graph_prefix}"
|
||||||
result[pool['name']]['history'].push(metric[0].to_i)
|
end
|
||||||
else
|
|
||||||
result[pool['name']]['history'].push(pool['last'])
|
# 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
|
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
|
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
|
end
|
||||||
end
|
JSON.pretty_generate(result)
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:history]
|
get '/dashboard/stats/vmpooler/running/?' do
|
||||||
if graph_url
|
content_type :json
|
||||||
begin
|
result = {}
|
||||||
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
|
|
||||||
|
|
||||||
for i in 0..pool['datapoints'].length
|
Vmpooler::API.settings.config[:pools].each do |pool|
|
||||||
if
|
running = Vmpooler::API.settings.redis.scard('vmpooler__running__' + pool['name'])
|
||||||
pool['datapoints'][i] &&
|
pool['major'] = Regexp.last_match[1] if pool['name'] =~ /^(\w+)\-/
|
||||||
pool['datapoints'][i][0]
|
result[pool['major']] ||= {}
|
||||||
pool['last'] = pool['datapoints'][i][0]
|
result[pool['major']]['running'] = result[pool['major']]['running'].to_i + running.to_i
|
||||||
result[pool['major']]['history'][i] ||= 0
|
end
|
||||||
result[pool['major']]['history'][i] = result[pool['major']]['history'][i].to_i + pool['datapoints'][i][0].to_i
|
|
||||||
else
|
if params[:history]
|
||||||
result[pool['major']]['history'][i] = result[pool['major']]['history'][i].to_i + pool['last'].to_i
|
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
|
end
|
||||||
end
|
end
|
||||||
|
rescue
|
||||||
end
|
end
|
||||||
rescue
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
JSON.pretty_generate(result)
|
||||||
end
|
end
|
||||||
JSON.pretty_generate(result)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,71 +1,71 @@
|
||||||
module Vmpooler
|
module Vmpooler
|
||||||
class API
|
class API
|
||||||
class Reroute < Sinatra::Base
|
class Reroute < Sinatra::Base
|
||||||
api_version = '1'
|
api_version = '1'
|
||||||
|
|
||||||
get '/status/?' do
|
get '/status/?' do
|
||||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/status")
|
call env.merge('PATH_INFO' => "/api/v#{api_version}/status")
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/summary/?' do
|
get '/summary/?' do
|
||||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/summary")
|
call env.merge('PATH_INFO' => "/api/v#{api_version}/summary")
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/summary/:route/?:key?/?' do
|
get '/summary/:route/?:key?/?' do
|
||||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/summary/#{params[:route]}/#{params[:key]}")
|
call env.merge('PATH_INFO' => "/api/v#{api_version}/summary/#{params[:route]}/#{params[:key]}")
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/token/?' do
|
get '/token/?' do
|
||||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/token")
|
call env.merge('PATH_INFO' => "/api/v#{api_version}/token")
|
||||||
end
|
end
|
||||||
|
|
||||||
post '/token/?' do
|
post '/token/?' do
|
||||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/token")
|
call env.merge('PATH_INFO' => "/api/v#{api_version}/token")
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/token/:token/?' do
|
get '/token/:token/?' do
|
||||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/token/#{params[:token]}")
|
call env.merge('PATH_INFO' => "/api/v#{api_version}/token/#{params[:token]}")
|
||||||
end
|
end
|
||||||
|
|
||||||
delete '/token/:token/?' do
|
delete '/token/:token/?' do
|
||||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/token/#{params[:token]}")
|
call env.merge('PATH_INFO' => "/api/v#{api_version}/token/#{params[:token]}")
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/vm/?' do
|
get '/vm/?' do
|
||||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/vm")
|
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm")
|
||||||
end
|
end
|
||||||
|
|
||||||
post '/vm/?' do
|
post '/vm/?' do
|
||||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/vm")
|
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm")
|
||||||
end
|
end
|
||||||
|
|
||||||
post '/vm/:template/?' do
|
post '/vm/:template/?' do
|
||||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/vm/#{params[:template]}")
|
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm/#{params[:template]}")
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/vm/:hostname/?' do
|
get '/vm/:hostname/?' do
|
||||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/vm/#{params[:hostname]}")
|
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm/#{params[:hostname]}")
|
||||||
end
|
end
|
||||||
|
|
||||||
delete '/vm/:hostname/?' do
|
delete '/vm/:hostname/?' do
|
||||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/vm/#{params[:hostname]}")
|
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm/#{params[:hostname]}")
|
||||||
end
|
end
|
||||||
|
|
||||||
put '/vm/:hostname/?' do
|
put '/vm/:hostname/?' do
|
||||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/vm/#{params[:hostname]}")
|
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm/#{params[:hostname]}")
|
||||||
end
|
end
|
||||||
|
|
||||||
post '/vm/:hostname/snapshot/?' do
|
post '/vm/:hostname/snapshot/?' do
|
||||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/vm/#{params[:hostname]}/snapshot")
|
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm/#{params[:hostname]}/snapshot")
|
||||||
end
|
end
|
||||||
|
|
||||||
post '/vm/:hostname/snapshot/:snapshot/?' do
|
post '/vm/:hostname/snapshot/:snapshot/?' do
|
||||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/vm/#{params[:hostname]}/snapshot/#{params[:snapshot]}")
|
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm/#{params[:hostname]}/snapshot/#{params[:snapshot]}")
|
||||||
end
|
end
|
||||||
|
|
||||||
put '/vm/:hostname/disk/:size/?' do
|
put '/vm/:hostname/disk/:size/?' do
|
||||||
call env.merge("PATH_INFO" => "/api/v#{api_version}/vm/#{params[:hostname]}/disk/#{params[:size]}")
|
call env.merge('PATH_INFO' => "/api/v#{api_version}/vm/#{params[:hostname]}/disk/#{params[:size]}")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,18 +2,18 @@ module Vmpooler
|
||||||
class DummyStatsd
|
class DummyStatsd
|
||||||
attr_reader :server, :port, :prefix
|
attr_reader :server, :port, :prefix
|
||||||
|
|
||||||
def initialize(params = {})
|
def initialize(*)
|
||||||
end
|
end
|
||||||
|
|
||||||
def increment(label)
|
def increment(*)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def gauge(label, value)
|
def gauge(*)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def timing(label, duration)
|
def timing(*)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,13 @@ module Vmpooler
|
||||||
attr_reader :server, :port, :prefix
|
attr_reader :server, :port, :prefix
|
||||||
|
|
||||||
def initialize(params = {})
|
def initialize(params = {})
|
||||||
if params["server"].nil? || params["server"].empty?
|
if params['server'].nil? || params['server'].empty?
|
||||||
raise ArgumentError, "Graphite server is required. Config: #{params.inspect}"
|
raise ArgumentError, "Graphite server is required. Config: #{params.inspect}"
|
||||||
end
|
end
|
||||||
|
|
||||||
@server = params["server"]
|
@server = params['server']
|
||||||
@port = params["port"] || 2003
|
@port = params['port'] || 2003
|
||||||
@prefix = params["prefix"] || "vmpooler"
|
@prefix = params['prefix'] || 'vmpooler'
|
||||||
end
|
end
|
||||||
|
|
||||||
def increment(label)
|
def increment(label)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
%w( base vsphere ).each do |lib|
|
%w(base vsphere).each do |lib|
|
||||||
begin
|
begin
|
||||||
require "vmpooler/providers/#{lib}"
|
require "vmpooler/providers/#{lib}"
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
|
|
|
||||||
|
|
@ -19,16 +19,16 @@ module Vmpooler
|
||||||
# returns
|
# returns
|
||||||
# hashtable
|
# hashtable
|
||||||
# name : name of the device <---- TODO is this all?
|
# name : name of the device <---- TODO is this all?
|
||||||
def vms_in_pool(pool)
|
def vms_in_pool(_pool)
|
||||||
fail "#{self.class.name} does not implement vms_in_pool"
|
raise("#{self.class.name} does not implement vms_in_pool")
|
||||||
end
|
end
|
||||||
|
|
||||||
# inputs
|
# inputs
|
||||||
# vm_name: string
|
# vm_name: string
|
||||||
# returns
|
# returns
|
||||||
# [String] hostname = Name of the host computer running the vm. If this is not a Virtual Machine, it returns the vm_name
|
# [String] hostname = Name of the host computer running the vm. If this is not a Virtual Machine, it returns the vm_name
|
||||||
def get_vm_host(vm_name)
|
def get_vm_host(_vm_name)
|
||||||
fail "#{self.class.name} does not implement get_vm_host"
|
raise("#{self.class.name} does not implement get_vm_host")
|
||||||
end
|
end
|
||||||
|
|
||||||
# inputs
|
# inputs
|
||||||
|
|
@ -36,8 +36,8 @@ module Vmpooler
|
||||||
# returns
|
# returns
|
||||||
# [String] hostname = Name of the most appropriate host computer to run this VM. Useful for load balancing VMs in a cluster
|
# [String] hostname = Name of the most appropriate host computer to run this VM. Useful for load balancing VMs in a cluster
|
||||||
# If this is not a Virtual Machine, it returns the vm_name
|
# If this is not a Virtual Machine, it returns the vm_name
|
||||||
def find_least_used_compatible_host(vm_name)
|
def find_least_used_compatible_host(_vm_name)
|
||||||
fail "#{self.class.name} does not implement find_least_used_compatible_host"
|
raise("#{self.class.name} does not implement find_least_used_compatible_host")
|
||||||
end
|
end
|
||||||
|
|
||||||
# inputs
|
# inputs
|
||||||
|
|
@ -45,8 +45,8 @@ module Vmpooler
|
||||||
# dest_host_name: string (Name of the host to migrate `vm_name` to)
|
# dest_host_name: string (Name of the host to migrate `vm_name` to)
|
||||||
# returns
|
# returns
|
||||||
# [Boolean] Returns true on success or false on failure
|
# [Boolean] Returns true on success or false on failure
|
||||||
def migrate_vm_to_host(vm_name, dest_host_name)
|
def migrate_vm_to_host(_vm_name, _dest_host_name)
|
||||||
fail "#{self.class.name} does not implement migrate_vm_to_host"
|
raise("#{self.class.name} does not implement migrate_vm_to_host")
|
||||||
end
|
end
|
||||||
|
|
||||||
# inputs
|
# inputs
|
||||||
|
|
@ -61,8 +61,8 @@ module Vmpooler
|
||||||
# [Time] boottime = Time when the VM was created/booted
|
# [Time] boottime = Time when the VM was created/booted
|
||||||
# [String] powerstate = Current power state of a VM. Valid values (as per vCenter API)
|
# [String] powerstate = Current power state of a VM. Valid values (as per vCenter API)
|
||||||
# - 'PoweredOn','PoweredOff'
|
# - 'PoweredOn','PoweredOff'
|
||||||
def get_vm(vm_name)
|
def get_vm(_vm_name)
|
||||||
fail "#{self.class.name} does not implement get_vm"
|
raise("#{self.class.name} does not implement get_vm")
|
||||||
end
|
end
|
||||||
|
|
||||||
# inputs
|
# inputs
|
||||||
|
|
@ -70,8 +70,8 @@ module Vmpooler
|
||||||
# new_vmname : string Name the new VM should use
|
# new_vmname : string Name the new VM should use
|
||||||
# returns
|
# returns
|
||||||
# Hashtable of the VM as per get_vm
|
# Hashtable of the VM as per get_vm
|
||||||
def create_vm(pool,new_vmname)
|
def create_vm(_pool, _new_vmname)
|
||||||
fail "#{self.class.name} does not implement create_vm"
|
raise("#{self.class.name} does not implement create_vm")
|
||||||
end
|
end
|
||||||
|
|
||||||
# inputs
|
# inputs
|
||||||
|
|
@ -79,8 +79,8 @@ module Vmpooler
|
||||||
# pool: string
|
# pool: string
|
||||||
# returns
|
# returns
|
||||||
# boolean : true if success, false on error
|
# boolean : true if success, false on error
|
||||||
def destroy_vm(vm_name,pool)
|
def destroy_vm(_vm_name, _pool)
|
||||||
fail "#{self.class.name} does not implement destroy_vm"
|
raise("#{self.class.name} does not implement destroy_vm")
|
||||||
end
|
end
|
||||||
|
|
||||||
# inputs
|
# inputs
|
||||||
|
|
@ -89,8 +89,8 @@ module Vmpooler
|
||||||
# timeout: int (Seconds)
|
# timeout: int (Seconds)
|
||||||
# returns
|
# returns
|
||||||
# result: boolean
|
# result: boolean
|
||||||
def is_vm_ready?(vm,pool,timeout)
|
def vm_ready?(_vm, _pool, _timeout)
|
||||||
fail "#{self.class.name} does not implement is_vm_ready?"
|
raise("#{self.class.name} does not implement vm_ready?")
|
||||||
end
|
end
|
||||||
|
|
||||||
# inputs
|
# inputs
|
||||||
|
|
@ -100,7 +100,6 @@ module Vmpooler
|
||||||
def vm_exists?(vm)
|
def vm_exists?(vm)
|
||||||
!get_vm(vm).nil?
|
!get_vm(vm).nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,14 @@
|
||||||
module Vmpooler
|
module Vmpooler
|
||||||
class PoolManager
|
class PoolManager
|
||||||
class Provider
|
class Provider
|
||||||
class VSphere < Vmpooler::PoolManager::Provider::Base
|
class VSphere < Vmpooler::PoolManager::Provider::Base
|
||||||
|
|
||||||
def initialize(options)
|
def initialize(options)
|
||||||
super(options)
|
super(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def name
|
def name
|
||||||
'vsphere'
|
'vsphere'
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,30 +6,30 @@ module Vmpooler
|
||||||
attr_reader :server, :port, :prefix
|
attr_reader :server, :port, :prefix
|
||||||
|
|
||||||
def initialize(params = {})
|
def initialize(params = {})
|
||||||
if params["server"].nil? || params["server"].empty?
|
if params['server'].nil? || params['server'].empty?
|
||||||
raise ArgumentError, "Statsd server is required. Config: #{params.inspect}"
|
raise ArgumentError, "Statsd server is required. Config: #{params.inspect}"
|
||||||
end
|
end
|
||||||
|
|
||||||
host = params["server"]
|
host = params['server']
|
||||||
@port = params["port"] || 8125
|
@port = params['port'] || 8125
|
||||||
@prefix = params["prefix"] || 'vmpooler'
|
@prefix = params['prefix'] || 'vmpooler'
|
||||||
@server = ::Statsd.new(host, @port)
|
@server = ::Statsd.new(host, @port)
|
||||||
end
|
end
|
||||||
|
|
||||||
def increment(label)
|
def increment(label)
|
||||||
server.increment(prefix + "." + label)
|
server.increment(prefix + '.' + label)
|
||||||
rescue => err
|
rescue => err
|
||||||
$stderr.puts "Failure incrementing #{prefix}.#{label} on statsd server [#{server}:#{port}]: #{err}"
|
$stderr.puts "Failure incrementing #{prefix}.#{label} on statsd server [#{server}:#{port}]: #{err}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def gauge(label, value)
|
def gauge(label, value)
|
||||||
server.gauge(prefix + "." + label, value)
|
server.gauge(prefix + '.' + label, value)
|
||||||
rescue => err
|
rescue => err
|
||||||
$stderr.puts "Failure updating gauge #{prefix}.#{label} on statsd server [#{server}:#{port}]: #{err}"
|
$stderr.puts "Failure updating gauge #{prefix}.#{label} on statsd server [#{server}:#{port}]: #{err}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def timing(label, duration)
|
def timing(label, duration)
|
||||||
server.timing(prefix + "." + label, duration)
|
server.timing(prefix + '.' + label, duration)
|
||||||
rescue => err
|
rescue => err
|
||||||
$stderr.puts "Failure updating timing #{prefix}.#{label} on statsd server [#{server}:#{port}]: #{err}"
|
$stderr.puts "Failure updating timing #{prefix}.#{label} on statsd server [#{server}:#{port}]: #{err}"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -66,9 +66,9 @@ describe 'Vmpooler::PoolManager::Provider::Base' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#is_vm_ready?' do
|
describe '#vm_ready?' do
|
||||||
it 'should raise error' do
|
it 'should raise error' do
|
||||||
expect{subject.is_vm_ready?('vm','pool','timeout')}.to raise_error(/does not implement is_vm_ready?/)
|
expect{subject.vm_ready?('vm','pool','timeout')}.to raise_error(/does not implement vm_ready?/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,9 +63,9 @@ describe 'Vmpooler::PoolManager::Provider::VSphere' do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#is_vm_ready?' do
|
describe '#vm_ready?' do
|
||||||
it 'should raise error' do
|
it 'should raise error' do
|
||||||
expect{subject.is_vm_ready?('vm','pool','timeout')}.to raise_error(/does not implement is_vm_ready?/)
|
expect{subject.vm_ready?('vm','pool','timeout')}.to raise_error(/does not implement vm_ready?/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue