(POOLER-70) Move vSphere configuration into providers section

Previously the vSphere based configuration was in the root of the configuration
YAML.  As there is deprecation support to move the old configuration to the new
location, the vSphere provider can be updated.  This commit updates the vSphere
Provider and tests to use the new configuration location under:

:providers:
  :vsphere:
This commit is contained in:
Glenn Sarti 2017-04-14 16:08:12 -07:00
parent 57eba4a8e4
commit 2e255a5a43
4 changed files with 138 additions and 128 deletions

View file

@ -29,10 +29,11 @@ The following YAML configuration sets up two pools, `debian-7-i386` and `debian-
``` ```
--- ---
:vsphere: :providers:
server: 'vsphere.company.com' :vsphere:
username: 'vmpooler' server: 'vsphere.company.com'
password: 'swimsw1msw!m' username: 'vmpooler'
password: 'swimsw1msw!m'
:redis: :redis:
server: 'redis.company.com' server: 'redis.company.com'
@ -47,12 +48,14 @@ The following YAML configuration sets up two pools, `debian-7-i386` and `debian-
pool: 'Pooled VMs/debian-7-i386' pool: 'Pooled VMs/debian-7-i386'
datastore: 'vmstorage' datastore: 'vmstorage'
size: 5 size: 5
provider: vsphere
- name: 'debian-7-x86_64' - name: 'debian-7-x86_64'
template: 'Templates/debian-7-x86_64' template: 'Templates/debian-7-x86_64'
folder: 'Pooled VMs/debian-7-x86_64' folder: 'Pooled VMs/debian-7-x86_64'
pool: 'Pooled VMs/debian-7-x86_64' pool: 'Pooled VMs/debian-7-x86_64'
datastore: 'vmstorage' datastore: 'vmstorage'
size: 5 size: 5
provider: vsphere
``` ```
See the provided YAML configuration example, [vmpooler.yaml.example](vmpooler.yaml.example), for additional configuration options and parameters. See the provided YAML configuration example, [vmpooler.yaml.example](vmpooler.yaml.example), for additional configuration options and parameters.

View file

@ -2,12 +2,6 @@ module Vmpooler
class PoolManager class PoolManager
class Provider class Provider
class VSphere < Vmpooler::PoolManager::Provider::Base class VSphere < Vmpooler::PoolManager::Provider::Base
def initialize(config, logger, metrics, name, options)
super(config, logger, metrics, name, options)
@credentials = provider_config
@conf = global_config[:config]
end
def name def name
'vsphere' 'vsphere'
end end
@ -239,12 +233,6 @@ module Vmpooler
true true
end end
def provider_config
# The vSphere configuration is currently in it's own root. This will
# eventually shift into the same location base expects it
global_config[:vsphere]
end
# VSphere Helper methods # VSphere Helper methods
def get_target_cluster_from_config(pool_name) def get_target_cluster_from_config(pool_name)
@ -279,21 +267,21 @@ module Vmpooler
begin begin
@connection.serviceInstance.CurrentTime @connection.serviceInstance.CurrentTime
rescue rescue
@connection = connect_to_vsphere @credentials @connection = connect_to_vsphere
end end
@connection @connection
end end
def connect_to_vsphere(credentials) def connect_to_vsphere
max_tries = @conf['max_tries'] || 3 max_tries = global_config[:config]['max_tries'] || 3
retry_factor = @conf['retry_factor'] || 10 retry_factor = global_config[:config]['retry_factor'] || 10
try = 1 try = 1
begin begin
connection = RbVmomi::VIM.connect host: credentials['server'], connection = RbVmomi::VIM.connect host: provider_config['server'],
user: credentials['username'], user: provider_config['username'],
password: credentials['password'], password: provider_config['password'],
insecure: credentials['insecure'] || true insecure: provider_config['insecure'] || true
metrics.increment('connect.open') metrics.increment('connect.open')
return connection return connection
rescue => err rescue => err

View file

