Merge pull request #232 from glennsarti/fix-rubocop

Fix rubocop
This commit is contained in:
Rob Braden 2017-07-25 15:06:42 -07:00 committed by GitHub
commit d7adb5aee0
6 changed files with 204 additions and 362 deletions

View file

@ -60,8 +60,12 @@ Style/ConditionalAssignment:
Enabled: false Enabled: false
Next: Next:
Enabled: false Enabled: false
Metrics/ParameterLists:
Max: 10
Style/GuardClause:
Enabled: false
# Enforce LF line endings, even when on Windows # Enforce LF line endings, even when on Windows
Style/EndOfLine: Layout/EndOfLine:
EnforcedStyle: lf EnforcedStyle: lf

View file

@ -1,11 +1,122 @@
# This configuration was generated by # This configuration was generated by
# `rubocop --auto-gen-config` # `rubocop --auto-gen-config`
# on 2017-03-30 17:30:59 -0700 using RuboCop version 0.47.1. # on 2017-07-18 15:25:35 -0700 using RuboCop version 0.49.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
# versions of RuboCop, may require this file to be generated again. # versions of RuboCop, may require this file to be generated again.
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: with_first_parameter, with_fixed_indentation
Layout/AlignParameters:
Exclude:
- 'lib/vmpooler/api/v1.rb'
# Offense count: 9
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentOneStep, IndentationWidth.
# SupportedStyles: case, end
Layout/CaseIndentation:
Exclude:
- 'lib/vmpooler/api/helpers.rb'
- 'lib/vmpooler/api/v1.rb'
# Offense count: 1
# Cop supports --auto-correct.
Layout/ClosingParenthesisIndentation:
Exclude:
- 'lib/vmpooler/api/v1.rb'
# Offense count: 1
# Cop supports --auto-correct.
Layout/EmptyLines:
Exclude:
- 'lib/vmpooler/api/dashboard.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
Layout/EmptyLinesAroundClassBody:
Exclude:
- 'lib/vmpooler/api/helpers.rb'
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
Layout/EmptyLinesAroundModuleBody:
Exclude:
- 'lib/vmpooler/api/helpers.rb'
# Offense count: 7
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_braces
Layout/IndentHash:
Exclude:
- 'lib/vmpooler/api/helpers.rb'
- 'lib/vmpooler/api/v1.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: Width, IgnoredPatterns.
Layout/IndentationWidth:
Exclude:
- 'lib/vmpooler/api/v1.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: symmetrical, new_line, same_line
Layout/MultilineMethodCallBraceLayout:
Exclude:
- 'lib/vmpooler/api/v1.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: space, no_space
Layout/SpaceAroundEqualsInParameterDefault:
Exclude:
- 'lib/vmpooler/api/helpers.rb'
# Offense count: 1
# Cop supports --auto-correct.
Layout/SpaceAroundKeyword:
Exclude:
- 'lib/vmpooler/api/v1.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment.
Layout/SpaceAroundOperators:
Exclude:
- 'lib/vmpooler/api/v1.rb'
# Offense count: 2
# Cop supports --auto-correct.
Layout/SpaceInsideBrackets:
Exclude:
- 'lib/vmpooler/api/v1.rb'
# Offense count: 8
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces.
# SupportedStyles: space, no_space, compact
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceInsideHashLiteralBraces:
Exclude:
- 'lib/vmpooler/api/helpers.rb'
# Offense count: 1
# Cop supports --auto-correct.
Layout/SpaceInsideParens:
Exclude:
- 'lib/vmpooler/api/v1.rb'
# Offense count: 2 # Offense count: 2
# Configuration parameters: AllowSafeAssignment. # Configuration parameters: AllowSafeAssignment.
Lint/AssignmentInCondition: Lint/AssignmentInCondition:
@ -13,30 +124,22 @@ Lint/AssignmentInCondition:
- 'lib/vmpooler/api/helpers.rb' - 'lib/vmpooler/api/helpers.rb'
- 'lib/vmpooler/api/v1.rb' - 'lib/vmpooler/api/v1.rb'
# Offense count: 5 # Offense count: 2
Lint/ConditionPosition:
Exclude:
- 'lib/vmpooler/pool_manager.rb'
# Offense count: 3
Lint/HandleExceptions: Lint/HandleExceptions:
Exclude: Exclude:
- 'lib/vmpooler/api/dashboard.rb' - 'lib/vmpooler/api/dashboard.rb'
- 'lib/vmpooler/pool_manager.rb'
# Offense count: 1 # Offense count: 1
Lint/ShadowingOuterLocalVariable: Lint/ShadowingOuterLocalVariable:
Exclude: Exclude:
- 'lib/vmpooler/api/helpers.rb' - 'lib/vmpooler/api/helpers.rb'
# Offense count: 3 # Offense count: 1
# 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/pool_manager.rb'
- 'lib/vmpooler/vsphere_helper.rb'
# Offense count: 6 # Offense count: 6
Lint/UselessAssignment: Lint/UselessAssignment:
@ -44,28 +147,9 @@ Lint/UselessAssignment:
- 'lib/vmpooler/api/dashboard.rb' - 'lib/vmpooler/api/dashboard.rb'
- 'lib/vmpooler/api/helpers.rb' - 'lib/vmpooler/api/helpers.rb'
# Offense count: 1 # Offense count: 2
# Configuration parameters: CountKeywordArgs.
Metrics/ParameterLists:
Max: 7
# Offense count: 3
# Cop supports --auto-correct. # Cop supports --auto-correct.
Performance/RedundantMatch: Performance/RedundantMatch:
Exclude:
- 'lib/vmpooler/api/v1.rb'
- 'lib/vmpooler/vsphere_helper.rb'
# Offense count: 1
Style/AccessorMethodName:
Exclude:
- 'lib/vmpooler/providers/vsphere.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: with_first_parameter, with_fixed_indentation
Style/AlignParameters:
Exclude: Exclude:
- 'lib/vmpooler/api/v1.rb' - 'lib/vmpooler/api/v1.rb'
@ -78,17 +162,6 @@ Style/AndOr:
- 'lib/vmpooler/api/helpers.rb' - 'lib/vmpooler/api/helpers.rb'
- 'lib/vmpooler/api/v1.rb' - 'lib/vmpooler/api/v1.rb'
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
# FunctionalMethods: let, let!, subject, watch
# IgnoredMethods: lambda, proc, it
Style/BlockDelimiters:
Exclude:
- 'vmpooler'
# Offense count: 2 # Offense count: 2
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles. # Configuration parameters: EnforcedStyle, SupportedStyles.
@ -102,66 +175,6 @@ Style/CaseEquality:
Exclude: Exclude:
- 'lib/vmpooler/api/helpers.rb' - 'lib/vmpooler/api/helpers.rb'
# Offense count: 12
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentOneStep, IndentationWidth.
# SupportedStyles: case, end
Style/CaseIndentation:
Exclude:
- 'lib/vmpooler/api/helpers.rb'
- 'lib/vmpooler/api/v1.rb'
- 'lib/vmpooler/vsphere_helper.rb'
# Offense count: 1
# Cop supports --auto-correct.
Style/ClosingParenthesisIndentation:
Exclude:
- 'lib/vmpooler/api/v1.rb'
# Offense count: 1
# Cop supports --auto-correct.
Style/EmptyCaseCondition:
Exclude:
- 'lib/vmpooler/vsphere_helper.rb'
# Offense count: 1
# Cop supports --auto-correct.
Style/EmptyLines:
Exclude:
- 'lib/vmpooler/api/dashboard.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
Style/EmptyLinesAroundClassBody:
Exclude:
- 'lib/vmpooler/api/helpers.rb'
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
Style/EmptyLinesAroundModuleBody:
Exclude:
- 'lib/vmpooler/api/helpers.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
Style/ExtraSpacing:
Exclude:
- 'lib/vmpooler/pool_manager.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: consistent, special_for_inner_method_call, special_for_inner_method_call_in_parentheses
Style/FirstParameterIndentation:
Exclude:
- 'lib/vmpooler/pool_manager.rb'
- 'lib/vmpooler/vsphere_helper.rb'
# Offense count: 1 # Offense count: 1
# Configuration parameters: EnforcedStyle, SupportedStyles. # Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: for, each # SupportedStyles: for, each
@ -169,21 +182,6 @@ Style/For:
Exclude: Exclude:
- 'lib/vmpooler/api/dashboard.rb' - 'lib/vmpooler/api/dashboard.rb'
# Offense count: 8
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: format, sprintf, percent
Style/FormatString:
Exclude:
- 'lib/vmpooler/pool_manager.rb'
# Offense count: 10
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'lib/vmpooler/api/v1.rb'
- 'lib/vmpooler/pool_manager.rb'
- 'lib/vmpooler/vsphere_helper.rb'
# Offense count: 24 # Offense count: 24
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
@ -193,87 +191,21 @@ Style/HashSyntax:
- 'lib/vmpooler/api/helpers.rb' - 'lib/vmpooler/api/helpers.rb'
- 'lib/vmpooler/api/v1.rb' - 'lib/vmpooler/api/v1.rb'
# Offense count: 2 # Offense count: 4
Style/IfInsideElse:
Exclude:
- 'lib/vmpooler/pool_manager.rb'
# Offense count: 6
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: MaxLineLength. # Configuration parameters: MaxLineLength.
Style/IfUnlessModifier: Style/IfUnlessModifier:
Exclude: Exclude:
- 'lib/vmpooler/api/helpers.rb' - 'lib/vmpooler/api/helpers.rb'
- 'lib/vmpooler/api/v1.rb' - 'lib/vmpooler/api/v1.rb'
- 'lib/vmpooler/pool_manager.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_brackets
Style/IndentArray:
Exclude:
- 'lib/vmpooler/pool_manager.rb'
# Offense count: 7
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_braces
Style/IndentHash:
Exclude:
- 'lib/vmpooler/api/helpers.rb'
- 'lib/vmpooler/api/v1.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: Width.
Style/IndentationWidth:
Exclude:
- 'lib/vmpooler/api/v1.rb'
- 'lib/vmpooler/vsphere_helper.rb'
# Offense count: 1
# Cop supports --auto-correct.
Style/MethodCallWithoutArgsParentheses:
Exclude:
- 'lib/vmpooler/vsphere_helper.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: symmetrical, new_line, same_line
Style/MultilineHashBraceLayout:
Exclude:
- 'lib/vmpooler/pool_manager.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: symmetrical, new_line, same_line
Style/MultilineMethodCallBraceLayout:
Exclude:
- 'lib/vmpooler/api/v1.rb'
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: aligned, indented
Style/MultilineOperationIndentation:
Exclude:
- 'lib/vmpooler/pool_manager.rb'
# Offense count: 3 # Offense count: 3
# Cop supports --auto-correct. # Cop supports --auto-correct.
Style/MutableConstant: # Configuration parameters: EnforcedStyle, SupportedStyles.
Exclude: # SupportedStyles: both, prefix, postfix
- 'lib/vmpooler/vsphere_helper.rb'
# Offense count: 5
# Cop supports --auto-correct.
Style/NegatedIf: Style/NegatedIf:
Exclude: Exclude:
- 'lib/vmpooler/api/v1.rb' - 'lib/vmpooler/api/v1.rb'
- 'lib/vmpooler/pool_manager.rb'
# Offense count: 3 # Offense count: 3
# Cop supports --auto-correct. # Cop supports --auto-correct.
@ -281,7 +213,7 @@ Style/Not:
Exclude: Exclude:
- 'lib/vmpooler/api/v1.rb' - 'lib/vmpooler/api/v1.rb'
# Offense count: 5 # Offense count: 1
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, EnforcedStyle, SupportedStyles. # Configuration parameters: AutoCorrect, EnforcedStyle, SupportedStyles.
# SupportedStyles: predicate, comparison # SupportedStyles: predicate, comparison
@ -289,22 +221,19 @@ Style/NumericPredicate:
Exclude: Exclude:
- 'spec/**/*' - 'spec/**/*'
- 'lib/vmpooler/api/v1.rb' - 'lib/vmpooler/api/v1.rb'
- 'lib/vmpooler/pool_manager.rb'
# Offense count: 3 # Offense count: 2
# Cop supports --auto-correct. # Cop supports --auto-correct.
Style/ParallelAssignment: Style/ParallelAssignment:
Exclude: Exclude:
- 'lib/vmpooler/api/v1.rb' - 'lib/vmpooler/api/v1.rb'
- 'lib/vmpooler/pool_manager.rb'
# Offense count: 2 # Offense count: 1
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: AllowSafeAssignment. # Configuration parameters: AllowSafeAssignment.
Style/ParenthesesAroundCondition: Style/ParenthesesAroundCondition:
Exclude: Exclude:
- 'lib/vmpooler/api/v1.rb' - 'lib/vmpooler/api/v1.rb'
- 'lib/vmpooler/pool_manager.rb'
# Offense count: 2 # Offense count: 2
# Cop supports --auto-correct. # Cop supports --auto-correct.
@ -322,24 +251,11 @@ Style/PredicateName:
- 'spec/**/*' - 'spec/**/*'
- 'lib/vmpooler/api/helpers.rb' - 'lib/vmpooler/api/helpers.rb'
# Offense count: 2 # Offense count: 1
# Cop supports --auto-correct.
Style/RedundantBegin:
Exclude:
- 'lib/vmpooler/pool_manager.rb'
# Offense count: 2
# Cop supports --auto-correct.
Style/RedundantException:
Exclude:
- 'lib/vmpooler/vsphere_helper.rb'
# Offense count: 26
# Cop supports --auto-correct. # Cop supports --auto-correct.
Style/RedundantParentheses: Style/RedundantParentheses:
Exclude: Exclude:
- 'lib/vmpooler/api/v1.rb' - 'lib/vmpooler/api/v1.rb'
- 'lib/vmpooler/pool_manager.rb'
# Offense count: 2 # Offense count: 2
# Cop supports --auto-correct. # Cop supports --auto-correct.
@ -354,83 +270,13 @@ Style/RedundantSelf:
Exclude: Exclude:
- 'lib/vmpooler/api.rb' - 'lib/vmpooler/api.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: only_raise, only_fail, semantic
Style/SignalException:
Exclude:
- 'lib/vmpooler/pool_manager.rb'
# Offense count: 22
# Cop supports --auto-correct.
Style/SpaceAfterNot:
Exclude:
- 'lib/vmpooler/pool_manager.rb'
# Offense count: 7
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: space, no_space
Style/SpaceAroundEqualsInParameterDefault:
Exclude:
- 'lib/vmpooler/api/helpers.rb'
- 'lib/vmpooler/pool_manager.rb'
- 'lib/vmpooler/vsphere_helper.rb'
# Offense count: 1 # Offense count: 1
# Cop supports --auto-correct. # Cop supports --auto-correct.
Style/SpaceAroundKeyword:
Exclude:
- 'lib/vmpooler/api/v1.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment.
Style/SpaceAroundOperators:
Exclude:
- 'lib/vmpooler/api/v1.rb'
# Offense count: 4
# Cop supports --auto-correct.
Style/SpaceInsideBrackets:
Exclude:
- 'lib/vmpooler/api/v1.rb'
- 'lib/vmpooler/vsphere_helper.rb'
# Offense count: 8
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces.
# SupportedStyles: space, no_space, compact
# SupportedStylesForEmptyBraces: space, no_space
Style/SpaceInsideHashLiteralBraces:
Exclude:
- 'lib/vmpooler/api/helpers.rb'
# Offense count: 1
# Cop supports --auto-correct.
Style/SpaceInsideParens:
Exclude:
- 'lib/vmpooler/api/v1.rb'
# Offense count: 12
# 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/v1.rb' - 'lib/vmpooler/api/v1.rb'
- 'lib/vmpooler/pool_manager.rb'
- 'lib/vmpooler/vsphere_helper.rb'
- 'vmpooler'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: IgnoredMethods.
# IgnoredMethods: respond_to, define_method
Style/SymbolProc:
Exclude:
- 'vmpooler'
# Offense count: 1 # Offense count: 1
# Cop supports --auto-correct. # Cop supports --auto-correct.
@ -440,18 +286,21 @@ Style/TernaryParentheses:
Exclude: Exclude:
- 'lib/vmpooler/api/helpers.rb' - 'lib/vmpooler/api/helpers.rb'
# Offense count: 10 # Offense count: 2
# Configuration parameters: EnforcedStyle, SupportedStyles. # Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: snake_case, camelCase # SupportedStyles: snake_case, camelCase
Style/VariableName: Style/VariableName:
Exclude: Exclude:
- 'lib/vmpooler/api/v1.rb' - 'lib/vmpooler/api/v1.rb'
- 'lib/vmpooler/pool_manager.rb'
- 'lib/vmpooler/vsphere_helper.rb'
# Offense count: 2 # Offense count: 1
# Cop supports --auto-correct.
Style/YodaCondition:
Exclude:
- 'lib/vmpooler/api/helpers.rb'
# Offense count: 1
# Cop supports --auto-correct. # Cop supports --auto-correct.
Style/ZeroLengthPredicate: Style/ZeroLengthPredicate:
Exclude: Exclude:
- 'lib/vmpooler/api/helpers.rb' - 'lib/vmpooler/api/helpers.rb'
- 'lib/vmpooler/pool_manager.rb'

