mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Allow specification of cpuset (#923)
Allows the pinning of vcpus to physical cpus.
This commit is contained in:
parent
398258e306
commit
60ef4b03d1
@ -297,12 +297,14 @@ end
|
||||
Libvirt](https://libvirt.org/formatdomain.html#elementsNICSModel).
|
||||
* `memory` - Amount of memory in MBytes. Defaults to 512 if not set.
|
||||
* `cpus` - Number of virtual cpus. Defaults to 1 if not set.
|
||||
* `cpuset` - Physical cpus to which the vcpus can be pinned. For more details see [documentation](https://libvirt.org/formatdomain.html#elementsCPUAllocation).
|
||||
* `cputopology` - Number of CPU sockets, cores and threads running per core. All fields of `:sockets`, `:cores` and `:threads` are mandatory, `cpus` domain option must be present and must be equal to total count of **sockets * cores * threads**. For more details see [documentation](https://libvirt.org/formatdomain.html#elementsCPU).
|
||||
|
||||
```ruby
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.provider :libvirt do |libvirt|
|
||||
libvirt.cpus = 4
|
||||
libvirt.cpuset = '1-4,^3,6'
|
||||
libvirt.cputopology :sockets => '2', :cores => '2', :threads => '1'
|
||||
end
|
||||
end
|
||||
|
@ -33,6 +33,7 @@ module VagrantPlugins
|
||||
@name = env[:domain_name]
|
||||
@uuid = config.uuid
|
||||
@cpus = config.cpus.to_i
|
||||
@cpuset = config.cpuset
|
||||
@cpu_features = config.cpu_features
|
||||
@cpu_topology = config.cpu_topology
|
||||
@features = config.features
|
||||
@ -189,6 +190,9 @@ module VagrantPlugins
|
||||
env[:ui].info(" -- Forced UUID: #{@uuid}") if @uuid != ''
|
||||
env[:ui].info(" -- Domain type: #{@domain_type}")
|
||||
env[:ui].info(" -- Cpus: #{@cpus}")
|
||||
unless @cpuset.nil?
|
||||
env[:ui].info(" -- Cpuset: #{@cpuset}")
|
||||
end
|
||||
if not @cpu_topology.empty?
|
||||
env[:ui].info(" -- CPU topology: sockets=#{@cpu_topology[:sockets]}, cores=#{@cpu_topology[:cores]}, threads=#{@cpu_topology[:threads]}")
|
||||
end
|
||||
|
@ -68,7 +68,7 @@ module VagrantPlugins
|
||||
end
|
||||
|
||||
# vCpu count
|
||||
if config.cpus.to_i != libvirt_domain.vcpus.length
|
||||
if config.cpus.to_i != libvirt_domain.num_vcpus(0)
|
||||
descr_changed = true
|
||||
REXML::XPath.first(xml_descr, '/domain/vcpu').text = config.cpus
|
||||
end
|
||||
|
@ -72,6 +72,7 @@ module VagrantPlugins
|
||||
attr_accessor :memory_backing
|
||||
attr_accessor :channel
|
||||
attr_accessor :cpus
|
||||
attr_accessor :cpuset
|
||||
attr_accessor :cpu_mode
|
||||
attr_accessor :cpu_model
|
||||
attr_accessor :cpu_fallback
|
||||
@ -195,6 +196,7 @@ module VagrantPlugins
|
||||
@memory = UNSET_VALUE
|
||||
@memory_backing = UNSET_VALUE
|
||||
@cpus = UNSET_VALUE
|
||||
@cpuset = UNSET_VALUE
|
||||
@cpu_mode = UNSET_VALUE
|
||||
@cpu_model = UNSET_VALUE
|
||||
@cpu_fallback = UNSET_VALUE
|
||||
@ -672,6 +674,7 @@ module VagrantPlugins
|
||||
@memory = 512 if @memory == UNSET_VALUE
|
||||
@memory_backing = [] if @memory_backing == UNSET_VALUE
|
||||
@cpus = 1 if @cpus == UNSET_VALUE
|
||||
@cpuset = nil if @cpuset == UNSET_VALUE
|
||||
@cpu_mode = 'host-model' if @cpu_mode == UNSET_VALUE
|
||||
@cpu_model = if (@cpu_model == UNSET_VALUE) && (@cpu_mode == 'custom')
|
||||
'qemu64'
|
||||
|
@ -2,7 +2,7 @@
|
||||
<name><%= @name %></name>
|
||||
<uuid><%= @uuid %></uuid>
|
||||
<memory><%= @memory_size %></memory>
|
||||
<vcpu><%= @cpus %></vcpu>
|
||||
<vcpu<% if @cpuset %> cpuset='<%= @cpuset %>'<% end %>><%= @cpus %></vcpu>
|
||||
|
||||
|
||||
<cpu mode='<%= @cpu_mode %>'>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<name></name>
|
||||
<uuid></uuid>
|
||||
<memory></memory>
|
||||
<vcpu>1</vcpu>
|
||||
<vcpu cpuset='1-4,^3,6'>1</vcpu>
|
||||
|
||||
|
||||
<cpu mode='custom'>
|
||||
|
@ -76,6 +76,7 @@ describe 'templates/domain' do
|
||||
|
||||
domain.qemuargs(value: '-device')
|
||||
domain.qemuargs(value: 'dummy-device')
|
||||
domain.cpuset = '1-4,^3,6'
|
||||
end
|
||||
let(:test_file) { 'domain_all_settings.xml' }
|
||||
it 'renders template' do
|
||||
|
Loading…
Reference in New Issue
Block a user