Commit graph

150 commits

Author SHA1 Message Date
Brandon High
019ed021b0
(QENG-7530) Add check for unique hostnames
Prior to this commit the pooler had no awareness of the complete set of
hostnames that are currently in use. This meant that it was possible to
allocate the same hostname twice, which would result in the original
host with that hostname becoming unreachable.

This commit adds a check for the existence of the
`vmpooler__vm__<hostname>` key before attempting to  clone the vm.
This should prevent duplicate hostnames.

If the hostname is already taken, `_clone_vm` will retry with a new
random hostname multiple times before raising an exception.
2019-11-04 15:53:05 -08:00
Brandon High
625472df35
(QENG-7530) Fix hostname_shorten regex
Prior to this commit the hostname_shorten regex wouldn't match the
updated human readable hostnames because they contain dashes.
This commit updates the regex to capture dashes in the hostname, and
adds a few specs to verify that behavior.
2019-11-01 10:30:56 -07:00
kirby@puppetlabs.com
267772d8eb (POOLER-147) Fix create_linked_clone pool option
This commit updates the create_linked_clone pool option to correctly detect when linked clones have been set at a pool level. Without this change a pool setting create_linked_clone to false is not interpreted correctly, and a linked clone is created if possible.
2019-08-22 14:32:06 -07:00
kirby@puppetlabs.com
9c5a0d114b (POOLER-142) Add running host to vm API data
This change adds the running host for a VM to the API data available via /vm/hostname. Without this change the running host would be logged to vmpooler log, but not available any other way. Additionally, the data will specify if a machine has been migrated. Without this change parent host data for a vmpooler machine is not available via the vmpooler API.
2019-08-21 12:43:06 -07:00
kirby@puppetlabs.com
09a382a10f Make it possible to disable linked clones
This commit adds a new configuration parameter to allow setting whether to create linked clones on a global, or per pool basis. Without this change vmpooler would always attempt to create linked clones. The default behavior of creating linked clones is preserved.
2019-08-06 14:29:31 -07:00
Spencer McElmurry
98a547b807 (POOLER-143) Add clone_target config change to API
This allows the user to change the cluster in which the targeted pool
will clone to. Upon configuration change, the thread will wake up and
execute the change within 1 second.
2019-07-29 08:53:27 -07:00
Samuel Beaulieu
8eb15f8d10 (maint) Optimize the status api using redis pipeline
Before this change looping over many pools would query the redis backend
for each pool, leading in slow response from the backend for configurations
with many pools (60+)
Changed the requests to use redis pipelines https://redis.io/topics/pipelining
This is supported since the beginning, so will not force any redis update for
users. The pipeline method runs the queries in batches and we need to loop
over the result and reduces the number of requests to redis by N=number of
pools in the configuration.
2019-04-18 13:24:40 -05:00
kirby@puppetlabs.com
d94b14a4d8 (POOLER-137) Support integer environment variables
This commit updates vmpooler to set configuration values received via environment variables to integer values when an integer value is expected. Without this change vmpooler does not support setting integer values via environment variables. Additionally, testing is added for configuring vmpooler via environment variables.

To support this testing the gem climate_control is added, which allows
for testing environment variables without those set variables leaking to
other tests.
2019-01-22 15:02:07 -08:00
kirby@puppetlabs.com
2de4a6db0b Ensure nodes are consistent for usage stats
This commit updates vm usage stats collection to replace all instances of '.' characters within node strings. Without this change the node string containing a '.' character causes the metric to be interpreted as containing another node.
2018-12-19 12:45:50 -08:00
kirby@puppetlabs.com
60b8715a80 Update providers_spec to match array contents
This commit updates providers_spec so the test ensures array content of the providers match. Without this change the provider_spec test will fail when comparing providers if the order is not exactly the same in each array.
2018-12-07 17:08:08 -08:00
kirby@puppetlabs.com
9a57c6d1b5 (POOLER-134) Ship VM usage stats
This commit updates vmpooler to ship VM usage stats when a VM is destroyed. The stats are gathered for jobs based on user and pool name. If a jenkins build URL is present then this is broken down by user, instance, value stream, branch and project. Additionally, if present then the RMM_COMPONENT_TO_TEST_NAME will be listed after project. Without this change we do not collect stats on per VM usage and its correlation to users and pools.
2018-12-07 11:59:27 -08:00
kirby@puppetlabs.com
3c856d7ae9 (POOLER-133) Identify when a ready VM has failed
This commit fixes checking of a VM that has already been identified as ready. Without this change a ready VM that has failed will be identified as having failed, but will not successfully be removed from the ready queue. Additionally, the default vm_checktime value has been reduced from 15 to 1 to ensure that ready VMs are checked within one minute of the time they have reached the ready state by default.

Lastly, the docker-compose files are updated to specify that the redis
instance used is a local redis instance.
2018-12-03 12:21:08 -08:00
kirby@puppetlabs.com
830acd705d Remove debug statements. Return when get_vm returns nil 2018-09-12 12:28:12 -07:00
mchllweeks
0e86937245
Merge pull request #297 from mattkirby/pooler_130
(POOLER-130) Improve delta disk creation handling
2018-08-30 17:22:35 -07:00
kirby@puppetlabs.com
3fd0c6f475 (POOLER-130) Improve delta disk creation handling
This commit updates delta disk creation to reduce the likelihood of this being run more than once for any given template. Without this change an error can be generated with vsphere 6.5 or later when a template is updated, and then the update is reverted. The error prevents the image from being used because the template is never marked as prepared. To address this any failure is now logged, and the template is marked as prepared regardless of whether this was successful, or not, which allows the image to be used despite the error. This failure mode is more graceful and allows the pool to continue to function.
2018-08-30 15:50:07 -07:00
Samuel Beaulieu
3aac95d5b9 (POOLER-114) Refactor check_pool in pool_manager
This commit refactorss the check_pool method in pool_manager.
Specifically, each commented section describing a stage of check_pool is
broken out into a separate method and check_pool is simplified by
calling these methods. Without this change it is difficult to follow the
intent for or make changes to check_pool.

