mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Merge pull request #554 from infernix/cpu-features
Enable CPU features support
This commit is contained in:
commit
c6d5c1a3a6
22
README.md
22
README.md
@ -30,6 +30,7 @@ welcome and can help a lot :-)
|
|||||||
- [CDROMs](#cdroms)
|
- [CDROMs](#cdroms)
|
||||||
- [Input](#input)
|
- [Input](#input)
|
||||||
- [PCI device passthrough](#pci-device-passthrough)
|
- [PCI device passthrough](#pci-device-passthrough)
|
||||||
|
- [CPU Features](#cpu-features)
|
||||||
- [No box and PXE boot](#no-box-and-pxe-boot)
|
- [No box and PXE boot](#no-box-and-pxe-boot)
|
||||||
- [SSH Access To VM](#ssh-access-to-vm)
|
- [SSH Access To VM](#ssh-access-to-vm)
|
||||||
- [Forwarded Ports](#forwarded-ports)
|
- [Forwarded Ports](#forwarded-ports)
|
||||||
@ -542,6 +543,27 @@ Vagrant.configure("2") do |config|
|
|||||||
end
|
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
|
## 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:
|
You can specify multiple USB devices to passthrough to the VM via `libvirt.usb`. The device can be specified by the following options:
|
||||||
|
@ -33,6 +33,7 @@ module VagrantPlugins
|
|||||||
@name = env[:domain_name]
|
@name = env[:domain_name]
|
||||||
@uuid = config.uuid
|
@uuid = config.uuid
|
||||||
@cpus = config.cpus.to_i
|
@cpus = config.cpus.to_i
|
||||||
|
@cpu_features = config.cpu_features
|
||||||
@cpu_mode = config.cpu_mode
|
@cpu_mode = config.cpu_mode
|
||||||
@loader = config.loader
|
@loader = config.loader
|
||||||
@machine_type = config.machine_type
|
@machine_type = config.machine_type
|
||||||
@ -150,6 +151,9 @@ module VagrantPlugins
|
|||||||
end
|
end
|
||||||
env[:ui].info(" -- Domain type: #{@domain_type}")
|
env[:ui].info(" -- Domain type: #{@domain_type}")
|
||||||
env[:ui].info(" -- Cpus: #{@cpus}")
|
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(" -- Memory: #{@memory_size / 1024}M")
|
||||||
env[:ui].info(" -- Management MAC: #{@management_network_mac}")
|
env[:ui].info(" -- Management MAC: #{@management_network_mac}")
|
||||||
env[:ui].info(" -- Loader: #{@loader}")
|
env[:ui].info(" -- Loader: #{@loader}")
|
||||||
|
@ -58,6 +58,7 @@ module VagrantPlugins
|
|||||||
attr_accessor :memory
|
attr_accessor :memory
|
||||||
attr_accessor :cpus
|
attr_accessor :cpus
|
||||||
attr_accessor :cpu_mode
|
attr_accessor :cpu_mode
|
||||||
|
attr_accessor :cpu_features
|
||||||
attr_accessor :loader
|
attr_accessor :loader
|
||||||
attr_accessor :boot_order
|
attr_accessor :boot_order
|
||||||
attr_accessor :machine_type
|
attr_accessor :machine_type
|
||||||
@ -128,6 +129,7 @@ module VagrantPlugins
|
|||||||
@memory = UNSET_VALUE
|
@memory = UNSET_VALUE
|
||||||
@cpus = UNSET_VALUE
|
@cpus = UNSET_VALUE
|
||||||
@cpu_mode = UNSET_VALUE
|
@cpu_mode = UNSET_VALUE
|
||||||
|
@cpu_features = UNSET_VALUE
|
||||||
@loader = UNSET_VALUE
|
@loader = UNSET_VALUE
|
||||||
@machine_type = UNSET_VALUE
|
@machine_type = UNSET_VALUE
|
||||||
@machine_arch = UNSET_VALUE
|
@machine_arch = UNSET_VALUE
|
||||||
@ -209,6 +211,21 @@ module VagrantPlugins
|
|||||||
raise 'Only four cdroms may be attached at a time'
|
raise 'Only four cdroms may be attached at a time'
|
||||||
end
|
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={})
|
def input(options={})
|
||||||
if options[:type].nil? || options[:bus].nil?
|
if options[:type].nil? || options[:bus].nil?
|
||||||
raise 'Input type AND bus must be specified'
|
raise 'Input type AND bus must be specified'
|
||||||
@ -390,6 +407,7 @@ module VagrantPlugins
|
|||||||
@memory = 512 if @memory == UNSET_VALUE
|
@memory = 512 if @memory == UNSET_VALUE
|
||||||
@cpus = 1 if @cpus == UNSET_VALUE
|
@cpus = 1 if @cpus == UNSET_VALUE
|
||||||
@cpu_mode = 'host-model' if @cpu_mode == UNSET_VALUE
|
@cpu_mode = 'host-model' if @cpu_mode == UNSET_VALUE
|
||||||
|
@cpu_features = [] if @cpu_features == UNSET_VALUE
|
||||||
@loader = nil if @loader == UNSET_VALUE
|
@loader = nil if @loader == UNSET_VALUE
|
||||||
@machine_type = nil if @machine_type == UNSET_VALUE
|
@machine_type = nil if @machine_type == UNSET_VALUE
|
||||||
@machine_arch = nil if @machine_arch == UNSET_VALUE
|
@machine_arch = nil if @machine_arch == UNSET_VALUE
|
||||||
|
@ -12,6 +12,9 @@
|
|||||||
<feature policy='optional' name='vmx'/>
|
<feature policy='optional' name='vmx'/>
|
||||||
<feature policy='optional' name='svm'/>
|
<feature policy='optional' name='svm'/>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<% @cpu_features.each do |cpu_feature| %>
|
||||||
|
<feature name='<%= cpu_feature[:name] %>' policy='<%= cpu_feature[:policy] %>'/>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</cpu>
|
</cpu>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user