mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
Stub out dns provider usage
This commit is contained in:
parent
16d23a0226
commit
ac96550f57
5 changed files with 300 additions and 6 deletions
|
|
@ -1,5 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'vmpooler/dns'
|
||||
require 'vmpooler/providers'
|
||||
require 'vmpooler/util/parsing'
|
||||
require 'spicy-proton'
|
||||
|
|
@ -26,6 +27,9 @@ module Vmpooler
|
|||
# VM Provider objects
|
||||
$providers = Concurrent::Hash.new
|
||||
|
||||
# VM DNS objects
|
||||
$dns_plugins = Concurrent::Hash.new
|
||||
|
||||
# Our thread-tracker object
|
||||
$threads = Concurrent::Hash.new
|
||||
|
||||
|
|
@ -39,6 +43,9 @@ module Vmpooler
|
|||
|
||||
# load specified providers from config file
|
||||
load_used_providers
|
||||
|
||||
# load specified dns plugins from config file
|
||||
load_used_dns_plugins
|
||||
end
|
||||
|
||||
def config
|
||||
|
|
@ -323,10 +330,10 @@ module Vmpooler
|
|||
end
|
||||
|
||||
# Clone a VM
|
||||
def clone_vm(pool_name, provider, request_id = nil, pool_alias = nil)
|
||||
def clone_vm(pool_name, provider, dns_plugin, request_id = nil, pool_alias = nil)
|
||||
Thread.new do
|
||||
begin
|
||||
_clone_vm(pool_name, provider, request_id, pool_alias)
|
||||
_clone_vm(pool_name, provider, dns_plugin, request_id, pool_alias)
|
||||
rescue StandardError => e
|
||||
if request_id
|
||||
$logger.log('s', "[!] [#{pool_name}] failed while cloning VM for request #{request_id} with an error: #{e}")
|
||||
|
|
@ -414,7 +421,7 @@ module Vmpooler
|
|||
[dns_ip, false]
|
||||
end
|
||||
|
||||
def _clone_vm(pool_name, provider, request_id = nil, pool_alias = nil)
|
||||
def _clone_vm(pool_name, provider, dns_plugin, request_id = nil, pool_alias = nil)
|
||||
new_vmname = find_unique_hostname(pool_name)
|
||||
pool_domain = Parsing.get_domain_for_pool(config, pool_name)
|
||||
mutex = vm_mutex(new_vmname)
|
||||
|
|
@ -447,6 +454,8 @@ module Vmpooler
|
|||
$logger.log('s', "[+] [#{pool_name}] '#{new_vmname}' cloned in #{finish} seconds")
|
||||
|
||||
$metrics.timing("clone.#{pool_name}", finish)
|
||||
|
||||
dns_plugin.create_or_replace_record(new_vmname)
|
||||
rescue StandardError
|
||||
@redis.with_metrics do |redis|
|
||||
redis.pipelined do |pipeline|
|
||||
|
|
@ -632,6 +641,12 @@ module Vmpooler
|
|||
result
|
||||
end
|
||||
|
||||
# load only dns plugins used in config file
|
||||
def load_used_dns_plugins
|
||||
dns_plugins = Vmpooler::Dns.get_dns_plugin_config_classes(config)
|
||||
Vmpooler::Dns.load_by_name(dns_plugins)
|
||||
end
|
||||
|
||||
# load only providers used in config file
|
||||
def load_used_providers
|
||||
Vmpooler::Providers.load_by_name(used_providers)
|
||||
|
|
@ -679,6 +694,15 @@ module Vmpooler
|
|||
$providers[provider_name]
|
||||
end
|
||||
|
||||
def get_dns_plugin_class_for_pool(pool_name)
|
||||
pool = $config[:pools].find { |p| p['name'] == pool_name }
|
||||
return nil unless pool
|
||||
|
||||
plugin_name = pool.fetch('dns_plugin')
|
||||
plugin_class = Vmpooler::Dns.get_dns_plugin_class_by_name(config, plugin_name)
|
||||
$dns_plugins[plugin_class]
|
||||
end
|
||||
|
||||
def check_disk_queue(maxloop = 0, loop_delay = 5)
|
||||
$logger.log('d', '[*] [disk_manager] starting worker thread')
|
||||
|
||||
|
|
@ -1290,6 +1314,8 @@ module Vmpooler
|
|||
$metrics.gauge("ready.#{pool_name}", ready)
|
||||
$metrics.gauge("running.#{pool_name}", running)
|
||||
|
||||
dns_plugin = get_dns_plugin_class_for_pool(pool_name)
|
||||
|
||||
unless pool_size == 0
|
||||
if redis.get("vmpooler__empty__#{pool_name}")
|
||||
redis.del("vmpooler__empty__#{pool_name}") unless ready == 0
|
||||
|
|
@ -1304,7 +1330,7 @@ module Vmpooler
|
|||
begin
|
||||
redis.incr('vmpooler__tasks__clone')
|
||||
pool_check_response[:cloned_vms] += 1
|
||||
clone_vm(pool_name, provider)
|
||||
clone_vm(pool_name, provider, dns_plugin)
|
||||
rescue StandardError => e
|
||||
$logger.log('s', "[!] [#{pool_name}] clone failed during check_pool with an error: #{e}")
|
||||
redis.decr('vmpooler__tasks__clone')
|
||||
|
|
@ -1390,6 +1416,16 @@ module Vmpooler
|
|||
raise("Provider '#{provider_class}' is unknown for pool with provider name '#{provider_name}'") if provider_klass.nil?
|
||||
end
|
||||
|
||||
def create_dns_object(config, logger, metrics, redis_connection_pool, dns_class, dns_name, options)
|
||||
dns_klass = Vmpooler::PoolManager::Dns
|
||||
dns_klass.constants.each do |classname|
|
||||
next unless classname.to_s.casecmp(dns_class) == 0
|
||||
|
||||
return dns_klass.const_get(classname).new(config, logger, metrics, redis_connection_pool, dns_name, options)
|
||||
end
|
||||
raise("DNS '#{dns_class}' is unknown for pool with dns name '#{dns_name}'") if dns_klass.nil?
|
||||
end
|
||||
|
||||
def check_ondemand_requests(maxloop = 0,
|
||||
loop_delay_min = CHECK_LOOP_DELAY_MIN_DEFAULT,
|
||||
loop_delay_max = CHECK_LOOP_DELAY_MAX_DEFAULT,
|
||||
|
|
@ -1473,20 +1509,21 @@ module Vmpooler
|
|||
pool_alias, pool, count, request_id = request.split(':')
|
||||
count = count.to_i
|
||||
provider = get_provider_for_pool(pool)
|
||||
dns_plugin = get_dns_plugin_class_for_pool(pool)
|
||||
slots = ondemand_clone_limit - clone_count
|
||||
break if slots == 0
|
||||
|
||||
if slots >= count
|
||||
count.times do
|
||||
redis.incr('vmpooler__tasks__ondemandclone')
|
||||
clone_vm(pool, provider, request_id, pool_alias)
|
||||
clone_vm(pool, provider, dns_plugin, request_id, pool_alias)
|
||||
end
|
||||
redis.zrem(queue_key, request)
|
||||
else
|
||||
remaining_count = count - slots
|
||||
slots.times do
|
||||
redis.incr('vmpooler__tasks__ondemandclone')
|
||||
clone_vm(pool, provider, request_id, pool_alias)
|
||||
clone_vm(pool, provider, dns_plugin, request_id, pool_alias)
|
||||
end
|
||||
redis.pipelined do |pipeline|
|
||||
pipeline.zrem(queue_key, request)
|
||||
|
|
@ -1601,6 +1638,7 @@ module Vmpooler
|
|||
# Create the providers
|
||||
$config[:pools].each do |pool|
|
||||
provider_name = pool['provider']
|
||||
dns_plugin_name = pool['dns_plugin']
|
||||
# The provider_class parameter can be defined in the provider's data eg
|
||||
# :providers:
|
||||
# :vsphere:
|
||||
|
|
@ -1621,12 +1659,22 @@ module Vmpooler
|
|||
else
|
||||
provider_class = $config[:providers][provider_name.to_sym]['provider_class']
|
||||
end
|
||||
|
||||
begin
|
||||
$providers[provider_name] = create_provider_object($config, $logger, $metrics, @redis, provider_class, provider_name, {}) if $providers[provider_name].nil?
|
||||
rescue StandardError => e
|
||||
$logger.log('s', "Error while creating provider for pool #{pool['name']}: #{e}")
|
||||
raise
|
||||
end
|
||||
|
||||
dns_plugin_class = $config[:dns_configs][dns_plugin_name.to_sym]['dns_class']
|
||||
|
||||
begin
|
||||
$dns_plugins[dns_plugin_class] = create_dns_object($config, $logger, $metrics, @redis, dns_plugin_class, dns_plugin_name, {}) if $dns_plugins[dns_plugin_class].nil?
|
||||
rescue StandardError => e
|
||||
$logger.log('s', "Error while creating dns plugin for pool #{pool['name']}: #{e}")
|
||||
raise
|
||||
end
|
||||
end
|
||||
|
||||
purge_unused_vms_and_resources
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue