mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 18:08:42 -05:00
Adding support for multiple vsphere providers
Refactoring the vmpooler.yaml format to support multiple providers. The second level key under :providers: is a unique key name that represents a provider that can be refered in the pool's parameter called provider. The code is still backward compatible to support the :vsphere: and :dummy: keys but in reality if you have more than one vsphere configuration you would give them a different name. For example :vsphere-pdx: and :vsphere-bfs: and the actual provider class would be specified as a parameter called 'provider_class'. See tests and examples for more information.
This commit is contained in:
parent
1fcb19bd7b
commit
d93ab332f7
5 changed files with 101 additions and 6 deletions
|
|
@ -694,14 +694,20 @@ module Vmpooler
|
|||
raise
|
||||
end
|
||||
|
||||
def create_provider_object(config, logger, metrics, provider_name, options)
|
||||
case provider_name
|
||||
# create a provider object based on the providers/*.rb class that implements providers/base.rb
|
||||
# provider_class: needs to match a provider class in providers/*.rb ie Vmpooler::PoolManager::Provider::X
|
||||
# provider_name: should be a unique provider name
|
||||
#
|
||||
# returns an object Vmpooler::PoolManager::Provider::*
|
||||
# or raises an error if the class does not exist
|
||||
def create_provider_object(config, logger, metrics, provider_class, provider_name, options)
|
||||
case provider_class
|
||||
when 'vsphere'
|
||||
Vmpooler::PoolManager::Provider::VSphere.new(config, logger, metrics, provider_name, options)
|
||||
when 'dummy'
|
||||
Vmpooler::PoolManager::Provider::Dummy.new(config, logger, metrics, provider_name, options)
|
||||
else
|
||||
raise("Provider '#{provider_name}' is unknown")
|
||||
raise("Provider '#{provider_class}' is unknown for pool with provider '#{provider_name}'")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -731,8 +737,28 @@ module Vmpooler
|
|||
# Create the providers
|
||||
$config[:pools].each do |pool|
|
||||
provider_name = pool['provider']
|
||||
# The provider_class parameter can be defined in the provider's data eg
|
||||
#:providers:
|
||||
# :vsphere:
|
||||
# provider_class: 'vsphere'
|
||||
# :another-vsphere:
|
||||
# provider_class: 'vsphere'
|
||||
# the above would create two providers/vsphere.rb class objects named 'vsphere' and 'another-vsphere'
|
||||
# each pools would then define which provider definition to use: vsphere or another-vsphere
|
||||
#
|
||||
# if provider_class is not defined it will try to use the provider_name as the class, this is to be
|
||||
# backwards compatible for example when there is only one provider listed
|
||||
# :providers:
|
||||
# :dummy:
|
||||
# filename: 'db.txs'
|
||||
# the above example would create an object based on the class providers/dummy.rb
|
||||
if $config[:providers].nil? || $config[:providers][provider_name.to_sym].nil? || $config[:providers][provider_name.to_sym]['provider_class'].nil?
|
||||
provider_class = provider_name
|
||||
else
|
||||
provider_class = $config[:providers][provider_name.to_sym]['provider_class']
|
||||
end
|
||||
begin
|
||||
$providers[provider_name] = create_provider_object($config, $logger, $metrics, provider_name, {}) if $providers[provider_name].nil?
|
||||
$providers[provider_name] = create_provider_object($config, $logger, $metrics, provider_class, provider_name, {}) if $providers[provider_name].nil?
|
||||
rescue => err
|
||||
$logger.log('s', "Error while creating provider for pool #{pool['name']}: #{err}")
|
||||
raise
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ module Vmpooler
|
|||
end
|
||||
end
|
||||
|
||||
# name of the provider class
|
||||
def name
|
||||
'vsphere'
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue