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.
This commit is contained in:
kirby@puppetlabs.com 2019-08-06 13:48:43 -07:00
parent d319643123
commit 09a382a10f
7 changed files with 58 additions and 2 deletions

View file

@ -64,6 +64,7 @@ module Vmpooler
parsed_config[:config]['retry_factor'] = string_to_int(ENV['RETRY_FACTOR']) if ENV['RETRY_FACTOR']
parsed_config[:config]['create_folders'] = ENV['CREATE_FOLDERS'] if ENV['CREATE_FOLDERS']
parsed_config[:config]['create_template_delta_disks'] = ENV['CREATE_TEMPLATE_DELTA_DISKS'] if ENV['CREATE_TEMPLATE_DELTA_DISKS']
set_linked_clone(parsed_config)
parsed_config[:config]['experimental_features'] = ENV['EXPERIMENTAL_FEATURES'] if ENV['EXPERIMENTAL_FEATURES']
parsed_config[:config]['purge_unconfigured_folders'] = ENV['PURGE_UNCONFIGURED_FOLDERS'] if ENV['PURGE_UNCONFIGURED_FOLDERS']
parsed_config[:config]['usage_stats'] = ENV['USAGE_STATS'] if ENV['USAGE_STATS']
@ -183,4 +184,14 @@ module Vmpooler
return unless s =~ /\d/
return Integer(s)
end
def self.true?(obj)
obj.to_s.downcase == "true"
end
def self.set_linked_clone(parsed_config)
parsed_config[:config]['create_linked_clones'] = parsed_config[:config]['create_linked_clones'] || true
parsed_config[:config]['create_linked_clones'] = ENV['CREATE_LINKED_CLONES'] if ENV['CREATE_LINKED_CLONES'] =~ /true|false/
parsed_config[:config]['create_linked_clones'] = true?(parsed_config[:config]['create_linked_clones']) if parsed_config[:config]['create_linked_clones']
end
end

View file

@ -312,7 +312,7 @@ module Vmpooler
# Put the VM in the specified folder and resource pool
relocate_spec = RbVmomi::VIM.VirtualMachineRelocateSpec(
datastore: find_datastore(target_datastore, connection, target_datacenter_name),
diskMoveType: :moveChildMostDiskBacking
diskMoveType: get_disk_backing(pool)
)
manage_host_selection = @config[:config]['manage_host_selection'] if @config[:config].key?('manage_host_selection')
@ -1028,6 +1028,17 @@ module Vmpooler
return false if template[-1] == '/'
return true
end
def get_disk_backing(pool)
return :moveChildMostDiskBacking if linked_clone?(pool)
return :moveAllDiskBackingsAndConsolidate
end
def linked_clone?(pool)
return if pool[:create_linked_clone] == false
return true if pool[:create_linked_clone]
return true if @config[:config]['create_linked_clones']
end
end
end
end