Skip to content

Commit

Permalink
Add support to macOS virtualization
Browse files Browse the repository at this point in the history
  • Loading branch information
laozc committed Aug 2, 2023
1 parent 8433854 commit 4efb01e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/vagrant-libvirt/action/create_domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ def call(env)
@shares = config.shares
@cpu_mode = config.cpu_mode
@cpu_model = config.cpu_model
@cpu_match = config.cpu_match
@cpu_fallback = config.cpu_fallback
@numa_nodes = config.numa_nodes
@loader = config.loader
@nvram = config.nvram
@nvram_template = config.nvram_template
@machine_type = config.machine_type
@machine_arch = config.machine_arch
@disk_controller_model = config.disk_controller_model
Expand Down Expand Up @@ -271,6 +273,7 @@ def call(env)
env[:ui].info(" -- Initrd: #{@initrd}") if @initrd
env[:ui].info(" -- Loader: #{@loader}") if @loader
env[:ui].info(" -- Nvram: #{@nvram}") if @nvram
env[:ui].info(" -- Nvram Template: #{@nvram_template}") if @nvram_template
if env[:machine].config.vm.box
env[:ui].info(" -- Base box: #{env[:machine].box.name}")
end
Expand Down
19 changes: 17 additions & 2 deletions lib/vagrant-libvirt/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class Config < Vagrant.plugin('2', :config)
attr_accessor :cpus
attr_accessor :cpuset
attr_accessor :cpu_mode
attr_accessor :cpu_match
attr_accessor :cpu_model
attr_accessor :cpu_fallback
attr_accessor :cpu_features
Expand All @@ -109,6 +110,7 @@ class Config < Vagrant.plugin('2', :config)
attr_accessor :numa_nodes
attr_accessor :loader
attr_accessor :nvram
attr_accessor :nvram_template
attr_accessor :boot_order
attr_accessor :machine_type
attr_accessor :machine_arch
Expand Down Expand Up @@ -280,6 +282,7 @@ def initialize
@cpuset = UNSET_VALUE
@cpu_mode = UNSET_VALUE
@cpu_model = UNSET_VALUE
@cpu_match = UNSET_VALUE
@cpu_fallback = UNSET_VALUE
@cpu_features = UNSET_VALUE
@cpu_topology = UNSET_VALUE
Expand All @@ -297,6 +300,7 @@ def initialize
@numa_nodes = UNSET_VALUE
@loader = UNSET_VALUE
@nvram = UNSET_VALUE
@nvram_template = UNSET_VALUE
@machine_type = UNSET_VALUE
@machine_arch = UNSET_VALUE
@machine_virtual_size = UNSET_VALUE
Expand Down Expand Up @@ -979,6 +983,13 @@ def finalize!
@memory_backing = [] if @memory_backing == UNSET_VALUE
@cpus = 1 if @cpus == UNSET_VALUE
@cpuset = nil if @cpuset == UNSET_VALUE
if @driver == 'hvf' && @cpu_mode == UNSET_VALUE && @cpu_match == UNSET_VALUE && @cpu_fallback == UNSET_VALUE && @cpu_model == UNSET_VALUE
# default value for apple hypervisor framework
@cpu_mode = 'custom'
@cpu_match = 'exact'
@cpu_fallback = 'forbid'
@cpu_model = 'host'
end
@cpu_mode = if @cpu_mode == UNSET_VALUE
# only some architectures support the cpu element
if @machine_arch.nil? || ARCH_SUPPORT_CPU.include?(@machine_arch.downcase)
Expand All @@ -995,7 +1006,8 @@ def finalize!
''
else
@cpu_model
end
end
@cpu_match = nil if @cpu_match == UNSET_VALUE
@cpu_topology = {} if @cpu_topology == UNSET_VALUE
@cpu_affinity = {} if @cpu_affinity == UNSET_VALUE
@cpu_fallback = 'allow' if @cpu_fallback == UNSET_VALUE
Expand Down Expand Up @@ -1078,7 +1090,10 @@ def finalize!
end

# Inputs
@inputs = [{ type: 'mouse', bus: 'ps2' }] if @inputs == UNSET_VALUE
if @inputs == UNSET_VALUE
# hvf does not support ps2 devices
@inputs = @driver == 'hvf' ? [] : [{ type: 'mouse', bus: 'ps2' }]
end

# Channels
@channels = [] if @channels == UNSET_VALUE
Expand Down
4 changes: 2 additions & 2 deletions lib/vagrant-libvirt/templates/domain.xml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<memory><%= @memory_size %></memory>
<vcpu<% if @cpuset %> cpuset='<%= @cpuset %>'<% end %>><%= @cpus %></vcpu>
<%- unless @cpu_mode.nil? -%>
<cpu mode='<%= @cpu_mode %>'>
<cpu mode='<%= @cpu_mode %>'<% if @cpu_match %> match='<%= @cpu_match %>'<% end %>>
<%- if @cpu_mode != 'host-passthrough' -%>
<model fallback='<%= @cpu_fallback %>'><% if @cpu_mode == 'custom' %><%= @cpu_model %><% end %></model>
<%- end -%>
Expand Down Expand Up @@ -85,7 +85,7 @@
<%- end -%>
<%- end -%>
<%- if @nvram -%>
<nvram><%= @nvram %></nvram>
<nvram<% if @nvram_template %> template='<%= @nvram_template %>'<% end %>><%= @nvram %></nvram>
<%- end -%>
<bootmenu enable='<%= @boot_order.count >= 1 ? "yes" : "no" %>'/>
<kernel><%= @kernel %></kernel>
Expand Down

0 comments on commit 4efb01e

Please sign in to comment.