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

@ -15,7 +15,7 @@ COPY ./ ./
ENV RACK_ENV=production ENV RACK_ENV=production
RUN gem install bundler -v '2.0.1' && bundle install && gem build vmpooler.gemspec && gem install vmpooler*.gem && \ RUN gem install bundler && bundle install && gem build vmpooler.gemspec && gem install vmpooler*.gem && \
chmod +x /usr/local/bin/docker-entrypoint.sh chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"] ENTRYPOINT ["docker-entrypoint.sh"]

View file

@ -147,6 +147,12 @@ Note: this will only create the last folder when it does not exist. It will not
Create backing delta disks for the specified templates to support creating linked clones. Create backing delta disks for the specified templates to support creating linked clones.
(optional; default: false) (optional; default: false)
### CREATE\_LINKED\_CLONES
Whether to create linked clone virtual machines when using the vsphere provider.
This can also be set per pool.
(optional; default: true)
### PURGE\_UNCONFIGURED\_FOLDERS ### PURGE\_UNCONFIGURED\_FOLDERS
Enable purging of VMs and folders detected within the base folder path that are not configured for the provider Enable purging of VMs and folders detected within the base folder path that are not configured for the provider

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]['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_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'] 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]['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]['purge_unconfigured_folders'] = ENV['PURGE_UNCONFIGURED_FOLDERS'] if ENV['PURGE_UNCONFIGURED_FOLDERS']
parsed_config[:config]['usage_stats'] = ENV['USAGE_STATS'] if ENV['USAGE_STATS'] parsed_config[:config]['usage_stats'] = ENV['USAGE_STATS'] if ENV['USAGE_STATS']
@ -183,4 +184,14 @@ module Vmpooler
return unless s =~ /\d/ return unless s =~ /\d/
return Integer(s) return Integer(s)
end 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 end

View file

@ -312,7 +312,7 @@ module Vmpooler
# Put the VM in the specified folder and resource pool # Put the VM in the specified folder and resource pool
relocate_spec = RbVmomi::VIM.VirtualMachineRelocateSpec( relocate_spec = RbVmomi::VIM.VirtualMachineRelocateSpec(
datastore: find_datastore(target_datastore, connection, target_datacenter_name), 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') 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 false if template[-1] == '/'
return true return true
end 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 end
end end

View file

@ -26,6 +26,7 @@ describe 'Vmpooler' do
['clone_target', test_string, nil], ['clone_target', test_string, nil],
['create_folders', test_bool, nil], ['create_folders', test_bool, nil],
['create_template_delta_disks', test_bool, nil], ['create_template_delta_disks', test_bool, nil],
['create_linked_clones', test_bool, nil],
['experimental_features', test_bool, nil], ['experimental_features', test_bool, nil],
['purge_unconfigured_folders', test_bool, nil], ['purge_unconfigured_folders', test_bool, nil],
['usage_stats', test_bool, nil], ['usage_stats', test_bool, nil],

View file

@ -3431,4 +3431,29 @@ EOT
end end
end end
end end
describe 'get_disk_backing' do
it 'should return moveChildMostDiskBacking when linked clone enabled' do
expect( subject.get_disk_backing({create_linked_clone: true}) ).to eq(:moveChildMostDiskBacking)
end
it 'should return moveAllDiskBackingsAndConsolidate when no preference is specified' do
expect( subject.get_disk_backing({})).to eq(:moveAllDiskBackingsAndConsolidate)
end
it 'should return moveAllDiskBackingsAndConsolidate when linked clone is false' do
expect( subject.get_disk_backing({create_linked_clone: false})).to eq(:moveAllDiskBackingsAndConsolidate)
end
end
describe 'linked_clone?' do
it 'should return true when linked clone is enabled on the pool' do
expect( subject.linked_clone?({create_linked_clone: true}) ).to be true
end
it 'should return nil when linked clone is not enabled on the pool' do
expect( subject.linked_clone?({}) ).to be nil
end
end
end end

View file

@ -592,6 +592,7 @@
timeout: 15 timeout: 15
ready_ttl: 1440 ready_ttl: 1440
provider: vsphere provider: vsphere
create_linked_clone: true
- 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'
@ -601,3 +602,4 @@
timeout: 15 timeout: 15
ready_ttl: 1440 ready_ttl: 1440
provider: vsphere provider: vsphere
create_linked_clone: false