mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Add support for configuring memballoon-related settings (#1083)
Allow configuration of various memballoon-related settings. It was discovered that it may be needed to be able to control the memballoon's PCI slot/bus location in order to prevent it from conflicting with other explicit PCI location assignments. For example when configuring the management network NIC to go to slot 0x05, libvirt would try to put the memballoon there as well and resulting in a fatal error.
This commit is contained in:
22
README.md
22
README.md
@@ -1444,6 +1444,28 @@ Vagrant.configure("2") do |config|
|
||||
end
|
||||
```
|
||||
|
||||
## Memory balloon
|
||||
|
||||
The configuration of the memory balloon device can be overridden. By default,
|
||||
libvirt will automatically attach a memory balloon; this behavior is preserved
|
||||
by not configuring any memballoon-related options. The memory balloon can be
|
||||
explicitly disabled by setting `memballoon_enabled` to `false`. Setting
|
||||
`memballoon_enabled` to `true` will allow additional configuration of
|
||||
memballoon-related options.
|
||||
|
||||
Here is an example of using the memballoon options:
|
||||
|
||||
```ruby
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.provider :libvirt do |libvirt|
|
||||
libvirt.memballoon_enabled = true
|
||||
libvirt.memballoon_model = 'virtio'
|
||||
libvirt.memballoon_pci_bus = '0x00'
|
||||
libvirt.memballoon_pci_slot = '0x0f'
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
## Libvirt communication channels
|
||||
|
||||
For certain functionality to be available within a guest, a private
|
||||
|
||||
@@ -119,6 +119,12 @@ module VagrantPlugins
|
||||
attr_accessor :tpm_path
|
||||
attr_accessor :tpm_version
|
||||
|
||||
# Configure the memballoon
|
||||
attr_accessor :memballoon_enabled
|
||||
attr_accessor :memballoon_model
|
||||
attr_accessor :memballoon_pci_bus
|
||||
attr_accessor :memballoon_pci_slot
|
||||
|
||||
# Sets the max number of NICs that can be created
|
||||
# Default set to 8. Don't change the default unless you know
|
||||
# what are doing
|
||||
@@ -248,6 +254,11 @@ module VagrantPlugins
|
||||
@tpm_path = UNSET_VALUE
|
||||
@tpm_version = UNSET_VALUE
|
||||
|
||||
@memballoon_enabled = UNSET_VALUE
|
||||
@memballoon_model = UNSET_VALUE
|
||||
@memballoon_pci_bus = UNSET_VALUE
|
||||
@memballoon_pci_slot = UNSET_VALUE
|
||||
|
||||
@nic_adapter_count = UNSET_VALUE
|
||||
|
||||
# Boot order
|
||||
@@ -784,6 +795,10 @@ module VagrantPlugins
|
||||
@tpm_type = 'passthrough' if @tpm_type == UNSET_VALUE
|
||||
@tpm_path = nil if @tpm_path == UNSET_VALUE
|
||||
@tpm_version = nil if @tpm_version == UNSET_VALUE
|
||||
@memballoon_enabled = nil if @memballoon_enabled == UNSET_VALUE
|
||||
@memballoon_model = 'virtio' if @memballoon_model == UNSET_VALUE
|
||||
@memballoon_pci_bus = '0x00' if @memballoon_pci_bus == UNSET_VALUE
|
||||
@memballoon_pci_slot = '0x0f' if @memballoon_pci_slot == UNSET_VALUE
|
||||
@nic_adapter_count = 8 if @nic_adapter_count == UNSET_VALUE
|
||||
@emulator_path = nil if @emulator_path == UNSET_VALUE
|
||||
|
||||
|
||||
@@ -271,6 +271,15 @@
|
||||
<%# USB Controller -%>
|
||||
<controller type='usb' model='<%= @usbctl_dev[:model] %>' <%= "ports=\"#{@usbctl_dev[:ports]}\" " if @usbctl_dev[:ports] %>/>
|
||||
<% end %>
|
||||
<% unless @memballoon_enabled.nil? %>
|
||||
<% if @memballoon_enabled %>
|
||||
<memballoon model='<%= @memballoon_model %>'>
|
||||
<address type='pci' domain='0x0000' bus='<%= @memballoon_pci_bus %>' slot='<%= @memballoon_pci_slot %>' function='0x0'/>
|
||||
</memballoon>
|
||||
<% else %>
|
||||
<memballoon model='none'/>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</devices>
|
||||
|
||||
<% if not @qemu_args.empty? or not @qemu_env.empty? %>
|
||||
|
||||
@@ -129,4 +129,54 @@ describe 'templates/domain' do
|
||||
expect(domain.to_xml('domain')).to eq xml_expected
|
||||
end
|
||||
end
|
||||
|
||||
context 'memballoon' do
|
||||
context 'default' do
|
||||
it 'renders without specifying the xml tag' do
|
||||
domain.finalize!
|
||||
|
||||
expect(domain.to_xml('domain')).to_not match(/memballoon/)
|
||||
end
|
||||
end
|
||||
|
||||
context 'memballon enabled' do
|
||||
before do
|
||||
domain.memballoon_enabled = true
|
||||
end
|
||||
|
||||
it 'renders with memballon element' do
|
||||
domain.finalize!
|
||||
|
||||
expect(domain.to_xml('domain')).to match(/<memballoon model='virtio'>/)
|
||||
expect(domain.to_xml('domain')).to match(/<address type='pci' domain='0x0000' bus='0x00' slot='0x0f' function='0x0'\/>/)
|
||||
end
|
||||
|
||||
context 'all settings specified' do
|
||||
before do
|
||||
domain.memballoon_model = "virtio-non-transitional"
|
||||
domain.memballoon_pci_bus = "0x01"
|
||||
domain.memballoon_pci_slot = "0x05"
|
||||
end
|
||||
|
||||
it 'renders with specified values' do
|
||||
domain.finalize!
|
||||
|
||||
expect(domain.to_xml('domain')).to match(/<memballoon model='virtio-non-transitional'>/)
|
||||
expect(domain.to_xml('domain')).to match(/<address type='pci' domain='0x0000' bus='0x01' slot='0x05' function='0x0'\/>/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'memballon disabled' do
|
||||
before do
|
||||
domain.memballoon_enabled = false
|
||||
end
|
||||
|
||||
it 'renders the memballoon element with model none' do
|
||||
domain.finalize!
|
||||
|
||||
expect(domain.to_xml('domain')).to match(/<memballoon model='none'\/>/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user