@ -47,11 +47,12 @@ describe 'Vmpooler::PoolManager::Provider::VSphere' do
:config: :config:
max_tries: 3 max_tries: 3
retry_factor: 10 retry_factor: 10
:vsphere: :providers:
server: "vcenter.domain.local" :vsphere:
username: "vcenter_user" server: "vcenter.domain.local"
password: "vcenter_password" username: "vcenter_user"
insecure: true password: "vcenter_password"
insecure: true
:pools: :pools:
- name: '#{poolname}' - name: '#{poolname}'
alias: [ 'mockpool' ] alias: [ 'mockpool' ]
@ -66,8 +67,6 @@ EOT
) )
} }
let(:credentials) { config[:vsphere] }
let(:connection_options) {{}} let(:connection_options) {{}}
let(:connection) { mock_RbVmomi_VIM_Connection(connection_options) } let(:connection) { mock_RbVmomi_VIM_Connection(connection_options) }
let(:vmname) { 'vm1' } let(:vmname) { 'vm1' }
@ -912,14 +911,14 @@ EOT
it 'should call connect_to_vsphere to reconnect' do it 'should call connect_to_vsphere to reconnect' do
allow(metrics).to receive(:increment) allow(metrics).to receive(:increment)
expect(subject).to receive(:connect_to_vsphere).with(credentials) expect(subject).to receive(:connect_to_vsphere).with(no_args)
subject.get_connection() subject.get_connection()
end end
it 'should return a new connection' do it 'should return a new connection' do
new_connection = mock_RbVmomi_VIM_Connection(connection_options) new_connection = mock_RbVmomi_VIM_Connection(connection_options)
expect(subject).to receive(:connect_to_vsphere).with(credentials).and_return(new_connection) expect(subject).to receive(:connect_to_vsphere).with(no_args).and_return(new_connection)
result = subject.get_connection() result = subject.get_connection()
@ -933,6 +932,8 @@ EOT
allow(RbVmomi::VIM).to receive(:connect).and_return(connection) allow(RbVmomi::VIM).to receive(:connect).and_return(connection)
end end
let (:credentials) { config[:providers][:vsphere] }
context 'succesful connection' do context 'succesful connection' do
it 'should use the supplied credentials' do it 'should use the supplied credentials' do
expect(RbVmomi::VIM).to receive(:connect).with({ expect(RbVmomi::VIM).to receive(:connect).with({
@ -941,7 +942,7 @@ EOT
:password => credentials['password'], :password => credentials['password'],
:insecure => credentials['insecure'] :insecure => credentials['insecure']
}).and_return(connection) }).and_return(connection)
subject.connect_to_vsphere(credentials) subject.connect_to_vsphere
end end
it 'should honor the insecure setting' do it 'should honor the insecure setting' do
@ -954,11 +955,11 @@ EOT
:password => credentials['password'], :password => credentials['password'],
:insecure => false, :insecure => false,
}).and_return(connection) }).and_return(connection)
subject.connect_to_vsphere(credentials) subject.connect_to_vsphere
end end
it 'should default to an insecure connection' do it 'should default to an insecure connection' do
config[:vsphere][:insecure] = nil config[:providers][:vsphere][:insecure] = nil
expect(RbVmomi::VIM).to receive(:connect).with({ expect(RbVmomi::VIM).to receive(:connect).with({
:host => credentials['server'], :host => credentials['server'],
@ -967,18 +968,18 @@ EOT
:insecure => true :insecure => true
}).and_return(connection) }).and_return(connection)
subject.connect_to_vsphere(credentials) subject.connect_to_vsphere
end end
it 'should return the connection object' do it 'should return the connection object' do
result = subject.connect_to_vsphere(credentials) result = subject.connect_to_vsphere
expect(result).to be(connection) expect(result).to be(connection)
end end
it 'should increment the connect.open counter' do it 'should increment the connect.open counter' do
expect(metrics).to receive(:increment).with('connect.open') expect(metrics).to receive(:increment).with('connect.open')
subject.connect_to_vsphere(credentials) subject.connect_to_vsphere
end end
end end
@ -992,7 +993,7 @@ EOT
end end
it 'should return the connection object' do it 'should return the connection object' do
result = subject.connect_to_vsphere(credentials) result = subject.connect_to_vsphere
expect(result).to be(connection) expect(result).to be(connection)
end end
@ -1000,7 +1001,7 @@ EOT
it 'should increment the connect.fail and then connect.open counter' do it 'should increment the connect.fail and then connect.open counter' do
expect(metrics).to receive(:increment).with('connect.fail').exactly(1).times expect(metrics).to receive(:increment).with('connect.fail').exactly(1).times
expect(metrics).to receive(:increment).with('connect.open').exactly(1).times expect(metrics).to receive(:increment).with('connect.open').exactly(1).times
subject.connect_to_vsphere(credentials) subject.connect_to_vsphere
end end
end end
@ -1011,7 +1012,7 @@ EOT
end end
it 'should raise an error' do it 'should raise an error' do
expect{subject.connect_to_vsphere(credentials)}.to raise_error(RuntimeError,'MockError') expect{subject.connect_to_vsphere}.to raise_error(RuntimeError,'MockError')
end end
it 'should retry the connection attempt config.max_tries times' do it 'should retry the connection attempt config.max_tries times' do
@ -1020,7 +1021,7 @@ EOT
begin begin
# Swallow any errors # Swallow any errors
subject.connect_to_vsphere(credentials) subject.connect_to_vsphere
rescue rescue
end end
end end
@ -1031,7 +1032,7 @@ EOT
begin begin
# Swallow any errors # Swallow any errors
subject.connect_to_vsphere(credentials) subject.connect_to_vsphere
rescue rescue
end end
end end
@ -1051,7 +1052,7 @@ EOT
begin begin
# Swallow any errors # Swallow any errors
subject.connect_to_vsphere(credentials) subject.connect_to_vsphere
rescue rescue
end end
end end

