mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 18:08:42 -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")
|
$logger.log('s', "[+] [#{pool_name}] '#{new_vmname}' cloned in #{finish} seconds")
|
||||||
|
|
||||||
$metrics.timing("clone.#{pool_name}", finish)
|
$metrics.timing("clone.#{pool_name}", finish)
|
||||||
rescue => err
|
rescue => _err
|
||||||
$logger.log('s', "[!] [#{pool_name}] '#{new_vmname}' clone failed with an error: #{err}")
|
|
||||||
$redis.srem('vmpooler__pending__' + pool_name, new_vmname)
|
$redis.srem('vmpooler__pending__' + pool_name, new_vmname)
|
||||||
raise
|
raise _err
|
||||||
ensure
|
ensure
|
||||||
$redis.decr('vmpooler__tasks__clone')
|
$redis.decr('vmpooler__tasks__clone')
|
||||||
end
|
end
|
||||||
|
|
@ -712,9 +711,6 @@ module Vmpooler
|
||||||
end
|
end
|
||||||
|
|
||||||
pool_check_response
|
pool_check_response
|
||||||
rescue => err
|
|
||||||
$logger.log('d', "[!] [#{pool['name']}] _check_pool failed with an error: #{err}")
|
|
||||||
raise
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create a provider object, usually based on the providers/*.rb class, that implements providers/base.rb
|
# 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}"
|
dc = "#{datacenter}_#{cluster}"
|
||||||
@provider_hosts_lock.synchronize do
|
@provider_hosts_lock.synchronize do
|
||||||
if architecture
|
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
|
host = target[dc]['architectures'][architecture].shift
|
||||||
target[dc]['architectures'][architecture] << host
|
target[dc]['architectures'][architecture] << host
|
||||||
if target[dc]['hosts'].include?(host)
|
if target[dc]['hosts'].include?(host)
|
||||||
|
|
@ -131,7 +131,7 @@ module Vmpooler
|
||||||
end
|
end
|
||||||
return host
|
return host
|
||||||
else
|
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
|
host = target[dc]['hosts'].shift
|
||||||
target[dc]['hosts'] << host
|
target[dc]['hosts'] << host
|
||||||
target[dc]['architectures'].each do |arch|
|
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("cluster for pool #{pool_name} cannot be identified") if cluster.nil?
|
||||||
raise("datacenter for pool #{pool_name} cannot be identified") if datacenter.nil?
|
raise("datacenter for pool #{pool_name} cannot be identified") if datacenter.nil?
|
||||||
dc = "#{datacenter}_#{cluster}"
|
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 true if target[dc]['architectures'][architecture].include?(parent_host)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
@ -699,7 +699,7 @@ module Vmpooler
|
||||||
cluster_object = find_cluster(cluster, connection, datacentername)
|
cluster_object = find_cluster(cluster, connection, datacentername)
|
||||||
raise("Cluster #{cluster} cannot be found") if cluster_object.nil?
|
raise("Cluster #{cluster} cannot be found") if cluster_object.nil?
|
||||||
target_hosts = get_cluster_host_utilization(cluster_object)
|
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)
|
architectures = build_compatible_hosts_lists(target_hosts, percentage)
|
||||||
least_used_hosts = select_least_used_hosts(target_hosts, percentage)
|
least_used_hosts = select_least_used_hosts(target_hosts, percentage)
|
||||||
{
|
{
|
||||||
|
|
@ -892,6 +892,7 @@ module Vmpooler
|
||||||
|
|
||||||
def migrate_vm(pool_name, vm_name)
|
def migrate_vm(pool_name, vm_name)
|
||||||
@connection_pool.with_metrics do |pool_object|
|
@connection_pool.with_metrics do |pool_object|
|
||||||
|
begin
|
||||||
connection = ensured_vsphere_connection(pool_object)
|
connection = ensured_vsphere_connection(pool_object)
|
||||||
vm_hash = get_vm_details(vm_name, connection)
|
vm_hash = get_vm_details(vm_name, connection)
|
||||||
migration_limit = @config[:config]['migration_limit'] if @config[:config].key?('migration_limit')
|
migration_limit = @config[:config]['migration_limit'] if @config[:config].key?('migration_limit')
|
||||||
|
|
@ -907,6 +908,12 @@ module Vmpooler
|
||||||
else
|
else
|
||||||
migrate_vm_to_new_host(pool_name, vm_name, vm_hash, connection)
|
migrate_vm_to_new_host(pool_name, vm_name, vm_hash, connection)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue