mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-27 10:28:41 -05:00
(POOLER-50) Remove VM migration code
The migrate_vm code introduced in commit 705e5d26d8 caused errors
and has since been found to be problematic. This commit removes the changes
introduced as part of PR 167 that peratin to the migrate_vm code.
This commit is contained in:
parent
850919f5db
commit
ddbc8f5046
6 changed files with 2 additions and 505 deletions
|
|
@ -55,7 +55,6 @@ module Vmpooler
|
|||
|
||||
def account_for_starting_vm(template, vm)
|
||||
backend.sadd('vmpooler__running__' + template, vm)
|
||||
backend.sadd('vmpooler__migrating__' + template, vm)
|
||||
backend.hset('vmpooler__active__' + template, vm, Time.now)
|
||||
backend.hset('vmpooler__vm__' + vm, 'checkout', Time.now)
|
||||
|
||||
|
|
|
|||
|
|
@ -498,77 +498,6 @@ module Vmpooler
|
|||
end
|
||||
end
|
||||
|
||||
def migration_limit(migration_limit)
|
||||
# Returns migration_limit setting when enabled
|
||||
return false if migration_limit == 0 || ! migration_limit
|
||||
migration_limit if migration_limit >= 1
|
||||
end
|
||||
|
||||
def migrate_vm(vm, pool, vsphere)
|
||||
Thread.new do
|
||||
_migrate_vm(vm, pool, vsphere)
|
||||
end
|
||||
end
|
||||
|
||||
def _migrate_vm(vm, pool, vsphere)
|
||||
begin
|
||||
$redis.srem('vmpooler__migrating__' + pool, vm)
|
||||
vm_object = vsphere.find_vm(vm)
|
||||
parent_host, parent_host_name = get_vm_host_info(vm_object)
|
||||
migration_limit = migration_limit $config[:config]['migration_limit']
|
||||
migration_count = $redis.scard('vmpooler__migration')
|
||||
|
||||
if ! migration_limit
|
||||
$logger.log('s', "[ ] [#{pool}] '#{vm}' is running on #{parent_host_name}")
|
||||
return
|
||||
else
|
||||
if migration_count >= migration_limit
|
||||
$logger.log('s', "[ ] [#{pool}] '#{vm}' is running on #{parent_host_name}. No migration will be evaluated since the migration_limit has been reached")
|
||||
return
|
||||
else
|
||||
$redis.sadd('vmpooler__migration', vm)
|
||||
host, host_name = vsphere.find_least_used_compatible_host(vm_object)
|
||||
if host == parent_host
|
||||
$logger.log('s', "[ ] [#{pool}] No migration required for '#{vm}' running on #{parent_host_name}")
|
||||
else
|
||||
finish = migrate_vm_and_record_timing(vm_object, vm, pool, host, parent_host_name, host_name, vsphere)
|
||||
$logger.log('s', "[>] [#{pool}] '#{vm}' migrated from #{parent_host_name} to #{host_name} in #{finish} seconds")
|
||||
end
|
||||
remove_vmpooler_migration_vm(pool, vm)
|
||||
end
|
||||
end
|
||||
rescue => err
|
||||
$logger.log('s', "[x] [#{pool}] '#{vm}' migration failed with an error: #{err}")
|
||||
remove_vmpooler_migration_vm(pool, vm)
|
||||
end
|
||||
end
|
||||
|
||||
def get_vm_host_info(vm_object)
|
||||
parent_host = vm_object.summary.runtime.host
|
||||
[parent_host, parent_host.name]
|
||||
end
|
||||
|
||||
def remove_vmpooler_migration_vm(pool, vm)
|
||||
begin
|
||||
$redis.srem('vmpooler__migration', vm)
|
||||
rescue => err
|
||||
$logger.log('s', "[x] [#{pool}] '#{vm}' removal from vmpooler__migration failed with an error: #{err}")
|
||||
end
|
||||
end
|
||||
|
||||
def migrate_vm_and_record_timing(vm_object, vm_name, pool, host, source_host_name, dest_host_name, vsphere)
|
||||
start = Time.now
|
||||
vsphere.migrate_vm_host(vm_object, host)
|
||||
finish = '%.2f' % (Time.now - start)
|
||||
$metrics.timing("migrate.#{pool}", finish)
|
||||
$metrics.increment("migrate_from.#{source_host_name}")
|
||||
$metrics.increment("migrate_to.#{dest_host_name}")
|
||||
checkout_to_migration = '%.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}", 'checkout_to_migration', checkout_to_migration)
|
||||
finish
|
||||
end
|
||||
|
||||
def check_pool(pool,maxloop = 0, loop_delay = 5)
|
||||
$logger.log('d', "[*] [#{pool['name']}] starting worker thread")
|
||||
|
||||
|
|
@ -601,7 +530,6 @@ module Vmpooler
|
|||
(! $redis.sismember('vmpooler__pending__' + pool['name'], vm['name'])) &&
|
||||
(! $redis.sismember('vmpooler__completed__' + pool['name'], vm['name'])) &&
|
||||
(! $redis.sismember('vmpooler__discovered__' + pool['name'], vm['name'])) &&
|
||||
(! $redis.sismember('vmpooler__migrating__' + pool['name'], vm['name']))
|
||||
|
||||
$redis.sadd('vmpooler__discovered__' + pool['name'], vm['name'])
|
||||
|
||||
|
|
@ -688,17 +616,6 @@ module Vmpooler
|
|||
$logger.log('d', "[!] [#{pool['name']}] _check_pool failed with an error while evaluating discovered VMs: #{err}")
|
||||
end
|
||||
|
||||
# MIGRATIONS
|
||||
$redis.smembers("vmpooler__migrating__#{pool['name']}").each do |vm|
|
||||
if inventory[vm]
|
||||
begin
|
||||
migrate_vm(vm, pool['name'], vsphere)
|
||||
rescue => err
|
||||
$logger.log('s', "[x] [#{pool['name']}] '#{vm}' failed to migrate: #{err}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# REPOPULATE
|
||||
ready = $redis.scard("vmpooler__ready__#{pool['name']}")
|
||||
total = $redis.scard("vmpooler__pending__#{pool['name']}") + ready
|
||||
|
|
@ -741,8 +658,6 @@ module Vmpooler
|
|||
|
||||
# Clear out the tasks manager, as we don't know about any tasks at this point
|
||||
$redis.set('vmpooler__tasks__clone', 0)
|
||||
# Clear out vmpooler__migrations since stale entries may be left after a restart
|
||||
$redis.del('vmpooler__migration')
|
||||
|
||||
loop_count = 1
|
||||
loop do
|
||||
|
|
|
|||
|
|
@ -190,87 +190,11 @@ module Vmpooler
|
|||
base
|
||||
end
|
||||
|
||||
# Returns an array containing cumulative CPU and memory utilization of a host, and its object reference
|
||||
# Params:
|
||||
# +model+:: CPU arch version to match on
|
||||
# +limit+:: Hard limit for CPU or memory utilization beyond which a host is excluded for deployments
|
||||
def get_host_utilization(host, model=nil, limit=90)
|
||||
if model
|
||||
return nil unless host_has_cpu_model? host, model
|
||||
end
|
||||
return nil if host.runtime.inMaintenanceMode
|
||||
return nil unless host.overallStatus == 'green'
|
||||
|
||||
cpu_utilization = cpu_utilization_for host
|
||||
memory_utilization = memory_utilization_for host
|
||||
|
||||
return nil if cpu_utilization > limit
|
||||
return nil if memory_utilization > limit
|
||||
|
||||
[ cpu_utilization + memory_utilization, host ]
|
||||
end
|
||||
|
||||
def host_has_cpu_model?(host, model)
|
||||
get_host_cpu_arch_version(host) == model
|
||||
end
|
||||
|
||||
def get_host_cpu_arch_version(host)
|
||||
cpu_model = host.hardware.cpuPkg[0].description
|
||||
cpu_model_parts = cpu_model.split()
|
||||
arch_version = cpu_model_parts[4]
|
||||
arch_version
|
||||
end
|
||||
|
||||
def cpu_utilization_for(host)
|
||||
cpu_usage = host.summary.quickStats.overallCpuUsage
|
||||
cpu_size = host.summary.hardware.cpuMhz * host.summary.hardware.numCpuCores
|
||||
(cpu_usage.to_f / cpu_size.to_f) * 100
|
||||
end
|
||||
|
||||
def memory_utilization_for(host)
|
||||
memory_usage = host.summary.quickStats.overallMemoryUsage
|
||||
memory_size = host.summary.hardware.memorySize / 1024 / 1024
|
||||
(memory_usage.to_f / memory_size.to_f) * 100
|
||||
end
|
||||
|
||||
def find_least_used_host(cluster)
|
||||
ensure_connected @connection, $credentials
|
||||
|
||||
cluster_object = find_cluster(cluster)
|
||||
target_hosts = get_cluster_host_utilization(cluster_object)
|
||||
least_used_host = target_hosts.sort[0][1]
|
||||
least_used_host
|
||||
end
|
||||
|
||||
def find_cluster(cluster)
|
||||
datacenter = @connection.serviceInstance.find_datacenter
|
||||
datacenter.hostFolder.children.find { |cluster_object| cluster_object.name == cluster }
|
||||
end
|
||||
|
||||
def get_cluster_host_utilization(cluster)
|
||||
cluster_hosts = []
|
||||
cluster.host.each do |host|
|
||||
host_usage = get_host_utilization(host)
|
||||
cluster_hosts << host_usage if host_usage
|
||||
end
|
||||
cluster_hosts
|
||||
end
|
||||
|
||||
def find_least_used_compatible_host(vm)
|
||||
ensure_connected @connection, $credentials
|
||||
|
||||
source_host = vm.summary.runtime.host
|
||||
model = get_host_cpu_arch_version(source_host)
|
||||
cluster = source_host.parent
|
||||
target_hosts = []
|
||||
cluster.host.each do |host|
|
||||
host_usage = get_host_utilization(host, model)
|
||||
target_hosts << host_usage if host_usage
|
||||
end
|
||||
target_host = target_hosts.sort[0][1]
|
||||
[target_host, target_host.name]
|
||||
end
|
||||
|
||||
def find_pool(poolname)
|
||||
ensure_connected @connection, $credentials
|
||||
|
||||
|
|
@ -405,11 +329,6 @@ module Vmpooler
|
|||
snapshot
|
||||
end
|
||||
|
||||
def migrate_vm_host(vm, host)
|
||||
relospec = RbVmomi::VIM.VirtualMachineRelocateSpec(host: host)
|
||||
vm.RelocateVM_Task(spec: relospec).wait_for_completion
|
||||
end
|
||||
|
||||
def close
|
||||
@connection.close
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue