From e8125e7702ebb0f0dfd2604c27331896141ced54 Mon Sep 17 00:00:00 2001 From: Scott Schneider Date: Mon, 28 Jul 2014 10:51:45 -0700 Subject: [PATCH 1/2] Allow a 'clone_target' configuration setting If set, this setting will enable "fake DRS", cloning VMs onto the host in the specified cluster containing the least amount of VMs. --- lib/vmpooler/pool_manager.rb | 6 ++++++ lib/vmpooler/vsphere_helper.rb | 24 ++++++++++++++++++++++++ vmpooler.yaml.example | 4 ++++ 3 files changed, 34 insertions(+) diff --git a/lib/vmpooler/pool_manager.rb b/lib/vmpooler/pool_manager.rb index ee93fb4..f9ba48b 100644 --- a/lib/vmpooler/pool_manager.rb +++ b/lib/vmpooler/pool_manager.rb @@ -195,9 +195,15 @@ module Vmpooler }) ) + # Choose a clone target + if ($config[:config]['clone_target'] + $clone_target = $vsphere[vm['template']].find_least_used_host($config[:config]['clone_target']) + end + # Put the VM in the specified folder and resource pool relocateSpec = RbVmomi::VIM.VirtualMachineRelocateSpec( :datastore => $vsphere[vm['template']].find_datastore(datastore), + :host => $clone_target, :diskMoveType => :moveChildMostDiskBacking ) diff --git a/lib/vmpooler/vsphere_helper.rb b/lib/vmpooler/vsphere_helper.rb index 402530b..c9edb67 100644 --- a/lib/vmpooler/vsphere_helper.rb +++ b/lib/vmpooler/vsphere_helper.rb @@ -51,6 +51,30 @@ module Vmpooler + def find_least_used_host cluster + begin + @connection.serviceInstance.CurrentTime + rescue + initialize() + end + + hosts = Hash.new + hosts_sort = Hash.new + + datacenter = @connection.serviceInstance.find_datacenter + datacenter.hostFolder.children.each do |folder| + next unless folder.name == cluster + folder.host.each do |host| + hosts[host.name] = host + hosts_sort[host.name] = host.vm.length + end + end + + hosts[hosts_sort.sort_by { |k,v| v }[0][0]] + end + + + def find_pool poolname begin @connection.serviceInstance.CurrentTime diff --git a/vmpooler.yaml.example b/vmpooler.yaml.example index 0e06c08..4e877d2 100644 --- a/vmpooler.yaml.example +++ b/vmpooler.yaml.example @@ -83,6 +83,10 @@ # The path to vmpooler's log file. # (optional; default: '/var/log/vmpooler.log') # +# - clone_target +# The target cluster VMs are cloned into (host with least VMs chosen) +# (optional; default: same cluster/host as origin template) +# # - task_limit # The number of concurrent VMware vSphere tasks to perform. # (optional; default: '10') From 76ef04c100903a7a24d8aafad5768d68614c4334 Mon Sep 17 00:00:00 2001 From: Scott Schneider Date: Mon, 28 Jul 2014 10:55:42 -0700 Subject: [PATCH 2/2] Fixing typo --- lib/vmpooler/pool_manager.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vmpooler/pool_manager.rb b/lib/vmpooler/pool_manager.rb index f9ba48b..944c79e 100644 --- a/lib/vmpooler/pool_manager.rb +++ b/lib/vmpooler/pool_manager.rb @@ -196,7 +196,7 @@ module Vmpooler ) # Choose a clone target - if ($config[:config]['clone_target'] + if ($config[:config]['clone_target']) $clone_target = $vsphere[vm['template']].find_least_used_host($config[:config]['clone_target']) end