Skip to content

Commit

Permalink
(DIO-1059) Optionally add snapshot tuning params at clone time
Browse files Browse the repository at this point in the history
  • Loading branch information
suckatrash committed Oct 16, 2020
1 parent a42ed6c commit b2ac53f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 11 deletions.
41 changes: 30 additions & 11 deletions lib/vmpooler/providers/vsphere.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,19 +306,26 @@ def create_vm(pool_name, new_vmname)

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')
Expand Down Expand Up @@ -358,6 +365,18 @@ def create_vm(pool_name, new_vmname)
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)
Expand Down
31 changes: 31 additions & 0 deletions spec/unit/providers/vsphere_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,37 @@
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
Expand Down
11 changes: 11 additions & 0 deletions vmpooler.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -677,3 +686,5 @@
ready_ttl: 1440
provider: vsphere
create_linked_clone: false
snapshot_mainMem_ioBlockPages: '2048'
snapshot_mainMem_iowait: '0'

0 comments on commit b2ac53f

Please sign in to comment.