diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb
index 8bc28f3..b9f8c83 100644
--- a/lib/vagrant-libvirt/action/create_domain.rb
+++ b/lib/vagrant-libvirt/action/create_domain.rb
@@ -34,6 +34,7 @@ module VagrantPlugins
@uuid = config.uuid
@cpus = config.cpus.to_i
@cpu_features = config.cpu_features
+ @cpu_topology = config.cpu_topology
@features = config.features
@cpu_mode = config.cpu_mode
@cpu_model = config.cpu_model
@@ -176,6 +177,10 @@ module VagrantPlugins
env[:ui].info(" -- Forced UUID: #{@uuid}") if @uuid != ''
env[:ui].info(" -- Domain type: #{@domain_type}")
env[:ui].info(" -- Cpus: #{@cpus}")
+ if not @cpu_topology.empty?
+ env[:ui].info(" -- CPU topology: sockets=#{@cpu_topology[:sockets]}, cores=#{@cpu_topology[:cores]}, threads=#{@cpu_topology[:threads]}")
+ end
+ env[:ui].info("")
@cpu_features.each do |cpu_feature|
env[:ui].info(" -- CPU Feature: name=#{cpu_feature[:name]}, policy=#{cpu_feature[:policy]}")
end
diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb
index d08ef29..8439089 100644
--- a/lib/vagrant-libvirt/config.rb
+++ b/lib/vagrant-libvirt/config.rb
@@ -65,6 +65,7 @@ module VagrantPlugins
attr_accessor :cpu_model
attr_accessor :cpu_fallback
attr_accessor :cpu_features
+ attr_accessor :cpu_topology
attr_accessor :features
attr_accessor :numa_nodes
attr_accessor :loader
@@ -171,6 +172,7 @@ module VagrantPlugins
@cpu_model = UNSET_VALUE
@cpu_fallback = UNSET_VALUE
@cpu_features = UNSET_VALUE
+ @cpu_topology = UNSET_VALUE
@features = UNSET_VALUE
@numa_nodes = UNSET_VALUE
@loader = UNSET_VALUE
@@ -315,6 +317,20 @@ module VagrantPlugins
policy: options[:policy])
end
+ def cputopology(options = {})
+ if options[:sockets].nil? || options[:cores].nil? || options[:threads].nil?
+ raise 'CPU topology must have all of sockets, cores and threads specified'
+ end
+
+ if @cpu_topology == UNSET_VALUE
+ @cpu_topology = {}
+ end
+
+ @cpu_topology[:sockets] = options[:sockets]
+ @cpu_topology[:cores] = options[:cores]
+ @cpu_topology[:threads] = options[:threads]
+ end
+
def memorybacking(option, config = {})
case option
when :source
@@ -594,6 +610,7 @@ module VagrantPlugins
elsif @cpu_mode != 'custom'
''
end
+ @cpu_topology = {} if @cpu_topology == UNSET_VALUE
@cpu_fallback = 'allow' if @cpu_fallback == UNSET_VALUE
@cpu_features = [] if @cpu_features == UNSET_VALUE
@features = ['acpi','apic','pae'] if @features == UNSET_VALUE
diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb
index 4e689b2..ee159ad 100644
--- a/lib/vagrant-libvirt/templates/domain.xml.erb
+++ b/lib/vagrant-libvirt/templates/domain.xml.erb
@@ -15,6 +15,10 @@
<% @cpu_features.each do |cpu_feature| %>
<% end %>
+ <% unless @cpu_topology.empty? %>
+ <%# CPU topology -%>
+
+ <% end %>
<% end %>
<% if @numa_nodes %>
diff --git a/spec/unit/templates/domain_all_settings.xml b/spec/unit/templates/domain_all_settings.xml
index cdd8ac7..a84398f 100644
--- a/spec/unit/templates/domain_all_settings.xml
+++ b/spec/unit/templates/domain_all_settings.xml
@@ -8,6 +8,7 @@
qemu64
+
diff --git a/spec/unit/templates/domain_spec.rb b/spec/unit/templates/domain_spec.rb
index 851fe59..9b83249 100644
--- a/spec/unit/templates/domain_spec.rb
+++ b/spec/unit/templates/domain_spec.rb
@@ -31,6 +31,7 @@ describe 'templates/domain' do
domain.instance_variable_set('@domain_type', 'kvm')
domain.cpu_mode = 'custom'
domain.cpu_feature(name: 'AAA', policy: 'required')
+ domain.cputopology(sockets: '1', cores: '3', threads: '2')
domain.machine_type = 'pc-compatible'
domain.machine_arch = 'x86_64'
domain.loader = '/efi/loader'