vmpooler 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vmpooler/pool_manager.rb +35 -33
- data/lib/vmpooler/providers/base.rb +25 -2
- data/lib/vmpooler/version.rb +1 -1
- data/lib/vmpooler.rb +5 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc5733b50c5c48ba22925f993a81573840cc9621c1707d453e3b6febc71db5eb
|
4
|
+
data.tar.gz: 65ff19db989378ac0ba7d1f1c0f0f2a241a5455cb22a212c2c9b813b40854b6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5abd2edab02d247335f5b67c37004a4a6407798ad0739dde17c55db11e7651dd1d1328d11542972f9b7d9d6b15fffec99c9fb4ee02fb678f5af4e7ed41239a35
|
7
|
+
data.tar.gz: 52ceac894cac6e96f9c73b4a6048dd19ef700a271fc5da1977110020c412b6a376b498da430162f953555b626618009c2e932e260314754141e9f10bbd372a0f
|
@@ -294,6 +294,12 @@ module Vmpooler
|
|
294
294
|
move_vm_queue(pool, vm, 'running', 'completed', redis, 'is listed as running, but has no checkouttime data. Removing from running')
|
295
295
|
end
|
296
296
|
|
297
|
+
# tag VM if not tagged yet, this ensures the method is only called once
|
298
|
+
unless redis.hget("vmpooler__vm__#{vm}", 'user_tagged')
|
299
|
+
success = provider.tag_vm_user(pool, vm)
|
300
|
+
redis.hset("vmpooler__vm__#{vm}", 'user_tagged', 'true') if success
|
301
|
+
end
|
302
|
+
|
297
303
|
throw :stop_checking if provider.vm_ready?(pool, vm)
|
298
304
|
|
299
305
|
throw :stop_checking if provider.get_vm(pool, vm)
|
@@ -478,15 +484,15 @@ module Vmpooler
|
|
478
484
|
dereference_mutex(vm)
|
479
485
|
end
|
480
486
|
|
481
|
-
def
|
482
|
-
global_purge = $config[:config]['
|
487
|
+
def purge_unused_vms_and_resources
|
488
|
+
global_purge = $config[:config]['purge_unconfigured_resources']
|
483
489
|
providers = $config[:providers].keys
|
484
490
|
providers.each do |provider_key|
|
485
|
-
provider_purge = $config[:providers][provider_key]['
|
491
|
+
provider_purge = $config[:providers][provider_key]['purge_unconfigured_resources'] || global_purge
|
486
492
|
if provider_purge
|
487
493
|
Thread.new do
|
488
494
|
begin
|
489
|
-
|
495
|
+
purge_vms_and_resources(provider_key)
|
490
496
|
rescue StandardError => e
|
491
497
|
$logger.log('s', "[!] failed while purging provider #{provider_key} VMs and folders with an error: #{e}")
|
492
498
|
end
|
@@ -496,33 +502,16 @@ module Vmpooler
|
|
496
502
|
nil
|
497
503
|
end
|
498
504
|
|
499
|
-
|
500
|
-
def pool_folders(provider_name)
|
501
|
-
folders = {}
|
502
|
-
$config[:pools].each do |pool|
|
503
|
-
next unless pool['provider'] == provider_name.to_s
|
504
|
-
|
505
|
-
folder_parts = pool['folder'].split('/')
|
506
|
-
datacenter = $providers[provider_name.to_s].get_target_datacenter_from_config(pool['name'])
|
507
|
-
folders[folder_parts.pop] = "#{datacenter}/vm/#{folder_parts.join('/')}"
|
508
|
-
end
|
509
|
-
folders
|
510
|
-
end
|
511
|
-
|
512
|
-
def get_base_folders(folders)
|
513
|
-
base = []
|
514
|
-
folders.each do |_key, value|
|
515
|
-
base << value
|
516
|
-
end
|
517
|
-
base.uniq
|
518
|
-
end
|
519
|
-
|
520
|
-
def purge_vms_and_folders(provider_name)
|
505
|
+
def purge_vms_and_resources(provider_name)
|
521
506
|
provider = $providers[provider_name.to_s]
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
507
|
+
# Deprecated, will be removed in version 3
|
508
|
+
if provider.provider_config['folder_whitelist']
|
509
|
+
$logger.log('d', "[!] [deprecation] rename configuration 'folder_whitelist' to 'resources_allowlist' for provider #{provider_name}")
|
510
|
+
allowlist = provider.provider_config['folder_whitelist']
|
511
|
+
else
|
512
|
+
allowlist = provider.provider_config['resources_allowlist']
|
513
|
+
end
|
514
|
+
provider.purge_unconfigured_resources(allowlist)
|
526
515
|
end
|
527
516
|
|
528
517
|
def create_vm_disk(pool_name, vm, disk_size, provider)
|
@@ -630,8 +619,21 @@ module Vmpooler
|
|
630
619
|
# @return [Array] - a list of used providers from the config file, defaults to the default providers
|
631
620
|
# ie. ["dummy"]
|
632
621
|
def used_providers
|
633
|
-
|
634
|
-
|
622
|
+
# create an array of provider classes based on the config
|
623
|
+
if config[:providers]
|
624
|
+
config_provider_names = config[:providers].keys
|
625
|
+
config_providers = config_provider_names.map do |config_provider_name|
|
626
|
+
if config[:providers][config_provider_name] && config[:providers][config_provider_name]['provider_class']
|
627
|
+
config[:providers][config_provider_name]['provider_class'].to_s
|
628
|
+
else
|
629
|
+
config_provider_name.to_s
|
630
|
+
end
|
631
|
+
end.compact.uniq
|
632
|
+
else
|
633
|
+
config_providers = []
|
634
|
+
end
|
635
|
+
# return the unique array of providers from the config and VMPooler defaults
|
636
|
+
@used_providers ||= (config_providers + default_providers).uniq
|
635
637
|
end
|
636
638
|
|
637
639
|
# @return [Array] - returns a list of providers that should always be loaded
|
@@ -1606,7 +1608,7 @@ module Vmpooler
|
|
1606
1608
|
end
|
1607
1609
|
end
|
1608
1610
|
|
1609
|
-
|
1611
|
+
purge_unused_vms_and_resources
|
1610
1612
|
|
1611
1613
|
loop_count = 1
|
1612
1614
|
loop do
|
@@ -212,6 +212,22 @@ module Vmpooler
|
|
212
212
|
raise("#{self.class.name} does not implement vm_ready?")
|
213
213
|
end
|
214
214
|
|
215
|
+
# tag_vm_user This method is called once we know who is using the VM (it is running). This method enables seeing
|
216
|
+
# who is using what in the provider pools.
|
217
|
+
# This method should be implemented in the providers, if it is not implemented, this base method will be called
|
218
|
+
# and should be a noop. The implementation should check if the vm has a user (as per redis) and add a new tag
|
219
|
+
# with the information.
|
220
|
+
# inputs
|
221
|
+
# [String] pool_name : Name of the pool
|
222
|
+
# [String] vm_name : Name of the VM to check if ready
|
223
|
+
# returns
|
224
|
+
# [Boolean] : true if successful, false if an error occurred and it should retry
|
225
|
+
def tag_vm_user(_pool_name, _vm_name)
|
226
|
+
# noop by design. If the provider does not implement this method, this base method is called (because inherited)
|
227
|
+
# and should basically do nothing.
|
228
|
+
true
|
229
|
+
end
|
230
|
+
|
215
231
|
# inputs
|
216
232
|
# [String] pool_name : Name of the pool
|
217
233
|
# [String] vm_name : Name of the VM to check if it exists
|
@@ -237,8 +253,15 @@ module Vmpooler
|
|
237
253
|
raise("#{self.class.name} does not implement get_target_datacenter_from_config")
|
238
254
|
end
|
239
255
|
|
240
|
-
def
|
241
|
-
raise("#{self.class.name} does not implement
|
256
|
+
def purge_unconfigured_resources(_allowlist)
|
257
|
+
raise("#{self.class.name} does not implement purge_unconfigured_resources")
|
258
|
+
end
|
259
|
+
|
260
|
+
# DEPRECATED if a provider does not implement the new method, it will hit this base class method
|
261
|
+
# and return a deprecation message
|
262
|
+
def purge_unconfigured_folders(_deprecated, _deprecated2, allowlist)
|
263
|
+
logger.log('s', '[!] purge_unconfigured_folders was renamed to purge_unconfigured_resources, please update your provider implementation')
|
264
|
+
purge_unconfigured_resources(allowlist)
|
242
265
|
end
|
243
266
|
end
|
244
267
|
end
|
data/lib/vmpooler/version.rb
CHANGED
data/lib/vmpooler.rb
CHANGED
@@ -31,7 +31,7 @@ module Vmpooler
|
|
31
31
|
if ENV['VMPOOLER_CONFIG']
|
32
32
|
config_string = ENV['VMPOOLER_CONFIG']
|
33
33
|
# Parse the YAML config into a Hash
|
34
|
-
#
|
34
|
+
# Allow the Symbol class
|
35
35
|
parsed_config = YAML.safe_load(config_string, [Symbol])
|
36
36
|
else
|
37
37
|
# Take the name of the config file either from an ENV variable or from the filepath argument
|
@@ -81,10 +81,13 @@ module Vmpooler
|
|
81
81
|
parsed_config[:config]['retry_factor'] = string_to_int(ENV['RETRY_FACTOR']) if ENV['RETRY_FACTOR']
|
82
82
|
parsed_config[:config]['create_folders'] = true?(ENV['CREATE_FOLDERS']) if ENV['CREATE_FOLDERS']
|
83
83
|
parsed_config[:config]['experimental_features'] = ENV['EXPERIMENTAL_FEATURES'] if ENV['EXPERIMENTAL_FEATURES']
|
84
|
-
parsed_config[:config]['purge_unconfigured_folders'] = ENV['PURGE_UNCONFIGURED_FOLDERS'] if ENV['PURGE_UNCONFIGURED_FOLDERS']
|
85
84
|
parsed_config[:config]['usage_stats'] = ENV['USAGE_STATS'] if ENV['USAGE_STATS']
|
86
85
|
parsed_config[:config]['request_logger'] = ENV['REQUEST_LOGGER'] if ENV['REQUEST_LOGGER']
|
87
86
|
parsed_config[:config]['create_template_delta_disks'] = ENV['CREATE_TEMPLATE_DELTA_DISKS'] if ENV['CREATE_TEMPLATE_DELTA_DISKS']
|
87
|
+
parsed_config[:config]['purge_unconfigured_resources'] = ENV['PURGE_UNCONFIGURED_RESOURCES'] if ENV['PURGE_UNCONFIGURED_RESOURCES']
|
88
|
+
parsed_config[:config]['purge_unconfigured_resources'] = ENV['PURGE_UNCONFIGURED_FOLDERS'] if ENV['PURGE_UNCONFIGURED_FOLDERS']
|
89
|
+
# ENV PURGE_UNCONFIGURED_FOLDERS deprecated, will be removed in version 3
|
90
|
+
puts '[!] [deprecation] rename ENV var \'PURGE_UNCONFIGURED_FOLDERS\' to \'PURGE_UNCONFIGURED_RESOURCES\'' if ENV['PURGE_UNCONFIGURED_FOLDERS']
|
88
91
|
set_linked_clone(parsed_config)
|
89
92
|
|
90
93
|
parsed_config[:redis] = parsed_config[:redis] || {}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vmpooler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|