mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Remove unnecessary rescue
This commit removes an unnecessary rescue that results in duplicate clone error messages. Without this change clone failures due to unavailable host resources are logged twice. A log message is added to specify the host the VM is running on when migration_limit is not set and migration is disabled. Lastly, when a migration fails it reports the host the VM is running on in addition to the reason for the failed migration.
This commit is contained in:
parent
82b9033e83
commit
048ab4433a
2 changed files with 26 additions and 23 deletions
|
|
@ -224,10 +224,9 @@ module Vmpooler
|
|||
$logger.log('s', "[+] [#{pool_name}] '#{new_vmname}' cloned in #{finish} seconds")
|
||||
|
||||
$metrics.timing("clone.#{pool_name}", finish)
|
||||
rescue => err
|
||||
$logger.log('s', "[!] [#{pool_name}] '#{new_vmname}' clone failed with an error: #{err}")
|
||||
rescue => _err
|
||||
$redis.srem('vmpooler__pending__' + pool_name, new_vmname)
|
||||
raise
|
||||
raise _err
|
||||
ensure
|
||||
$redis.decr('vmpooler__tasks__clone')
|
||||
end
|
||||
|
|
@ -712,9 +711,6 @@ module Vmpooler
|
|||
end
|
||||
|
||||
pool_check_response
|
||||
rescue => err
|
||||
$logger.log('d', "[!] [#{pool['name']}] _check_pool failed with an error: #{err}")
|
||||
raise
|
||||
end
|
||||
|
||||
# Create a provider object, usually based on the providers/*.rb class, that implements providers/base.rb
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ module Vmpooler
|
|||
dc = "#{datacenter}_#{cluster}"
|
||||
@provider_hosts_lock.synchronize do
|
||||
if architecture
|
||||
raise("there is no candidate in vcenter that meets all the required conditions, that that the cluster has available hosts in a 'green' status, not in maintenance mode and not overloaded CPU and memory") unless target[dc].key?('architectures')
|
||||
raise("there is no candidate in vcenter that meets all the required conditions, that the cluster has available hosts in a 'green' status, not in maintenance mode and not overloaded CPU and memory") unless target[dc].key?('architectures')
|
||||
host = target[dc]['architectures'][architecture].shift
|
||||
target[dc]['architectures'][architecture] << host
|
||||
if target[dc]['hosts'].include?(host)
|
||||
|
|
@ -131,7 +131,7 @@ module Vmpooler
|
|||
end
|
||||
return host
|
||||
else
|
||||
raise("there is no candidate in vcenter that meets all the required conditions, that that the cluster has available hosts in a 'green' status, not in maintenance mode and not overloaded CPU and memory") unless target[dc].key?('hosts')
|
||||
raise("there is no candidate in vcenter that meets all the required conditions, that the cluster has available hosts in a 'green' status, not in maintenance mode and not overloaded CPU and memory") unless target[dc].key?('hosts')
|
||||
host = target[dc]['hosts'].shift
|
||||
target[dc]['hosts'] << host
|
||||
target[dc]['architectures'].each do |arch|
|
||||
|
|
@ -150,7 +150,7 @@ module Vmpooler
|
|||
raise("cluster for pool #{pool_name} cannot be identified") if cluster.nil?
|
||||
raise("datacenter for pool #{pool_name} cannot be identified") if datacenter.nil?
|
||||
dc = "#{datacenter}_#{cluster}"
|
||||
raise("there is no candidate in vcenter that meets all the required conditions, that that the cluster has available hosts in a 'green' status, not in maintenance mode and not overloaded CPU and memory") unless target[dc].key?('hosts')
|
||||
raise("there is no candidate in vcenter that meets all the required conditions, that the cluster has available hosts in a 'green' status, not in maintenance mode and not overloaded CPU and memory") unless target[dc].key?('hosts')
|
||||
return true if target[dc]['architectures'][architecture].include?(parent_host)
|
||||
return false
|
||||
end
|
||||
|
|
@ -699,7 +699,7 @@ module Vmpooler
|
|||
cluster_object = find_cluster(cluster, connection, datacentername)
|
||||
raise("Cluster #{cluster} cannot be found") if cluster_object.nil?
|
||||
target_hosts = get_cluster_host_utilization(cluster_object)
|
||||
raise("there is no candidate in vcenter that meets all the required conditions, that that the cluster has available hosts in a 'green' status, not in maintenance mode and not overloaded CPU and memory'") if target_hosts.nil?
|
||||
raise("there is no candidate in vcenter that meets all the required conditions, that the cluster has available hosts in a 'green' status, not in maintenance mode and not overloaded CPU and memory'") if target_hosts.empty?
|
||||
architectures = build_compatible_hosts_lists(target_hosts, percentage)
|
||||
least_used_hosts = select_least_used_hosts(target_hosts, percentage)
|
||||
{
|
||||
|
|
@ -892,21 +892,28 @@ module Vmpooler
|
|||
|
||||
def migrate_vm(pool_name, vm_name)
|
||||
@connection_pool.with_metrics do |pool_object|
|
||||
connection = ensured_vsphere_connection(pool_object)
|
||||
vm_hash = get_vm_details(vm_name, connection)
|
||||
migration_limit = @config[:config]['migration_limit'] if @config[:config].key?('migration_limit')
|
||||
migration_count = $redis.scard('vmpooler__migration')
|
||||
if migration_enabled? @config
|
||||
if migration_count >= migration_limit
|
||||
logger.log('s', "[ ] [#{pool_name}] '#{vm_name}' is running on #{vm_hash['host_name']}. No migration will be evaluated since the migration_limit has been reached")
|
||||
return
|
||||
end
|
||||
run_select_hosts(pool_name, @provider_hosts)
|
||||
if vm_in_target?(pool_name, vm_hash['host_name'], vm_hash['architecture'], @provider_hosts)
|
||||
logger.log('s', "[ ] [#{pool_name}] No migration required for '#{vm_name}' running on #{vm_hash['host_name']}")
|
||||
begin
|
||||
connection = ensured_vsphere_connection(pool_object)
|
||||
vm_hash = get_vm_details(vm_name, connection)
|
||||
migration_limit = @config[:config]['migration_limit'] if @config[:config].key?('migration_limit')
|
||||
migration_count = $redis.scard('vmpooler__migration')
|
||||
if migration_enabled? @config
|
||||
if migration_count >= migration_limit
|
||||
logger.log('s', "[ ] [#{pool_name}] '#{vm_name}' is running on #{vm_hash['host_name']}. No migration will be evaluated since the migration_limit has been reached")
|
||||
return
|
||||
end
|
||||
run_select_hosts(pool_name, @provider_hosts)
|
||||
if vm_in_target?(pool_name, vm_hash['host_name'], vm_hash['architecture'], @provider_hosts)
|
||||
logger.log('s', "[ ] [#{pool_name}] No migration required for '#{vm_name}' running on #{vm_hash['host_name']}")
|
||||
else
|
||||
migrate_vm_to_new_host(pool_name, vm_name, vm_hash, connection)
|
||||
end
|
||||
else
|
||||
migrate_vm_to_new_host(pool_name, vm_name, vm_hash, connection)
|
||||
logger.log('s', "[ ] [#{pool_name}] '#{vm_name}' is running on #{vm_hash['host_name']}")
|
||||
end
|
||||
rescue => _err
|
||||
logger.log('s', "[!] [#{pool_name}] '#{vm_name}' is running on #{vm_hash['host_name']}")
|
||||
raise _err
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue