Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the macOS VMs support on ARM-based Mac #429

Merged
merged 2 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions lib/vagrant-parallels/action/box_register.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ def call(env)
protected

def box_path(env)
pvm = Dir.glob(env[:machine].box.directory.join('*.pvm')).first
res = Dir.glob(env[:machine].box.directory.join('*.{pvm,macvm}')).first

if !pvm
if !res
raise Errors::BoxImageNotFound, name: env[:machine].box.name
end

pvm
res
end

def box_id(env)
Expand Down Expand Up @@ -120,9 +120,6 @@ def register_box(env)
f.write(env[:clone_id])
end

# Convert template to VM (compatibility with old-styled boxes)
env[:machine].provider.driver.execute_prlctl(
'set', env[:clone_id], '--template', 'off')
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/vagrant-parallels/action/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module VagrantPlugins
module Parallels
module Action
class Import
include VagrantPlugins::Parallels::Util::Common
@@lock = Mutex.new

def initialize(app, env)
Expand All @@ -24,7 +25,8 @@ def call(env)
end

# Linked clones are supported only for PD 11 and higher
if env[:machine].provider_config.linked_clone
# Linked clones are not supported in macvms
if env[:machine].provider_config.linked_clone and !is_macvm(env)
# Linked clone creation should not be concurrent [GH-206]
options[:snapshot_id] = env[:clone_snapshot_id]
options[:linked] = true
Expand Down
7 changes: 7 additions & 0 deletions lib/vagrant-parallels/action/prepare_clone_snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module VagrantPlugins
module Parallels
module Action
class PrepareCloneSnapshot
include VagrantPlugins::Parallels::Util::Common
@@lock = Mutex.new

def initialize(app, env)
Expand All @@ -19,6 +20,12 @@ def call(env)
return @app.call(env)
end

if is_macvm(env)
#Ignore, since macvms doesn't support snapshot creation
@logger.info('Snapshot creation is not supported yet for macOS ARM Guests, skip snapshot preparing')
return @app.call(env)
end

# If we're not doing a linked clone, snapshots don't matter
if !env[:machine].provider_config.linked_clone
return @app.call(env)
Expand Down
5 changes: 5 additions & 0 deletions lib/vagrant-parallels/action/sane_defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module VagrantPlugins
module Parallels
module Action
class SaneDefaults
include VagrantPlugins::Parallels::Util::Common

def initialize(app, env)
@logger = Log4r::Logger.new('vagrant_parallels::action::sanedefaults')
@app = app
Expand All @@ -27,6 +29,9 @@ def call(env)
private

def default_settings
# Options defined below are not supported for `*.macvm` VMs
return {} if is_macvm(@env)

{
tools_autoupdate: 'no',
on_shutdown: 'close',
Expand Down
1 change: 1 addition & 0 deletions lib/vagrant-parallels/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ module Model

module Util
autoload :CompileForwardedPorts, File.expand_path('../util/compile_forwarded_ports', __FILE__)
autoload :Common, File.expand_path('../util/common', __FILE__)
end
end
end
15 changes: 15 additions & 0 deletions lib/vagrant-parallels/util/common.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module VagrantPlugins
module Parallels
module Util
module Common

# Determines whether the VM's box contains a macOS guest for an Apple Silicon host.
# In this case the image file ends with '.macvm' instead of '.pvm'
def is_macvm(env)
return !!Dir.glob(env[:machine].box.directory.join('*.macvm')).first
end

end
end
end
end
2 changes: 1 addition & 1 deletion locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ en:
Box VM config: "%{config}"

box_image_not_found: |-
Parallels VM image (*.pvm) could not be found in the directory of
Parallels VM image (*.pvm or *.macvm) could not be found in the directory of
'%{name}' box. This is usually because the image has been removed manually.
Please remove the box, re-add it, and try again.
dhcp_leases_file_not_accessible: |-
Expand Down