diff --git a/README.md b/README.md index edb1bc0..3731b39 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ welcome and can help a lot :-) - [CDROMs](#cdroms) - [Input](#input) - [PCI device passthrough](#pci-device-passthrough) +- [CPU Features](#cpu-features) - [No box and PXE boot](#no-box-and-pxe-boot) - [SSH Access To VM](#ssh-access-to-vm) - [Forwarded Ports](#forwarded-ports) @@ -542,6 +543,27 @@ Vagrant.configure("2") do |config| end ``` +## CPU features + +You can specify CPU feature policies via `libvirt.cpu_feature`. Available options are +listed below. Note that both options are required: + +* `name` - The name of the feature for the chosen CPU (see libvirts `cpu_map.xml`) +* `policy` - The policy for this feature (one of `force`, `require`, `optional`, `disable` and `forbid` - see libvirt documentation) + +```ruby +Vagrant.configure("2") do |config| + config.vm.provider :libvirt do |libvirt| + # The feature will not be supported by virtual CPU. + libvirt.cpu_feature :name => 'hypervisor', :policy => 'disable' + # Guest creation will fail unless the feature is supported by host CPU. + libvirt.cpu_feature :name => 'vmx', :policy => 'require' + # The virtual CPU will claim the feature is supported regardless of it being supported by host CPU. + libvirt.cpu_feature :name => 'pdpe1gb', :policy => 'force' + end +end +``` + ## USB device passthrough You can specify multiple USB devices to passthrough to the VM via `libvirt.usb`. The device can be specified by the following options: diff --git a/lib/vagrant-libvirt/action/create_domain.rb b/lib/vagrant-libvirt/action/create_domain.rb index deecf86..0c34674 100644 --- a/lib/vagrant-libvirt/action/create_domain.rb +++ b/lib/vagrant-libvirt/action/create_domain.rb @@ -33,6 +33,7 @@ module VagrantPlugins @name = env[:domain_name] @uuid = config.uuid @cpus = config.cpus.to_i + @cpu_features = config.cpu_features @cpu_mode = config.cpu_mode @loader = config.loader @machine_type = config.machine_type @@ -150,6 +151,9 @@ module VagrantPlugins end env[:ui].info(" -- Domain type: #{@domain_type}") env[:ui].info(" -- Cpus: #{@cpus}") + @cpu_features.each do |cpu_feature| + env[:ui].info(" -- CPU Feature: name=#{cpu_feature[:name]}, policy=#{cpu_feature[:policy]}") + end env[:ui].info(" -- Memory: #{@memory_size / 1024}M") env[:ui].info(" -- Management MAC: #{@management_network_mac}") env[:ui].info(" -- Loader: #{@loader}") diff --git a/lib/vagrant-libvirt/config.rb b/lib/vagrant-libvirt/config.rb index 27bfbea..95db8bc 100644 --- a/lib/vagrant-libvirt/config.rb +++ b/lib/vagrant-libvirt/config.rb @@ -58,6 +58,7 @@ module VagrantPlugins attr_accessor :memory attr_accessor :cpus attr_accessor :cpu_mode + attr_accessor :cpu_features attr_accessor :loader attr_accessor :boot_order attr_accessor :machine_type @@ -128,6 +129,7 @@ module VagrantPlugins @memory = UNSET_VALUE @cpus = UNSET_VALUE @cpu_mode = UNSET_VALUE + @cpu_features = UNSET_VALUE @loader = UNSET_VALUE @machine_type = UNSET_VALUE @machine_arch = UNSET_VALUE @@ -209,6 +211,21 @@ module VagrantPlugins raise 'Only four cdroms may be attached at a time' end + def cpu_feature(options={}) + if options[:name].nil? || options[:policy].nil? + raise 'CPU Feature name AND policy must be specified' + end + + if @cpu_features == UNSET_VALUE + @cpu_features = [] + end + + @cpu_features.push({ + name: options[:name], + policy: options[:policy] + }) + end + def input(options={}) if options[:type].nil? || options[:bus].nil? raise 'Input type AND bus must be specified' @@ -390,6 +407,7 @@ module VagrantPlugins @memory = 512 if @memory == UNSET_VALUE @cpus = 1 if @cpus == UNSET_VALUE @cpu_mode = 'host-model' if @cpu_mode == UNSET_VALUE + @cpu_features = [] if @cpu_features == UNSET_VALUE @loader = nil if @loader == UNSET_VALUE @machine_type = nil if @machine_type == UNSET_VALUE @machine_arch = nil if @machine_arch == UNSET_VALUE diff --git a/lib/vagrant-libvirt/templates/domain.xml.erb b/lib/vagrant-libvirt/templates/domain.xml.erb index 27499f2..5c9cf29 100644 --- a/lib/vagrant-libvirt/templates/domain.xml.erb +++ b/lib/vagrant-libvirt/templates/domain.xml.erb @@ -12,6 +12,9 @@ <% end %> + <% @cpu_features.each do |cpu_feature| %> + + <% end %> <% end %>