Skip to content

Commit

Permalink
Expose vmx_options (optional)
Browse files Browse the repository at this point in the history
- used to set VM Options advanced configurations
usage:
```
cloud_properties:
  vmx_options:
    sched.mem.maxmemctl: "1330"
```

[#148036961](https://www.pivotaltracker.com/story/show/148036961)

Signed-off-by: Chris Dutra <[email protected]>
  • Loading branch information
Shoabe Shariff authored and Chris Dutra committed Jul 6, 2017
1 parent b893fed commit c73c05a
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/vsphere_cpi/lib/cloud/vsphere/vm_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ def bosh_group
end
end

def vmx_options
vm_type['vmx_options'] || {}
end

private

def validate_drs_rules
Expand Down
9 changes: 8 additions & 1 deletion src/vsphere_cpi/lib/cloud/vsphere/vm_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,16 @@ def create(vm_config)

replicated_stemcell_vm.fix_device_unit_numbers(config_spec.device_change)

@logger.info("Cloning vm: #{replicated_stemcell_vm} to #{vm_config.name}")
if vm_config.vmx_options.is_a?(Hash)
config_spec.extra_config = vm_config.vmx_options.keys.map { |key|
VimSdk::Vim::Option::OptionValue.new(key: key, value: vm_config.vmx_options[key])
}
else
raise "Unable to parse vmx options: 'vmx_options' is not a Hash"
end

# Clone VM
@logger.info("Cloning vm: #{replicated_stemcell_vm} to #{vm_config.name}")
created_vm_mob = @client.wait_for_task do
@cpi.clone_vm(replicated_stemcell_vm.mob,
vm_config.name,
Expand Down
73 changes: 73 additions & 0 deletions src/vsphere_cpi/spec/integration/vmx_options_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
require 'integration/spec_helper'

describe 'vmx_options' do
let(:vmx_option_key) { 'some_key' }

let(:network_spec) do
{
'static' => {
'ip' => "169.254.#{rand(1..254)}.#{rand(4..254)}",
'netmask' => '255.255.254.0',
'cloud_properties' => {'name' => @vlan},
'default' => ['dns', 'gateway'],
'dns' => ['169.254.1.2'],
'gateway' => '169.254.1.3'
}
}
end

context 'when vmx_options are provided as a Hash' do
let(:vm_type) do
{
'ram' => 512,
'disk' => 2048,
'cpu' => 1,
'vmx_options' => {
vmx_option_key => 'some_value'
}
}
end

it 'can set the defined vmx_options as configuration properties' do
begin
vm_id = @cpi.create_vm(
'agent-007',
@stemcell_id,
vm_type,
network_spec
)
vm = @cpi.vm_provider.find(vm_id)

found_vmx_option = vm.mob.config.extra_config.find {|c| c.key == vmx_option_key}
expect(found_vmx_option).not_to be_nil
expect(found_vmx_option.value).to eq('some_value')
ensure
delete_vm(@cpi, vm_id)
end
end
end

context 'when vmx_options are NOT a Hash' do
let(:vm_type) do
{
'ram' => 512,
'disk' => 2048,
'cpu' => 1,
'vmx_options' => [
vmx_option_key => 'some_value'
]
}
end

it 'can set the defined vmx_options as configuration properties' do
expect {
vm_id = @cpi.create_vm(
'agent-007',
@stemcell_id,
vm_type,
network_spec
)
}.to raise_error(/Unable to parse vmx options/)
end
end
end
31 changes: 31 additions & 0 deletions src/vsphere_cpi/spec/unit/cloud/vsphere/vm_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -686,5 +686,36 @@ module VSphereCloud
end
end
end

describe '#vmx_options' do
context 'vmx_options are specified' do
let(:input) do
{
vm_type: {
'vmx_options' => {
'sched.mem.maxmemctl' => '0'
}
}
}
end

it 'should return the vmx_options' do
expect(vm_config.vmx_options).to eq({ 'sched.mem.maxmemctl' => '0' })
end
end

context 'vmx_options are NOT specified' do
let(:input) do
{
vm_type: {}
}
end

it 'should return empty hash' do
expect(vm_config.vmx_options).to eq({})
end
end

end
end
end

0 comments on commit c73c05a

Please sign in to comment.