View file

@ -42,7 +42,7 @@ module Vmpooler
def _check_pending_vm(vm, pool, timeout, provider) def _check_pending_vm(vm, pool, timeout, provider)
host = provider.get_vm(pool, vm) host = provider.get_vm(pool, vm)
if ! host unless host
fail_pending_vm(vm, pool, timeout, false) fail_pending_vm(vm, pool, timeout, false)
return return
end end
@ -60,7 +60,7 @@ module Vmpooler
def fail_pending_vm(vm, pool, timeout, exists = true) def fail_pending_vm(vm, pool, timeout, exists = true)
clone_stamp = $redis.hget("vmpooler__vm__#{vm}", 'clone') clone_stamp = $redis.hget("vmpooler__vm__#{vm}", 'clone')
return true if !clone_stamp return true unless clone_stamp
time_since_clone = (Time.now - Time.parse(clone_stamp)) / 60 time_since_clone = (Time.now - Time.parse(clone_stamp)) / 60
if time_since_clone > timeout if time_since_clone > timeout
@ -80,12 +80,13 @@ module Vmpooler
def move_pending_vm_to_ready(vm, pool, host) def move_pending_vm_to_ready(vm, pool, host)
if host['hostname'] == vm if host['hostname'] == vm
begin begin
Socket.getaddrinfo(vm, nil) # WTF? I assume this is just priming the local DNS resolver cache?!?! Socket.getaddrinfo(vm, nil) # WTF? I assume this is just priming the local DNS resolver cache?!?!
rescue rescue # rubocop:disable Lint/HandleExceptions
# Do not care about errors what-so-ever
end end
clone_time = $redis.hget('vmpooler__vm__' + vm, 'clone') clone_time = $redis.hget('vmpooler__vm__' + vm, 'clone')
finish = '%.2f' % (Time.now - Time.parse(clone_time)) if clone_time finish = format('%.2f', Time.now - Time.parse(clone_time)) if clone_time
$redis.smove('vmpooler__pending__' + pool, 'vmpooler__ready__' + pool, vm) $redis.smove('vmpooler__pending__' + pool, 'vmpooler__ready__' + pool, vm)
$redis.hset('vmpooler__boot__' + Date.today.to_s, pool + ':' + vm, finish) $redis.hset('vmpooler__boot__' + Date.today.to_s, pool + ':' + vm, finish)
@ -112,7 +113,7 @@ module Vmpooler
host = provider.get_vm(pool, vm) host = provider.get_vm(pool, vm)
# Check if the host even exists # Check if the host even exists
if !host unless host
$redis.srem('vmpooler__ready__' + pool, vm) $redis.srem('vmpooler__ready__' + pool, vm)
$logger.log('s', "[!] [#{pool}] '#{vm}' not found in inventory, removed from 'ready' queue") $logger.log('s', "[!] [#{pool}] '#{vm}' not found in inventory, removed from 'ready' queue")
return return
@ -120,7 +121,7 @@ module Vmpooler
# Check if the hosts TTL has expired # Check if the hosts TTL has expired
if ttl > 0 if ttl > 0
if (((Time.now - host['boottime']) / 60).to_s[/^\d+\.\d{1}/].to_f) > ttl if ((Time.now - host['boottime']) / 60).to_s[/^\d+\.\d{1}/].to_f > ttl
$redis.smove('vmpooler__ready__' + pool, 'vmpooler__completed__' + pool, vm) $redis.smove('vmpooler__ready__' + pool, 'vmpooler__completed__' + pool, vm)
$logger.log('d', "[!] [#{pool}] '#{vm}' reached end of TTL after #{ttl} minutes, removed from 'ready' queue") $logger.log('d', "[!] [#{pool}] '#{vm}' reached end of TTL after #{ttl} minutes, removed from 'ready' queue")
@ -130,14 +131,14 @@ module Vmpooler
$redis.hset('vmpooler__vm__' + vm, 'check', Time.now) $redis.hset('vmpooler__vm__' + vm, 'check', Time.now)
# Check if the VM is not powered on # Check if the VM is not powered on
unless (host['powerstate'].casecmp('poweredon') == 0) unless host['powerstate'].casecmp('poweredon').zero?
$redis.smove('vmpooler__ready__' + pool, 'vmpooler__completed__' + pool, vm) $redis.smove('vmpooler__ready__' + pool, 'vmpooler__completed__' + pool, vm)
$logger.log('d', "[!] [#{pool}] '#{vm}' appears to be powered off, removed from 'ready' queue") $logger.log('d', "[!] [#{pool}] '#{vm}' appears to be powered off, removed from 'ready' queue")
return return
end end
# Check if the hostname has magically changed from underneath Pooler # Check if the hostname has magically changed from underneath Pooler
if (host['hostname'] != vm) if host['hostname'] != vm
$redis.smove('vmpooler__ready__' + pool, 'vmpooler__completed__' + pool, vm) $redis.smove('vmpooler__ready__' + pool, 'vmpooler__completed__' + pool, vm)
$logger.log('d', "[!] [#{pool}] '#{vm}' has mismatched hostname, removed from 'ready' queue") $logger.log('d', "[!] [#{pool}] '#{vm}' has mismatched hostname, removed from 'ready' queue")
return return
@ -145,7 +146,7 @@ module Vmpooler
# Check if the VM is still ready/available # Check if the VM is still ready/available
begin begin
fail "VM #{vm} is not ready" unless provider.vm_ready?(pool, vm) raise("VM #{vm} is not ready") unless provider.vm_ready?(pool, vm)
rescue rescue
if $redis.smove('vmpooler__ready__' + pool, 'vmpooler__completed__' + pool, vm) if $redis.smove('vmpooler__ready__' + pool, 'vmpooler__completed__' + pool, vm)
$logger.log('d', "[!] [#{pool}] '#{vm}' is unreachable, removed from 'ready' queue") $logger.log('d', "[!] [#{pool}] '#{vm}' is unreachable, removed from 'ready' queue")
@ -170,16 +171,13 @@ module Vmpooler
host = provider.get_vm(pool, vm) host = provider.get_vm(pool, vm)
if host if host
queue_from, queue_to = 'running', 'completed'
# Check that VM is within defined lifetime # Check that VM is within defined lifetime
checkouttime = $redis.hget('vmpooler__active__' + pool, vm) checkouttime = $redis.hget('vmpooler__active__' + pool, vm)
if checkouttime if checkouttime
running = (Time.now - Time.parse(checkouttime)) / 60 / 60 running = (Time.now - Time.parse(checkouttime)) / 60 / 60
if (ttl.to_i > 0) && if (ttl.to_i > 0) && (running.to_i >= ttl.to_i)
(running.to_i >= ttl.to_i) move_vm_queue(pool, vm, 'running', 'completed', "reached end of TTL after #{ttl} hours")
move_vm_queue(pool, vm, queue_from, queue_to, "reached end of TTL after #{ttl} hours")
end end
end end
end end
@ -218,7 +216,7 @@ module Vmpooler
$logger.log('d', "[ ] [#{pool_name}] Starting to clone '#{new_vmname}'") $logger.log('d', "[ ] [#{pool_name}] Starting to clone '#{new_vmname}'")
start = Time.now start = Time.now
provider.create_vm(pool_name, new_vmname) provider.create_vm(pool_name, new_vmname)
finish = '%.2f' % (Time.now - start) finish = format('%.2f', Time.now - start)
$redis.hset('vmpooler__clone__' + Date.today.to_s, pool_name + ':' + new_vmname, finish) $redis.hset('vmpooler__clone__' + Date.today.to_s, pool_name + ':' + new_vmname, finish)
$redis.hset('vmpooler__vm__' + new_vmname, 'clone_time', finish) $redis.hset('vmpooler__vm__' + new_vmname, 'clone_time', finish)
@ -258,7 +256,7 @@ module Vmpooler
provider.destroy_vm(pool, vm) provider.destroy_vm(pool, vm)
finish = '%.2f' % (Time.now - start) finish = format('%.2f', Time.now - start)
$logger.log('s', "[-] [#{pool}] '#{vm}' destroyed in #{finish} seconds") $logger.log('s', "[-] [#{pool}] '#{vm}' destroyed in #{finish} seconds")
$metrics.timing("destroy.#{pool}", finish) $metrics.timing("destroy.#{pool}", finish)
end end
@ -275,7 +273,7 @@ module Vmpooler
end end
def _create_vm_disk(pool_name, vm_name, disk_size, provider) def _create_vm_disk(pool_name, vm_name, disk_size, provider)
raise("Invalid disk size of '#{disk_size}' passed") if (disk_size.nil?) || (disk_size.empty?) || (disk_size.to_i <= 0) raise("Invalid disk size of '#{disk_size}' passed") if disk_size.nil? || disk_size.empty? || disk_size.to_i <= 0
$logger.log('s', "[ ] [disk_manager] '#{vm_name}' is attaching a #{disk_size}gb disk") $logger.log('s', "[ ] [disk_manager] '#{vm_name}' is attaching a #{disk_size}gb disk")
@ -283,7 +281,7 @@ module Vmpooler
result = provider.create_disk(pool_name, vm_name, disk_size.to_i) result = provider.create_disk(pool_name, vm_name, disk_size.to_i)
finish = '%.2f' % (Time.now - start) finish = format('%.2f', Time.now - start)
if result if result
rdisks = $redis.hget('vmpooler__vm__' + vm_name, 'disk') rdisks = $redis.hget('vmpooler__vm__' + vm_name, 'disk')
@ -316,7 +314,7 @@ module Vmpooler
result = provider.create_snapshot(pool_name, vm_name, snapshot_name) result = provider.create_snapshot(pool_name, vm_name, snapshot_name)
finish = '%.2f' % (Time.now - start) finish = format('%.2f', Time.now - start)
if result if result
$redis.hset('vmpooler__vm__' + vm_name, 'snapshot:' + snapshot_name, Time.now.to_s) $redis.hset('vmpooler__vm__' + vm_name, 'snapshot:' + snapshot_name, Time.now.to_s)
@ -345,7 +343,7 @@ module Vmpooler
result = provider.revert_snapshot(pool_name, vm_name, snapshot_name) result = provider.revert_snapshot(pool_name, vm_name, snapshot_name)
finish = '%.2f' % (Time.now - start) finish = format('%.2f', Time.now - start)
if result if result
$logger.log('s', "[+] [snapshot_manager] '#{vm_name}' reverted to snapshot '#{snapshot_name}' in #{finish} seconds") $logger.log('s', "[+] [snapshot_manager] '#{vm_name}' reverted to snapshot '#{snapshot_name}' in #{finish} seconds")
@ -373,7 +371,7 @@ module Vmpooler
end end
def check_disk_queue(maxloop = 0, loop_delay = 5) def check_disk_queue(maxloop = 0, loop_delay = 5)
$logger.log('d', "[*] [disk_manager] starting worker thread") $logger.log('d', '[*] [disk_manager] starting worker thread')
$threads['disk_manager'] = Thread.new do $threads['disk_manager'] = Thread.new do
loop_count = 1 loop_count = 1
@ -408,7 +406,7 @@ module Vmpooler
end end
def check_snapshot_queue(maxloop = 0, loop_delay = 5) def check_snapshot_queue(maxloop = 0, loop_delay = 5)
$logger.log('d', "[*] [snapshot_manager] starting worker thread") $logger.log('d', '[*] [snapshot_manager] starting worker thread')
$threads['snapshot_manager'] = Thread.new do $threads['snapshot_manager'] = Thread.new do
loop_count = 1 loop_count = 1
@ -462,7 +460,7 @@ module Vmpooler
def migration_limit(migration_limit) def migration_limit(migration_limit)
# Returns migration_limit setting when enabled # Returns migration_limit setting when enabled
return false if migration_limit == 0 || ! migration_limit return false if migration_limit == 0 || !migration_limit # rubocop:disable Style/NumericPredicate
migration_limit if migration_limit >= 1 migration_limit if migration_limit >= 1
end end
@ -485,43 +483,39 @@ module Vmpooler
migration_limit = migration_limit $config[:config]['migration_limit'] migration_limit = migration_limit $config[:config]['migration_limit']
migration_count = $redis.scard('vmpooler__migration') migration_count = $redis.scard('vmpooler__migration')
if ! migration_limit if !migration_limit
$logger.log('s', "[ ] [#{pool_name}] '#{vm_name}' is running on #{parent_host_name}") $logger.log('s', "[ ] [#{pool_name}] '#{vm_name}' is running on #{parent_host_name}")
return return
elsif migration_count >= migration_limit
$logger.log('s', "[ ] [#{pool_name}] '#{vm_name}' is running on #{parent_host_name}. No migration will be evaluated since the migration_limit has been reached")
return
else else
if migration_count >= migration_limit $redis.sadd('vmpooler__migration', vm_name)
$logger.log('s', "[ ] [#{pool_name}] '#{vm_name}' is running on #{parent_host_name}. No migration will be evaluated since the migration_limit has been reached") host_name = provider.find_least_used_compatible_host(pool_name, vm_name)
return if host_name == parent_host_name
$logger.log('s', "[ ] [#{pool_name}] No migration required for '#{vm_name}' running on #{parent_host_name}")
else else
$redis.sadd('vmpooler__migration', vm_name) finish = migrate_vm_and_record_timing(vm_name, pool_name, parent_host_name, host_name, provider)
host_name = provider.find_least_used_compatible_host(pool_name, vm_name) $logger.log('s', "[>] [#{pool_name}] '#{vm_name}' migrated from #{parent_host_name} to #{host_name} in #{finish} seconds")
if host_name == parent_host_name
$logger.log('s', "[ ] [#{pool_name}] No migration required for '#{vm_name}' running on #{parent_host_name}")
else
finish = migrate_vm_and_record_timing(vm_name, pool_name, parent_host_name, host_name, provider)
$logger.log('s', "[>] [#{pool_name}] '#{vm_name}' migrated from #{parent_host_name} to #{host_name} in #{finish} seconds")
end
remove_vmpooler_migration_vm(pool_name, vm_name)
end end
remove_vmpooler_migration_vm(pool_name, vm_name)
end end
end end
def remove_vmpooler_migration_vm(pool, vm) def remove_vmpooler_migration_vm(pool, vm)
begin $redis.srem('vmpooler__migration', vm)
$redis.srem('vmpooler__migration', vm) rescue => err
rescue => err $logger.log('s', "[x] [#{pool}] '#{vm}' removal from vmpooler__migration failed with an error: #{err}")
$logger.log('s', "[x] [#{pool}] '#{vm}' removal from vmpooler__migration failed with an error: #{err}")
end
end end
def migrate_vm_and_record_timing(vm_name, pool_name, source_host_name, dest_host_name, provider) def migrate_vm_and_record_timing(vm_name, pool_name, source_host_name, dest_host_name, provider)
start = Time.now start = Time.now
provider.migrate_vm_to_host(pool_name, vm_name, dest_host_name) provider.migrate_vm_to_host(pool_name, vm_name, dest_host_name)
finish = '%.2f' % (Time.now - start) finish = format('%.2f', Time.now - start)
$metrics.timing("migrate.#{pool_name}", finish) $metrics.timing("migrate.#{pool_name}", finish)
$metrics.increment("migrate_from.#{source_host_name}") $metrics.increment("migrate_from.#{source_host_name}")
$metrics.increment("migrate_to.#{dest_host_name}") $metrics.increment("migrate_to.#{dest_host_name}")
checkout_to_migration = '%.2f' % (Time.now - Time.parse($redis.hget("vmpooler__vm__#{vm_name}", 'checkout'))) checkout_to_migration = format('%.2f', Time.now - Time.parse($redis.hget("vmpooler__vm__#{vm_name}", 'checkout')))
$redis.hset("vmpooler__vm__#{vm_name}", 'migration_time', finish) $redis.hset("vmpooler__vm__#{vm_name}", 'migration_time', finish)
$redis.hset("vmpooler__vm__#{vm_name}", 'checkout_to_migration', checkout_to_migration) $redis.hset("vmpooler__vm__#{vm_name}", 'checkout_to_migration', checkout_to_migration)
finish finish
@ -585,13 +579,12 @@ module Vmpooler
inventory = {} inventory = {}
begin begin
provider.vms_in_pool(pool['name']).each do |vm| provider.vms_in_pool(pool['name']).each do |vm|
if if !$redis.sismember('vmpooler__running__' + pool['name'], vm['name']) &&
(! $redis.sismember('vmpooler__running__' + pool['name'], vm['name'])) && !$redis.sismember('vmpooler__ready__' + pool['name'], vm['name']) &&
(! $redis.sismember('vmpooler__ready__' + pool['name'], vm['name'])) && !$redis.sismember('vmpooler__pending__' + pool['name'], vm['name']) &&
(! $redis.sismember('vmpooler__pending__' + pool['name'], vm['name'])) && !$redis.sismember('vmpooler__completed__' + pool['name'], vm['name']) &&
(! $redis.sismember('vmpooler__completed__' + pool['name'], vm['name'])) && !$redis.sismember('vmpooler__discovered__' + pool['name'], vm['name']) &&
(! $redis.sismember('vmpooler__discovered__' + pool['name'], vm['name'])) && !$redis.sismember('vmpooler__migrating__' + pool['name'], vm['name'])
(! $redis.sismember('vmpooler__migrating__' + pool['name'], vm['name']))
pool_check_response[:discovered_vms] += 1 pool_check_response[:discovered_vms] += 1
$redis.sadd('vmpooler__discovered__' + pool['name'], vm['name']) $redis.sadd('vmpooler__discovered__' + pool['name'], vm['name'])
@ -703,14 +696,10 @@ module Vmpooler
$metrics.gauge("running.#{pool['name']}", $redis.scard("vmpooler__running__#{pool['name']}")) $metrics.gauge("running.#{pool['name']}", $redis.scard("vmpooler__running__#{pool['name']}"))
if $redis.get("vmpooler__empty__#{pool['name']}") if $redis.get("vmpooler__empty__#{pool['name']}")
unless ready == 0 $redis.del("vmpooler__empty__#{pool['name']}") unless ready.zero?
$redis.del("vmpooler__empty__#{pool['name']}") elsif ready.zero?
end $redis.set("vmpooler__empty__#{pool['name']}", 'true')
else $logger.log('s', "[!] [#{pool['name']}] is empty")
if ready == 0
$redis.set("vmpooler__empty__#{pool['name']}", 'true')
$logger.log('s', "[!] [#{pool['name']}] is empty")
end
end end
if total < pool['size'] if total < pool['size']
@ -814,24 +803,24 @@ module Vmpooler
loop_count = 1 loop_count = 1
loop do loop do
if ! $threads['disk_manager'] if !$threads['disk_manager']
check_disk_queue check_disk_queue
elsif ! $threads['disk_manager'].alive? elsif !$threads['disk_manager'].alive?
$logger.log('d', "[!] [disk_manager] worker thread died, restarting") $logger.log('d', '[!] [disk_manager] worker thread died, restarting')
check_disk_queue check_disk_queue
end end
if ! $threads['snapshot_manager'] if !$threads['snapshot_manager']
check_snapshot_queue check_snapshot_queue
elsif ! $threads['snapshot_manager'].alive? elsif !$threads['snapshot_manager'].alive?
$logger.log('d', "[!] [snapshot_manager] worker thread died, restarting") $logger.log('d', '[!] [snapshot_manager] worker thread died, restarting')
check_snapshot_queue check_snapshot_queue
end end
$config[:pools].each do |pool| $config[:pools].each do |pool|
if ! $threads[pool['name']] if !$threads[pool['name']]
check_pool(pool) check_pool(pool)
elsif ! $threads[pool['name']].alive? elsif !$threads[pool['name']].alive?
$logger.log('d', "[!] [#{pool['name']}] worker thread died, restarting") $logger.log('d', "[!] [#{pool['name']}] worker thread died, restarting")
check_pool(pool, check_loop_delay_min, check_loop_delay_max, check_loop_delay_decay) check_pool(pool, check_loop_delay_min, check_loop_delay_max, check_loop_delay_decay)
end end