Additionally, a docker-compose file is added to make it simple to launch
an all-in-one vmpooler instance along with a separate redis server with
docker.
2018-08-23 14:04:52 -07:00
Corey Osman
2daa5244b8 Adds a new mechanism to load providers from any gem or file path. (#263)
* Adds ability to load only providers used in config file
2018-07-24 16:35:18 -07:00
kirby@puppetlabs.com
490e5c1938 (POOLER-128) Remove references to VM mutex when destroying
This commit updates destroy_vm to remove references to its mutex tracking object when destroyed. Without this change a VM that is destroyed will leave its mutex tracking object forever causing the pool manager memory footprint to increase.
2018-07-23 16:53:53 -07:00
Steve Axthelm
c3d90dbfa6 (maint) change domain to example.com
Prior to this commit the docs and examples used 'company.com'
(a real domain). This commit changes those occurrences to
'example.com', which is a IANA-managed reserved domain.
2018-07-19 15:23:30 -07:00
Kevin Imber
099b53f348
Merge pull request #274 from mattkirby/cleanup_unused_folders_and_vms
(POOLER-66) Purge vms and folders no longer configured
2018-07-19 13:19:13 -07:00
Spencer McElmurry
5ca85beb18
Merge pull request #283 from mattkirby/remove_find_pool
(MAINT) Remove find_pool and update pending tests
2018-07-16 10:25:16 -07:00
kirby@puppetlabs.com
ff1d288b53 (MAINT) Remove find_pool and update pending tests
This commit removes find_pool, which is no longer used. Additionally, tests which are listed as pending and have been resolved are removed from pending tests. Lastly, a folder check that doesn't make sense given the change in method for finding objects is removed.
2018-07-13 12:42:09 -07:00
kirby@puppetlabs.com
a34c8dd11b (POOLER-66) Purge vms and folders no longer configured
This commit enables optional purging for vms and folders when they are
not configured in the vmpooler provided configuration. Base folders are
determined from folders specified in the pool configuration. Then,
anything not configured in that folder for that provider and is not a
whitelisted folder title will be destroyed. Without this change vmpooler
will leave unconfigured vms and folders behind and any vms will be left
running forever without manual intervention. Additionally, any
associated redis data will never be expired.
2018-07-13 12:09:28 -07:00
mattkirby
070199e877 Eliminate duplicate VM object lookups where possible (#269)
* Minimize duplicate checking of VMs

This commit updates check_pool pending, running and ready methods to greatly reduce instances in which the VM object is retrieved. Without this change get_vm is run for each of these check_pool steps even though the VM is already validated as being in inventory being running the check. This is left for checking running VMs when the VM is no longer ready. Without this change there is an unnecessarily large volume of VM object checks.

* Make hostname mismatch checking optional

This commit makes hostname mismatch checking optional on a pool and global config level. The default behavior of checking this is preserved. When disabled _check_ready_vm will not run get_vm, which allows for ready VMs to be checked without retrieving an object from vsphere and waiting for a free provider connection. Without this change it is not possible to disable VM object retrieval in _check_vm_ready.

* Check if a hostname return is empty string

This commit checks whether a hostname returned is an empty string.
Without this change a VM that returns a hostname with a empty string
will report as having a hostname mismatch, which may happen before all
VM data is updated.

* Only check hostname for mismatch after time since ready has past

Configure hostname checking so it is not checked until a VM has been
ready for greater than one minute. Without this change hostname checking
will often fail because the configured value has not propogated to the
VM on some platforms before this check is run.
2018-07-13 12:06:44 -05:00
Spencer McElmurry
a865e6bd2f (POOLER-34) Ship clone request to ready time to metrics (#277)
* (POOLER-34) Ship clone request to ready time to metrics

Before, we were already capturing this metric but we failed to ship
it anywhere. This ships the appropriate metric as `time_to_ready_state`
Dashboards can be found in grafana.

* Add spec test to ensure metric is being shipped properly on
move_pending_vm_to_ready call.
2018-07-09 16:22:49 -07:00
kirby@puppetlabs.com
9ddd3c21b7 (MAINT) Fix test reference to find_vm
This commit updates a test reference to find_vm. This method has been renamed find_vm_folder, so this commit updates usage to reflect the new title and reduced arguments required. Without this change tests fail on master.
2018-07-09 14:57:07 -07:00
mchllweeks
6f4f3cc4e7
Merge pull request #273 from mattkirby/pooler_124
(POOLER-124) Fix evaluation of max_tries
2018-07-09 12:50:34 -07:00
mchllweeks
afc5a33d8f
Merge pull request #272 from mattkirby/pooler_40
(POOLER-40) Do not return folders with get_pool_vms
2018-07-09 12:50:00 -07:00
mchllweeks
2f98b1bd7a
Merge pull request #271 from mattkirby/less_delta_disks
Ensure template deltas are created once
2018-07-09 12:49:08 -07:00
mchllweeks
69f8b21ca8
Merge pull request #270 from mattkirby/no_duplicate_vms_in_pool
Do not run duplicate instances of inventory check for a pool
2018-07-09 12:48:41 -07:00
mchllweeks
a72012b754
Merge pull request #268 from mattkirby/reduce_object_lookups
Reduce object lookups for finding folders
2018-07-09 12:46:17 -07:00
kirby@puppetlabs.com
faaec4f9bc (POOLER-124) Fix evaluation of max_tries
This commit updates usage of max_tries to ensure that the increment of the try value happens after evaluation of whether max_tries has been exceeded. Without this change max_tries doesn't work as advertised. Additionally, checking looks to see if try is greater than or equal to so the try count exceeding max_tries would also be detected.
2018-07-03 11:24:05 -07:00
kirby@puppetlabs.com
bd0ae2e192 (POOLER-40) Do not return folders with get_pool_vms
This commit updates get_pool_vms to only return if the object is a VirtualMachine. Without this change a folder wtihin a VM target folder can be discovered and destroyed as though it were a VM.
2018-07-03 11:09:07 -07:00
kirby@puppetlabs.com
70156ba7f7 Do not prepare template when config_template is set 2018-07-02 14:12:17 -07:00
kirby@puppetlabs.com
1b17cceb01 Ensure template deltas are created once
This commit updates how template delta disk creation is evaluated. Without this change template deltas are created for every template on each applicatoin startup. This change updates this behavior to instead run template delta disk creation only once per template configured for a pool. Without this change it is possible to get a template to a state where the XML depth is too great to be read with default settings and the template requires a new clone to resolve.
2018-07-02 09:53:41 -07:00
mchllweeks
0ce66eb763
Merge pull request #266 from mattkirby/pooler_31
(POOLER-31) Expire redis vm key when clone fails
2018-06-29 16:43:04 -07:00
kirby@puppetlabs.com
df89617fdc Do not run duplicate instances of inventory check for a pool
This commit updates check_pool inventory check to prevent multiple instances from running at once. Without this change the inventory check may run in multiple threads simultaneously.
2018-06-28 20:32:44 -07:00
kirby@puppetlabs.com
a6c2ef7bf3 Rename find_folder to find_vm_folder
This commit renames find_folder to find_vm_folder to clarify its intent to retrieve folders from the VM hierarchy. Without this change find_folder implies it may find folders that are not within the VM hierarchy.
2018-06-28 15:26:09 -07:00
kirby@puppetlabs.com
5c857f50f1 Replace find_folder with searchindex inventorypath
This commit replaces find_folder to use information already known about folders to determine their location and quickly fail when it does not exist without traversing the hierarchy. Without this change find_folder is very inneficient and can take a long time to return depending on how deep in the folder tree the folder exists.
2018-06-28 15:25:51 -07:00
kirby@puppetlabs.com
8840ef4a5c Reduce object lookups for get_vm
This commit reduces object lookups used for get_vm. Without this change get_vm looks up the VM folder, which is already used and known to find the vm with find_vm.
2018-06-28 15:25:25 -07:00
kirby@puppetlabs.com
9fa27af8e5 (POOLER-113) Add support for multiple LDAP search bases
This commit updates vmpooler to support setting an array of search bases
in addition to a single base provided as a string. Without this change
it is not possible to specify multiple search bases to use with the LDAP
authentication provider. Additionally, test coverage is added to
the authentication helper method.
2018-06-25 21:37:22 -07:00
kirby@puppetlabs.com
3a6e2a5cac (POOLER-31) Expire redis vm key when clone fails
This commit updates pool_manager to expire a redis VM key when a clone fails. Without this change VMs that fail to clone have their metadata left forever.
2018-06-20 17:27:31 -07:00
kirby@puppetlabs.com
3a0f0880e7 (POOLER-112) Ensure a VM is only destroyed once
This commit implements a vm_mutex hash to allow synchronizing VM operations that should only happen once across threads. Without this change pool_manager will try to evaluate or destroy a VM multiple times, which results in an error being thrown by one of the destroy attempts as only one can succeed and a duplication of resources unnecessarily when there are no errors.
2018-06-20 13:40:49 -07:00
Samuel
d736b1e978
Merge pull request #260 from mattkirby/fix_check_disk
Remove propertyCollector from add_disk
2018-06-20 15:25:38 -05:00
kirby@puppetlabs.com
9bb4df7d8e (POOLER-107) Add configuration API endpoint
This commit adds a configuration endpoint to the vmpooler API. Pool
size, and pool template, can be adjusted for pools that are configured
at vmpooler application start time. Pool template changes trigger a pool
refresh, and the new template has delta disks created automatically by
vmpooler.

Additionally, the capability to create template delta disks is added to
the vsphere provider, and this is implemented to ensure that templates
have delta disks created at application start time.

The mechanism used to find template VM objects is simplified to make the flow of logic easier to understand. As an additional benefit, performance of this lookup is improved by using FindByInventoryPath.

A table of contents is added to API.md to ease navigation. Without this change API.md has no table of contents and is difficult to navigate.

Add mutex object for managing pool configuration updates

This commit adds a mutex object for ensuring that pool configuration changes are synchronized across multiple running threads, removing the possibility of two threads attempting to update something at once, without relying on redis data. Without this change this is managed crudely by specifying in redis that a configuration update is taking place. This redis data is left so the REPOPULATE section of _check_pool can still identify when a configuration change is in progress, and prevent a pool from repopulating at that time.

Add wake up event for pool template changes

This commit adds a wake up event to detect pool template changes.
Additionally, GET /config has a template_ready section added to the
output for each pool, which makes clear when a pool is ready to populate
itself.
2018-06-15 10:15:47 -07:00
kirby@puppetlabs.com
d1ae85c8af Remove propertyCollector from add_disk
This commit updates add_disk to remove propertyCollector, which was used
to back the find_vmdks method to locate the disk file on datastore and
then use its length to name the new disk. Instead, the number of disks
on the VM is used to ensure a unique disk resource title. Without this
change add_disk can take 10-50x longer due to the propertyCollector
method. Additionally, without this change propertyCollector is used in a
non threadsafe manner, which may cause stability issues for vsphere
provider backends.
2018-06-04 11:51:55 -07:00
kirby@puppetlabs.com
4700ad2bb8 (POOLER-68) Replace find_vm search mechanism
This commit replaces find_vm and find_vm_heavy with a more performant and reliable mechanism of identifying VM objects. Specifically, FindByInventoryPath is able to leverage known data about a VM, its folder path and datacenter, and use that to identify whether that VM exists by its location. Without this change find_vm_heavy is called each time a VM cannot be found, which is frequent, and in doing so uses PropertyCollector in a manner that is not thread-safe. Additionally, this PropertyCollector usage does not clean up its traces, which can cause vCenter appliance instability issues on VCSA 6.x.
2018-05-14 09:12:20 -07:00
Samuel Beaulieu
10245321bf (maint) Add the last boot time for each pool
This commit add a redis hash where there is one key per pool, and the
stored value is the last time a VM was booted e.g. the last time
a VM went from 'pending' to 'ready'. This is also displayed in the
API as lastBoot:'2018-03-23 17:43:39 +0000'. The data can then be
used by any external system, in this case our alarming system.
2018-03-28 11:11:49 -07:00
David Bishop
d57fc72fdb Fix typo in error message 2018-01-25 08:59:00 -08:00
adamdav
878c93f646 Allow user to specify a configuration file in VMPOOLER_CONFIG_FILE
variable

Previously, there were two ways to configure Vmpooler, either by
changing the contents of vmpooler.yaml or by assigning the raw YAML
to the VMPOOLER_CONFIG environment variable. This commit adds a new
environment variable called VMPOOLER_CONFIG_FILE that can be assigned
the name of a config file to use. Also fixes #240 by whitelisting the
Symbol class when calling YAML.safe_load in Vmpooler.config.
2018-01-23 15:51:10 -08:00