From b2ac53fa764f97919903cb804e332fb5e91209fd Mon Sep 17 00:00:00 2001 From: suckatrash Date: Tue, 13 Oct 2020 13:16:59 -0700 Subject: [PATCH] (DIO-1059) Optionally add snapshot tuning params at clone time --- lib/vmpooler/providers/vsphere.rb | 41 +++++++++++++++++++++-------- spec/unit/providers/vsphere_spec.rb | 31 ++++++++++++++++++++++ vmpooler.yaml.example | 11 ++++++++ 3 files changed, 72 insertions(+), 11 deletions(-) diff --git a/lib/vmpooler/providers/vsphere.rb b/lib/vmpooler/providers/vsphere.rb index 63373ec..467a6b2 100644 --- a/lib/vmpooler/providers/vsphere.rb +++ b/lib/vmpooler/providers/vsphere.rb @@ -306,19 +306,26 @@ module Vmpooler template_vm_object = find_template_vm(pool, connection) + extra_config = [ + { key: 'guestinfo.hostname', value: new_vmname } + ] + + if pool.key?('snapshot_mainMem_ioBlockPages') + ioblockpages = pool['snapshot_mainMem_ioBlockPages'] + extra_config.push( + { key: 'mainMem.ioBlockPages', value: ioblockpages } + ) + end + if pool.key?('snapshot_mainMem_iowait') + iowait = pool['snapshot_mainMem_iowait'] + extra_config.push( + { key: 'mainMem.iowait', value: iowait } + ) + end + # Annotate with creation time, origin template, etc. # Add extraconfig options that can be queried by vmtools - config_spec = RbVmomi::VIM.VirtualMachineConfigSpec( - annotation: JSON.pretty_generate( - name: new_vmname, - created_by: provider_config['username'], - base_template: template_path, - creation_timestamp: Time.now.utc - ), - extraConfig: [ - { key: 'guestinfo.hostname', value: new_vmname } - ] - ) + config_spec = create_config_spec(new_vmname, template_path, extra_config) # Check if alternate network configuration is specified and add configuration if pool.key?('network') @@ -358,6 +365,18 @@ module Vmpooler vm_hash end + def create_config_spec(vm_name, template_name, extra_config) + RbVmomi::VIM.VirtualMachineConfigSpec( + annotation: JSON.pretty_generate( + name: vm_name, + created_by: provider_config['username'], + base_template: template_name, + creation_timestamp: Time.now.utc + ), + extraConfig: extra_config + ) + end + def create_relocate_spec(target_datastore, target_datacenter_name, pool_name, connection) pool = pool_config(pool_name) target_cluster_name = get_target_cluster_from_config(pool_name) diff --git a/spec/unit/providers/vsphere_spec.rb b/spec/unit/providers/vsphere_spec.rb index a2970ac..751a7ec 100644 --- a/spec/unit/providers/vsphere_spec.rb +++ b/spec/unit/providers/vsphere_spec.rb @@ -689,6 +689,37 @@ EOT expect(result['name']).to eq(vmname) end end + + context 'Given valid snapshot tuning settings' do + let(:folder_object) { mock_RbVmomi_VIM_Folder({ :name => 'pool1'}) } + let(:now) { Time.now } + let(:config_spec) { + [ + { key: 'guestinfo.hostname', value: vmname }, + { key: 'mainMem.ioBlockPages', value: '300' }, + { key: 'mainMem.iowait', value: '2' } + ] + } + + before(:each) do + template_vm = new_template_object + allow(subject).to receive(:find_template_vm).and_return(new_template_object) + allow(template_vm).to receive(:CloneVM_Task).and_return(clone_vm_task) + allow(clone_vm_task).to receive(:wait_for_completion).and_return(new_vm_object) + allow(subject).to receive(:find_vm_folder).and_return(folder_object) + allow(Time).to receive(:now).and_return(Time.now) + config[:pools][0]['snapshot_mainMem_ioBlockPages'] = '300' + config[:pools][0]['snapshot_mainMem_iowait'] = '2' + end + + it 'should apply the appropriate extraConfig settings' do + result = subject.create_config_spec(vmname, "template1", config_spec) + expect(result.extraConfig).to include( + { :key => 'mainMem.ioBlockPages', :value => '300' }, + { :key => 'mainMem.iowait', :value => '2'} + ) + end + end end describe '#set_network_device' do diff --git a/vmpooler.yaml.example b/vmpooler.yaml.example index 6194167..db50188 100644 --- a/vmpooler.yaml.example +++ b/vmpooler.yaml.example @@ -654,6 +654,15 @@ # The datacenter within vCenter to manage VMs. # (optional: default is the first datacenter in vSphere) # +# - snapshot_mainMem_ioBlockPages +# Provisions VMs with the option "mainMem.ioBlockPages". This setting can be useful +# (paired with mainMem.iowait below) for tuning the performance of snapshot management actions. +# See: https://kb.vmware.com/s/article/76687 +# +# - snapshot_mainMem_iowait +# Provisions VMs with the option "mainMem.iowait". This setting can be useful +# for tuning the performance of snapshot management actions +# # Example: :pools: @@ -677,3 +686,5 @@ ready_ttl: 1440 provider: vsphere create_linked_clone: false + snapshot_mainMem_ioBlockPages: '2048' + snapshot_mainMem_iowait: '0'