Reordering API operatiosn for quicker response-times

This commit is contained in:
Scott Schneider 2013-09-24 16:30:33 -07:00
parent 545792dece
commit ce79fcfa0f
2 changed files with 14 additions and 15 deletions

View file

@ -4,7 +4,7 @@ require 'rbvmomi'
require 'redis' require 'redis'
require 'yaml' require 'yaml'
require File.expand_path( File.dirname( __FILE__ ), './lib/vsphere_helper.rb' ) require File.expand_path( File.dirname( __FILE__ ), 'lib/vsphere_helper.rb' )
vsphere_helper = VsphereHelper.new vsphere_helper = VsphereHelper.new
# Load the pool configuration # Load the pool configuration
@ -27,8 +27,7 @@ $vim = RbVmomi::VIM.connect(
# Connect to Redis # Connect to Redis
$redis = Redis.new $redis = Redis.new
# Update loop
loop do loop do
pools.each do |pool| pools.each do |pool|
total = 0 total = 0

View file

@ -49,22 +49,22 @@ post '/vm/:template' do
if ( ( ! params[:folder] ) or ( ! params[:pool] )) if ( ( ! params[:folder] ) or ( ! params[:pool] ))
result[params[:template]]['error'] = 'You must specify a destination \'folder\' and \'pool\'' result[params[:template]]['error'] = 'You must specify a destination \'folder\' and \'pool\''
else else
datacenter = $vim.serviceInstance.find_datacenter vm = $redis.srandmember('vmware_host_pool-'+params[:template])
base = datacenter.hostFolder $redis.srem('vmware_host_pool-'+params[:template], vm)
# Move the VM to the specified folder and resource pool datacenter = $vim.serviceInstance.find_datacenter
relocateSpec = RbVmomi::VIM.VirtualMachineRelocateSpec( base = datacenter.hostFolder
:pool => vsphere_helper.find_pool(params[:pool])
)
vm = $redis.srandmember('vmware_host_pool-'+params[:template]) # Move the VM to the specified folder and resource pool
$redis.srem('vmware_host_pool-'+params[:template], vm) relocateSpec = RbVmomi::VIM.VirtualMachineRelocateSpec(
:pool => vsphere_helper.find_pool(params[:pool])
)
vm = vsphere_helper.find_vms(vm)[vm] vm = vsphere_helper.find_vms(vm)[vm]
vm.RelocateVM_Task(:spec => relocateSpec).wait_for_completion vm.RelocateVM_Task(:spec => relocateSpec)
result[params[:template]]['ok'] = 'true' result[params[:template]]['ok'] = 'true'
result[params[:template]]['hostname'] = vm['name'] result[params[:template]]['hostname'] = vm['name']
end end
result.to_json result.to_json