View file

@ -1,9 +1,20 @@
--- ---
:providers:
# :providers:
#
# This section contains the VM providers for VMs and Pools
# The currently supported backing services are:
# - vsphere
# - dummy
# :vsphere: # :vsphere:
# #
# This section contains the server hostname and authentication credentials # This section contains the server hostname and authentication credentials
# needed for vmpooler to connect to VMware vSphere. # needed for vmpooler to connect to VMware vSphere.
# #
# NOTE - To support older configuration files, a :vsphere: configuration section
# will be copied into :providers:/:vsphere: if one does not already exist.
#
# Available configuration parameters: # Available configuration parameters:
# #
# - server # - server
@ -17,20 +28,16 @@
# - password # - password
# The password used to authenticate VMware vSphere. # The password used to authenticate VMware vSphere.
# (required) # (required)
#
# - insecure
# Whether to ignore any HTTPS negotiation errors (e.g. untrusted self-signed certificates)
# (optional: default true)
# Example: # Example:
:vsphere: :vsphere:
server: 'vsphere.company.com' server: 'vsphere.company.com'
username: 'vmpooler' username: 'vmpooler'
password: 'swimsw1msw!m' password: 'swimsw1msw!m'
:providers:
# :providers:
#
# This section contains the VM providers for VMs and Pools
# The currently supported backing services are:
# - dummy
# :dummy: # :dummy:
# #
@ -146,58 +153,58 @@
server: 'redis.company.com' server: 'redis.company.com'
# :graphs: # :graphs:
# #
# This section contains the server and prefix information for a graphite- # This section contains the server and prefix information for a graphite-
# compatible web front-end where graphs may be viewed. This is used by the # compatible web front-end where graphs may be viewed. This is used by the
# vmpooler dashboard to retrieve statistics and graphs for a given instance. # vmpooler dashboard to retrieve statistics and graphs for a given instance.
# #
# NOTE: This is not the endpoint for publishing metrics data. See `graphite:` # NOTE: This is not the endpoint for publishing metrics data. See `graphite:`
# and `statsd:` below. # and `statsd:` below.
# #
# NOTE: If `graphs:` is not set, for legacy compatibility, `graphite:` will be # NOTE: If `graphs:` is not set, for legacy compatibility, `graphite:` will be
# consulted for `server`/`prefix` information to use in locating a # consulted for `server`/`prefix` information to use in locating a
# graph server for our dashboard. `graphs:` is recommended over # graph server for our dashboard. `graphs:` is recommended over
# `graphite:` # `graphite:`
# #
# #
# Available configuration parameters: # Available configuration parameters:
# #
# #
# - server # - server
# The FQDN hostname of the statsd daemon. # The FQDN hostname of the statsd daemon.
# (required) # (required)
# #
# - prefix # - prefix
# The prefix to use while storing statsd data. # The prefix to use while storing statsd data.
# (optional; default: 'vmpooler') # (optional; default: 'vmpooler')
# :statsd: # :statsd:
# #
# This section contains the connection information required to store # This section contains the connection information required to store
# historical data via statsd. This is mutually exclusive with graphite # historical data via statsd. This is mutually exclusive with graphite
# and takes precedence. # and takes precedence.
# #
# Available configuration parameters: # Available configuration parameters:
# #
# - server # - server
# The FQDN hostname of the statsd daemon. # The FQDN hostname of the statsd daemon.
# (required) # (required)
# #
# - prefix # - prefix
# The prefix to use while storing statsd data. # The prefix to use while storing statsd data.
# (optional; default: 'vmpooler') # (optional; default: 'vmpooler')
# #
# - port # - port
# The UDP port to communicate with the statsd daemon. # The UDP port to communicate with the statsd daemon.
# (optional; default: 8125) # (optional; default: 8125)
# Example: # Example:
:statsd: :statsd:
server: 'statsd.company.com' server: 'statsd.company.com'
prefix: 'vmpooler' prefix: 'vmpooler'
port: 8125 port: 8125
# :graphite: # :graphite:
# #
@ -309,7 +316,7 @@
# (optional; default: same cluster/host as origin template) # (optional; default: same cluster/host as origin template)
# #
# - task_limit # - task_limit
# The number of concurrent VMware vSphere tasks to perform. # The number of concurrent VM creation tasks to perform.
# (optional; default: '10') # (optional; default: '10')
# #
# - timeout # - timeout
@ -341,21 +348,23 @@
# #
# - migration_limit # - migration_limit
# When set to any value greater than 0 enable VM migration at checkout. # When set to any value greater than 0 enable VM migration at checkout.
# When enabled this capability will evaluate a VM for migration when it is requested # When enabled this capability will evaluate a VM for migration to a different host when it is requested
# in an effort to maintain a more even distribution of load across compute resources. # in an effort to maintain a more even distribution of load across compute resources.
# The migration_limit ensures that no more than n migrations will be evaluated at any one time # The migration_limit ensures that no more than the specified migrations will be evaluated at any one time
# and greatly reduces the possibilty of VMs ending up bunched together on a particular host. # and greatly reduces the possibilty of VMs ending up bunched together on a particular host.
# #
# - max_tries # - max_tries
# Set the max number of times a connection should retry in vsphere helper. # Set the max number of times a connection should retry in VM providers.
# This optional setting allows a user to dial in retry limits to # This optional setting allows a user to dial in retry limits to
# suit your environment. # suit your environment.
# (optional; default: 3)
# #
# - retry_factor # - retry_factor
# When retrying, each attempt sleeps for the try count * retry_factor. # When retrying, each attempt sleeps for the try count * retry_factor.
# Increase this number to lengthen the delay between retry attempts. # Increase this number to lengthen the delay between retry attempts.
# This is particularly useful for instances with a large number of pools # This is particularly useful for instances with a large number of pools
# to prevent a thundering herd when retrying connections. # to prevent a thundering herd when retrying connections.
# (optional; default: 10)
# Example: # Example:
@ -392,18 +401,15 @@
# The template or virtual machine target to spawn clones from. # The template or virtual machine target to spawn clones from.
# (required) # (required)
# #
# - folder
# The vSphere 'folder' destination for spawned clones.
# (required)
#
# - datastore
# The vSphere 'datastore' destination for spawned clones.
# (required)
#
# - size # - size
# The number of waiting VMs to keep in a pool. # The number of waiting VMs to keep in a pool.
# (required) # (required)
# #
# - provider
# The name of the VM provider which manage this pool. This should match
# a name in the :providers: section above e.g. vsphere
# (required; will default to vsphere for backwards compatibility)
#
# - clone_target # - clone_target
# Per-pool option to override the global 'clone_target' cluster. # Per-pool option to override the global 'clone_target' cluster.
# (optional) # (optional)
@ -415,8 +421,18 @@
# #
# - ready_ttl # - ready_ttl
# How long (in minutes) to keep VMs in 'ready' queues before destroying. # How long (in minutes) to keep VMs in 'ready' queues before destroying.
# (optional) # (optional; default: no limit)
#
# Provider specific pool settings
# vSphere provider
# - folder
# The vSphere 'folder' destination for spawned clones.
# (required)
#
# - datastore
# The vSphere 'datastore' destination for spawned clones.
# (required)
#
# Example: # Example:
:pools: :pools:
@ -428,6 +444,7 @@
size: 5 size: 5
timeout: 15 timeout: 15
ready_ttl: 1440 ready_ttl: 1440
provider: vsphere
- name: 'debian-7-x86_64' - name: 'debian-7-x86_64'
alias: [ 'debian-7-64', 'debian-7-amd64' ] alias: [ 'debian-7-64', 'debian-7-amd64' ]
template: 'Templates/debian-7-x86_64' template: 'Templates/debian-7-x86_64'
@ -436,3 +453,4 @@
size: 5 size: 5
timeout: 15 timeout: 15
ready_ttl: 1440 ready_ttl: 1440
provider: vsphere