diff --git a/README.md b/README.md index 66b9bd9..0b7116c 100644 --- a/README.md +++ b/README.md @@ -1,41 +1,38 @@ -![vmpooler](https://raw.github.com/sschneid/vmpooler/master/lib/vmpooler/public/img/logo.gif) +![VMPooler](https://raw.github.com/sschneid/vmpooler/master/lib/vmpooler/public/img/logo.gif) -# vmpooler - -vmpooler provides configurable 'pools' of instantly-available (running) virtual machines. +# VMPooler +VMPooler provides configurable 'pools' of instantly-available (pre-provisioned) and/or on-demand (provisioned on request) virtual machines. ## Usage -At [Puppet, Inc.](http://puppet.com) we run acceptance tests on thousands of disposable VMs every day. Vmpooler manages the lifecycle of these VMs from request through deletion, with options available to pool ready instances, and provision on demand. +At [Puppet, Inc.](http://puppet.com) we run acceptance tests on thousands of disposable VMs every day. VMPooler manages the life cycle of these VMs from request through deletion, with options available to pool ready instances, and provision on demand. ## Installation ### Prerequisites -vmpooler is available as a gem - -To use the gem `gem install vmpooler` +VMPooler is available as a gem. To use the gem run `gem install vmpooler` or add it to your Gemfile and install via bundler. ### Dependencies -Vmpooler requires a [Redis](http://redis.io/) server. This is the datastore used for vmpooler's inventory and queueing services. +VMPooler requires a [Redis](http://redis.io/) server. This is the data store used for VMPooler's inventory and queuing services. ### Configuration -Configuration for vmpooler may be provided via environment variables, or a configuration file. +Configuration for VMPooler may be provided via environment variables, or a configuration file. -Note on jruby 9.2.11.x: We have found when running vmpooler on jruby 9.2.11.x we occasionally encounter a stack overflow error that causes the pool\_manager application component to fail and stop doing work. To address this issue on jruby 9.2.11.x we recommend setting the jruby option 'invokedynamic.yield=false'. To set this with jruby 9.2.11.1 you can specify the environment variable 'JRUBY\_OPTS' with the value '-Xinvokedynamic.yield=false'. +**Note on JRuby 9.2.11.x:** We have found when running VMPooler on JRuby 9.2.11.x we occasionally encounter a stack overflow error that causes the pool\_manager application component to fail and stop doing work. To address this issue on JRuby 9.2.11.x we recommend setting the JRuby option 'invokedynamic.yield=false'. To set this with JRuby 9.2.11.1 you can specify the environment variable 'JRUBY\_OPTS' with the value '-Xinvokedynamic.yield=false'. -The provided configuration defaults are reasonable for small vmpooler instances with a few pools. If you plan to run a large vmpooler instance it is important to consider configuration values appropriate for the instance of your size in order to avoid starving the provider, or redis, of connections. +The provided configuration defaults are reasonable for small VMPooler instances with a few pools. If you plan to run a large VMPooler instance it is important to consider configuration values appropriate for the instance of your size in order to avoid starving the provider, or Redis, of connections. -As of vmpooler 0.13.x redis uses a connection pool to improve efficiency and ensure thread safe usage. At Puppet, we run an instance with about 100 pools at any given time. We have to provide it with 200 redis connections to the redis connection pool, and a timeout for connections of 40 seconds, to avoid timeouts. Because metrics are generated for connection available and waited your metrics provider will need to be able to cope with this volume. Statsd is recommended to ensure metrics get delivered reliably. +As of VMPooler 0.13.x Redis uses a connection pool to improve efficiency and ensure thread safe usage. At Puppet, we run an instance with about 100 pools at any given time. We have to provide it with 200 Redis connections to the Redis connection pool, and a timeout for connections of 40 seconds, to avoid timeouts. Because metrics are generated for connection available and waited your metrics provider will need to be able to cope with this volume. Prometheus or StatsD is recommended to ensure metrics get delivered reliably. -Please see this [configuration](docs/configuration.md) document for more details about configuring vmpooler via environment variables. +Please see this [configuration](docs/configuration.md) document for more details about configuring VMPooler via environment variables. The following YAML configuration sets up two pools, `debian-7-i386` and `debian-7-x86_64`, which contain 5 running VMs each: -``` +```yaml --- :providers: :vsphere: @@ -70,43 +67,43 @@ See the provided YAML configuration example, [vmpooler.yaml.example](vmpooler.ya ### Running via Docker -A [Dockerfile](/docker/Dockerfile) is included in this repository to allow running vmpooler inside a Docker container. A configuration file can be used via volume mapping, and specifying the destination as the configuration file via environment variables, or the application can be configured with environment variables alone. The Dockerfile provides an entrypoint so you may choose whether to run API, or manager services. The default behavior will run both. To build and run: +A [Dockerfile](/docker/Dockerfile) is included in this repository to allow running VMPooler inside a Docker container. A configuration file can be used via volume mapping, and specifying the destination as the configuration file via environment variables, or the application can be configured with environment variables alone. The Dockerfile provides an entrypoint so you may choose whether to run API, or manager services. The default behavior will run both. To build and run: -``` +```bash docker build -t vmpooler . && docker run -e VMPOOLER_CONFIG -p 80:4567 -it vmpooler ``` -To run only the API and dashboard +To run only the API and dashboard: -``` +```bash docker run -p 80:4567 -it vmpooler api ``` -To run only the manager component +To run only the manager component: -``` +```bash docker run -it vmpooler manager ``` ### docker-compose -A docker-compose file is provided to support running vmpooler easily via docker-compose. This is useful for development because your local code is used to build the gem used in the docker-compose environment. +A docker-compose file is provided to support running VMPooler easily via docker-compose. This is useful for development because your local code is used to build the gem used in the docker-compose environment. -``` +```bash docker-compose -f docker/docker-compose.yml up ``` ### Running Docker inside Vagrant -A vagrantfile is included in this repository. Please see [vagrant instructions](docs/vagrant.md) for details. +A Vagrantfile is included in this repository. Please see [vagrant instructions](docs/vagrant.md) for details. ## API and Dashboard -vmpooler provides an API and web front-end (dashboard) on port `:4567`. See the provided YAML configuration example, [vmpooler.yaml.example](vmpooler.yaml.example), to specify an alternative port to listen on. +VMPooler provides an API and web front-end (dashboard) on port `:4567`. See the provided YAML configuration example, [vmpooler.yaml.example](vmpooler.yaml.example), to specify an alternative port to listen on. ### API -vmpooler provides a REST API for VM management. See the [API documentation](docs/API.md) for more information. +VMPooler provides a REST API for VM management. See the [API documentation](docs/API.md) for more information. ### Dashboard @@ -122,17 +119,16 @@ A dashboard is provided to offer real-time statistics and historical graphs. It ## Vagrant plugin -- [vagrant-vmpooler](https://github.com/briancain/vagrant-vmpooler) Use Vagrant to create and manage your vmpooler instances. +- [vagrant-vmpooler](https://github.com/briancain/vagrant-vmpooler) Use Vagrant to create and manage your VMPooler instances. ## Development and further documentation -For more information about setting up a development instance of vmpooler or other subjects, see the [docs/](docs) directory. +For more information about setting up a development instance of VMPooler or other subjects, see the [docs/](docs) directory. ## Build status [![Build Status](https://travis-ci.org/puppetlabs/vmpooler.png?branch=master)](https://travis-ci.org/puppetlabs/vmpooler) - ## License -vmpooler is distributed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html). See the [LICENSE](LICENSE) file for more details. +VMPooler is distributed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html). See the [LICENSE](LICENSE) file for more details. diff --git a/lib/vmpooler.rb b/lib/vmpooler.rb index 7d39f18..7bd7c22 100644 --- a/lib/vmpooler.rb +++ b/lib/vmpooler.rb @@ -7,7 +7,6 @@ module Vmpooler require 'net/ldap' require 'open-uri' require 'pickup' - require 'rbvmomi' require 'redis' require 'set' require 'sinatra/base' diff --git a/lib/vmpooler/pool_manager.rb b/lib/vmpooler/pool_manager.rb index 1c9551e..7c8c727 100644 --- a/lib/vmpooler/pool_manager.rb +++ b/lib/vmpooler/pool_manager.rb @@ -628,7 +628,7 @@ module Vmpooler end # @return [Array] - a list of used providers from the config file, defaults to the default providers - # ie. ["vsphere", "dummy"] + # ie. ["dummy"] def used_providers pools = config[:pools] || [] @used_providers ||= (pools.map { |pool| pool[:provider] || pool['provider'] }.compact + default_providers).uniq @@ -638,7 +638,7 @@ module Vmpooler # note: vsphere is the default if user does not specify although this should not be # if vsphere is to no longer be loaded by default please remove def default_providers - @default_providers ||= %w[vsphere dummy] + @default_providers ||= %w[dummy] end def get_pool_name_for_vm(vm_name, redis) @@ -1561,8 +1561,8 @@ module Vmpooler # Set default provider for all pools that do not have one defined $config[:pools].each do |pool| if pool['provider'].nil? - $logger.log('d', "[!] Setting provider for pool '#{pool['name']}' to 'vsphere' as default") - pool['provider'] = 'vsphere' + $logger.log('d', "[!] Setting provider for pool '#{pool['name']}' to 'dummy' as default") + pool['provider'] = 'dummy' end end diff --git a/lib/vmpooler/providers/vsphere.rb b/lib/vmpooler/providers/vsphere.rb deleted file mode 100644 index 1933f64..0000000 --- a/lib/vmpooler/providers/vsphere.rb +++ /dev/null @@ -1,1172 +0,0 @@ -# frozen_string_literal: true - -require 'vmpooler/providers/base' -require 'bigdecimal' -require 'bigdecimal/util' - -module Vmpooler - class PoolManager - class Provider - class VSphere < Vmpooler::PoolManager::Provider::Base - # The connection_pool method is normally used only for testing - attr_reader :connection_pool - - def initialize(config, logger, metrics, redis_connection_pool, name, options) - super(config, logger, metrics, redis_connection_pool, name, options) - - task_limit = global_config[:config].nil? || global_config[:config]['task_limit'].nil? ? 10 : global_config[:config]['task_limit'].to_i - # The default connection pool size is: - # Whatever is biggest from: - # - How many pools this provider services - # - Maximum number of cloning tasks allowed - # - Need at least 2 connections so that a pool can have inventory functions performed while cloning etc. - default_connpool_size = [provided_pools.count, task_limit, 2].max - connpool_size = provider_config['connection_pool_size'].nil? ? default_connpool_size : provider_config['connection_pool_size'].to_i - # The default connection pool timeout should be quite large - 60 seconds - connpool_timeout = provider_config['connection_pool_timeout'].nil? ? 60 : provider_config['connection_pool_timeout'].to_i - logger.log('d', "[#{name}] ConnPool - Creating a connection pool of size #{connpool_size} with timeout #{connpool_timeout}") - @connection_pool = Vmpooler::PoolManager::GenericConnectionPool.new( - metrics: metrics, - connpool_type: 'provider_connection_pool', - connpool_provider: name, - size: connpool_size, - timeout: connpool_timeout - ) do - logger.log('d', "[#{name}] Connection Pool - Creating a connection object") - # Need to wrap the vSphere connection object in another object. The generic connection pooler will preserve - # the object reference for the connection, which means it cannot "reconnect" by creating an entirely new connection - # object. Instead by wrapping it in a Hash, the Hash object reference itself never changes but the content of the - # Hash can change, and is preserved across invocations. - new_conn = connect_to_vsphere - { connection: new_conn } - end - @provider_hosts = {} - @provider_hosts_lock = Mutex.new - @redis = redis_connection_pool - end - - # name of the provider class - def name - 'vsphere' - end - - def folder_configured?(folder_title, base_folder, configured_folders, whitelist) - return true if whitelist&.include?(folder_title) - return false unless configured_folders.keys.include?(folder_title) - return false unless configured_folders[folder_title] == base_folder - - true - end - - def destroy_vm_and_log(vm_name, vm_object, pool, data_ttl) - try = 0 if try.nil? - max_tries = 3 - @redis.with_metrics do |redis| - redis.multi - redis.srem("vmpooler__completed__#{pool}", vm_name) - redis.hdel("vmpooler__active__#{pool}", vm_name) - redis.hset("vmpooler__vm__#{vm_name}", 'destroy', Time.now) - - # Auto-expire metadata key - redis.expire("vmpooler__vm__#{vm_name}", (data_ttl * 60 * 60)) - redis.exec - end - - start = Time.now - - if vm_object.is_a? RbVmomi::VIM::Folder - logger.log('s', "[!] [#{pool}] '#{vm_name}' is a folder, bailing on destroying") - raise('Expected VM, but received a folder object') - end - vm_object.PowerOffVM_Task.wait_for_completion if vm_object.runtime&.powerState && vm_object.runtime.powerState == 'poweredOn' - vm_object.Destroy_Task.wait_for_completion - - finish = format('%