View file

@ -695,7 +695,7 @@ module Vmpooler
def find_vmdks(vmname, datastore, connection, datacentername) def find_vmdks(vmname, datastore, connection, datacentername)
disks = [] disks = []
vmdk_datastore = find_datastore(datastore, connection,datacentername) vmdk_datastore = find_datastore(datastore, connection, datacentername)
vm_files = connection.serviceContent.propertyCollector.collectMultiple vmdk_datastore.vm, 'layoutEx.file' vm_files = connection.serviceContent.propertyCollector.collectMultiple vmdk_datastore.vm, 'layoutEx.file'
vm_files.keys.each do |f| vm_files.keys.each do |f|

View file

@ -2316,7 +2316,7 @@ EOT
it 'should set checkout_to_migration metric in redis' do it 'should set checkout_to_migration metric in redis' do
expect(redis.hget("vmpooler__vm__#{vm}", 'checkout_to_migration')).to be_nil expect(redis.hget("vmpooler__vm__#{vm}", 'checkout_to_migration')).to be_nil
subject.migrate_vm_and_record_timing(vm, pool, source_host_name, dest_host_name, provider) subject.migrate_vm_and_record_timing(vm, pool, source_host_name, dest_host_name, provider)
expect(redis.hget("vmpooler__vm__#{vm}", 'checkout_to_migration')).to match(/0\.[\d]+/) expect(redis.hget("vmpooler__vm__#{vm}", 'checkout_to_migration')).to match(/[01]\.[\d]+/)
end end
end end

View file

@ -11,26 +11,26 @@ logger_file = config[:config]['logfile']
metrics = Vmpooler.new_metrics(config) metrics = Vmpooler.new_metrics(config)
api = Thread.new { api = Thread.new do
thr = Vmpooler::API.new thr = Vmpooler::API.new
thr.helpers.configure(config, Vmpooler.new_redis(redis_host), metrics) thr.helpers.configure(config, Vmpooler.new_redis(redis_host), metrics)
thr.helpers.execute! thr.helpers.execute!
} end
manager = Thread.new { manager = Thread.new do
Vmpooler::PoolManager.new( Vmpooler::PoolManager.new(
config, config,
Vmpooler.new_logger(logger_file), Vmpooler.new_logger(logger_file),
Vmpooler.new_redis(redis_host), Vmpooler.new_redis(redis_host),
metrics metrics
).execute! ).execute!
}
if ENV['VMPOOLER_DEBUG']
trap("INT") {
puts "Shutting down."
[api, manager].each { |t| t.exit }
}
end end
[api, manager].each { |t| t.join } if ENV['VMPOOLER_DEBUG']
trap('INT') do
puts 'Shutting down.'
[api, manager].each(&:exit)
end
end
[api, manager].each(&:join)