From bdee20cf213402a0ff8bc1877b296e3747fdb878 Mon Sep 17 00:00:00 2001 From: Scott Schneider Date: Tue, 1 Oct 2013 15:44:11 -0700 Subject: [PATCH] Syntax (spacing) --- lib/require_relative.rb | 10 +++++----- vmware-host-pooler | 20 ++++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/require_relative.rb b/lib/require_relative.rb index 64836dd..ab9114c 100644 --- a/lib/require_relative.rb +++ b/lib/require_relative.rb @@ -2,15 +2,15 @@ # available to younger rubies. It trys hard to not re-require # files. -unless Kernel.respond_to?( :require_relative ) +unless Kernel.respond_to?(:require_relative) module Kernel - def require_relative( path ) - desired_path = File.expand_path( '../' + path.to_str, caller[0] ) + def require_relative(path) + desired_path = File.expand_path('../'+path.to_str, caller[0]) shortest = desired_path $:.each do |path| path += '/' - if desired_path.index( path ) == 0 - candidate = desired_path.sub( path, '' ) + if desired_path.index(path) == 0 + candidate = desired_path.sub(path, '') shortest = candidate if candidate.size < shortest.size end end diff --git a/vmware-host-pooler b/vmware-host-pooler index 92b9969..c9d77f8 100755 --- a/vmware-host-pooler +++ b/vmware-host-pooler @@ -4,19 +4,19 @@ require 'rbvmomi' require 'redis' require 'yaml' -$:.unshift( File.dirname( __FILE__ ) ) +$:.unshift(File.dirname(__FILE__)) require 'lib/require_relative' require 'lib/vsphere_helper' vsphere_helper = VsphereHelper.new -Dir.chdir( File.dirname( __FILE__ ) ) +Dir.chdir(File.dirname(__FILE__)) # Load the configuration file -config_file = File.expand_path( 'vmware-host-pooler.yaml' ) +config_file = File.expand_path('vmware-host-pooler.yaml') -pools = YAML.load_file( config_file )[:pools] -vsphere = YAML.load_file( config_file )[:vsphere] +pools = YAML.load_file(config_file)[:pools] +vsphere = YAML.load_file(config_file)[:vsphere] # Connect to vSphere $vim = RbVmomi::VIM.connect( @@ -51,11 +51,15 @@ loop do end inventory[vm['name']] = 1 - total = total + 1 + total = total+1 end - # Check pending pool + # Check 'pending' pool $redis.smembers('vmware_host_pool__pending__'+pool['name']).each do |vm| + if ! inventory[vm] + $redis.srem('vmware_host_pool__pending__'+pool['name'], vm) + end + if ( (vsphere_helper.find_vms(vm)[vm]) and (vsphere_helper.find_vms(vm)[vm].summary.guest.toolsRunningStatus == 'guestToolsRunning') and @@ -74,7 +78,7 @@ loop do end end - # Check ready pool + # Check 'ready' pool $redis.smembers('vmware_host_pool__ready__'+pool['name']).each do |vm| if ! inventory[vm] $redis.srem('vmware_host_pool__ready__'+pool['name'], vm)