Syntax (spacing)

This commit is contained in:
Scott Schneider 2013-10-01 15:44:11 -07:00
parent ba56310415
commit bdee20cf21
2 changed files with 17 additions and 13 deletions

View file

@ -2,15 +2,15 @@
# available to younger rubies. It trys hard to not re-require # available to younger rubies. It trys hard to not re-require
# files. # files.
unless Kernel.respond_to?( :require_relative ) unless Kernel.respond_to?(:require_relative)
module Kernel module Kernel
def require_relative( path ) def require_relative(path)
desired_path = File.expand_path( '../' + path.to_str, caller[0] ) desired_path = File.expand_path('../'+path.to_str, caller[0])
shortest = desired_path shortest = desired_path
$:.each do |path| $:.each do |path|
path += '/' path += '/'
if desired_path.index( path ) == 0 if desired_path.index(path) == 0
candidate = desired_path.sub( path, '' ) candidate = desired_path.sub(path, '')
shortest = candidate if candidate.size < shortest.size shortest = candidate if candidate.size < shortest.size
end end
end end

View file

@ -4,19 +4,19 @@ require 'rbvmomi'
require 'redis' require 'redis'
require 'yaml' require 'yaml'
$:.unshift( File.dirname( __FILE__ ) ) $:.unshift(File.dirname(__FILE__))
require 'lib/require_relative' require 'lib/require_relative'
require 'lib/vsphere_helper' require 'lib/vsphere_helper'
vsphere_helper = VsphereHelper.new vsphere_helper = VsphereHelper.new
Dir.chdir( File.dirname( __FILE__ ) ) Dir.chdir(File.dirname(__FILE__))
# Load the configuration 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] pools = YAML.load_file(config_file)[:pools]
vsphere = YAML.load_file( config_file )[:vsphere] vsphere = YAML.load_file(config_file)[:vsphere]
# Connect to vSphere # Connect to vSphere
$vim = RbVmomi::VIM.connect( $vim = RbVmomi::VIM.connect(
@ -51,11 +51,15 @@ loop do
end end
inventory[vm['name']] = 1 inventory[vm['name']] = 1
total = total + 1 total = total+1
end end
# Check pending pool # Check 'pending' pool
$redis.smembers('vmware_host_pool__pending__'+pool['name']).each do |vm| $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 ( if (
(vsphere_helper.find_vms(vm)[vm]) and (vsphere_helper.find_vms(vm)[vm]) and
(vsphere_helper.find_vms(vm)[vm].summary.guest.toolsRunningStatus == 'guestToolsRunning') and (vsphere_helper.find_vms(vm)[vm].summary.guest.toolsRunningStatus == 'guestToolsRunning') and
@ -74,7 +78,7 @@ loop do
end end
end end
# Check ready pool # Check 'ready' pool
$redis.smembers('vmware_host_pool__ready__'+pool['name']).each do |vm| $redis.smembers('vmware_host_pool__ready__'+pool['name']).each do |vm|
if ! inventory[vm] if ! inventory[vm]
$redis.srem('vmware_host_pool__ready__'+pool['name'], vm) $redis.srem('vmware_host_pool__ready__'+pool['name'], vm)