mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
Add delete_record
This commit is contained in:
parent
ac96550f57
commit
65f04254a8
3 changed files with 43 additions and 4 deletions
|
|
@ -30,6 +30,24 @@ module Vmpooler
|
|||
plugin_class
|
||||
end
|
||||
|
||||
# Returns the plugin domain for the specified dns config by name
|
||||
#
|
||||
# @param config [Object] The entire VMPooler config object
|
||||
# @param name [Symbol] The name of the dns config key to get the dns domain
|
||||
# @return [String] The domain for the specifid dns config
|
||||
def self.get_dns_plugin_domain_by_name(config, name)
|
||||
dns_configs = config[:dns_configs].keys
|
||||
plugin_domain = ''
|
||||
|
||||
dns_configs.map do |dns_config_name|
|
||||
if dns_config_name.to_s == name
|
||||
plugin_domain = config[:dns_configs][dns_config_name]['domain']
|
||||
end
|
||||
end
|
||||
|
||||
plugin_domain
|
||||
end
|
||||
|
||||
# Returns a list of DNS plugin classes specified in the vmpooler configuration
|
||||
#
|
||||
# @param config [Object] The entire VMPooler config object
|
||||
|
|
|
|||
|
|
@ -63,6 +63,10 @@ module Vmpooler
|
|||
def create_or_replace_record(hostname)
|
||||
raise("#{self.class.name} does not implement create_or_replace_record")
|
||||
end
|
||||
|
||||
def delete_record(hostname)
|
||||
raise("#{self.class.name} does not implement delete_record")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -113,6 +113,10 @@ module Vmpooler
|
|||
|
||||
def remove_nonexistent_vm(vm, pool, redis)
|
||||
redis.srem("vmpooler__pending__#{pool}", vm)
|
||||
dns_plugin = get_dns_plugin_class_for_pool(pool)
|
||||
domain = get_dns_plugin_domain_for_pool(pool)
|
||||
fqdn = vm + '.' + domain
|
||||
dns_plugin.delete_record(fqdn)
|
||||
$logger.log('d', "[!] [#{pool}] '#{vm}' no longer exists. Removing from pending.")
|
||||
end
|
||||
|
||||
|
|
@ -475,10 +479,10 @@ module Vmpooler
|
|||
end
|
||||
|
||||
# Destroy a VM
|
||||
def destroy_vm(vm, pool, provider)
|
||||
def destroy_vm(vm, pool, provider, dns_plugin)
|
||||
Thread.new do
|
||||
begin
|
||||
_destroy_vm(vm, pool, provider)
|
||||
_destroy_vm(vm, pool, provider, dns_plugin)
|
||||
rescue StandardError => e
|
||||
$logger.log('d', "[!] [#{pool}] '#{vm}' failed while destroying the VM with an error: #{e}")
|
||||
raise
|
||||
|
|
@ -486,7 +490,7 @@ module Vmpooler
|
|||
end
|
||||
end
|
||||
|
||||
def _destroy_vm(vm, pool, provider)
|
||||
def _destroy_vm(vm, pool, provider, dns_plugin)
|
||||
mutex = vm_mutex(vm)
|
||||
return if mutex.locked?
|
||||
|
||||
|
|
@ -503,6 +507,9 @@ module Vmpooler
|
|||
start = Time.now
|
||||
|
||||
provider.destroy_vm(pool, vm)
|
||||
domain = get_dns_plugin_domain_for_pool(pool)
|
||||
fqdn = vm + '.' + domain
|
||||
dns_plugin.delete_record(fqdn)
|
||||
|
||||
redis.srem("vmpooler__completed__#{pool}", vm)
|
||||
|
||||
|
|
@ -703,6 +710,15 @@ module Vmpooler
|
|||
$dns_plugins[plugin_class]
|
||||
end
|
||||
|
||||
def get_dns_plugin_domain_for_pool(pool_name)
|
||||
pool = $config[:pools].find { |p| p['name'] == pool_name }
|
||||
return nil unless pool
|
||||
|
||||
plugin_name = pool.fetch('dns_plugin')
|
||||
plugin_domain = Vmpooler::Dns.get_dns_plugin_domain_by_name(config, plugin_name)
|
||||
plugin_domain
|
||||
end
|
||||
|
||||
def check_disk_queue(maxloop = 0, loop_delay = 5)
|
||||
$logger.log('d', '[*] [disk_manager] starting worker thread')
|
||||
|
||||
|
|
@ -1247,7 +1263,8 @@ module Vmpooler
|
|||
if inventory[vm]
|
||||
begin
|
||||
pool_check_response[:destroyed_vms] += 1
|
||||
destroy_vm(vm, pool_name, provider)
|
||||
dns_plugin = get_dns_plugin_class_for_pool(pool_name)
|
||||
destroy_vm(vm, pool_name, provider, dns_plugin)
|
||||
rescue StandardError => e
|
||||
redis.pipelined do |pipeline|
|
||||
pipeline.srem("vmpooler__completed__#{pool_name}", vm)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue