Skip to content

Commit

Permalink
Fix vagrant up command for macOS guests in Apple Silicon host
Browse files Browse the repository at this point in the history
  • Loading branch information
bineesh-n committed Dec 15, 2022
1 parent 3be28bc commit 300aa9f
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 34 deletions.
19 changes: 3 additions & 16 deletions lib/vagrant-parallels/action/box_register.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,13 @@ def call(env)
protected

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

if !pvm
pvm = Dir.glob(env[:machine].box.directory.join('*.macvm')).first
if pvm
mac_vm_m1 = true
end
end

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

pvm
res
end

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

# Convert template to VM (compatibility with old-styled boxes)
# Not required for a macOS VM on M1 - not supported as a template and overall no such boxes anymore in public. Removed. #
# 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
37 changes: 20 additions & 17 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,24 +29,25 @@ def call(env)
private

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

{
# all commented for macOS VM, need a better solution here

# tools_autoupdate: 'no',
# on_shutdown: 'close',
# on_window_close: 'keep-running',
# auto_share_camera: 'off',
# smart_guard: 'off',
# longer_battery_life: 'on',
# shared_cloud: 'off',
# shared_profile: 'off',
# smart_mount: 'off',
# sh_app_guest_to_host: 'off',
# sh_app_host_to_guest: 'off',
# startup_view: 'headless',
# time_sync: 'on',
# disable_timezone_sync: 'on',
# shf_host_defined: 'off'
tools_autoupdate: 'no',
on_shutdown: 'close',
on_window_close: 'keep-running',
auto_share_camera: 'off',
smart_guard: 'off',
longer_battery_life: 'on',
shared_cloud: 'off',
shared_profile: 'off',
smart_mount: 'off',
sh_app_guest_to_host: 'off',
sh_app_host_to_guest: 'off',
startup_view: 'headless',
time_sync: 'on',
disable_timezone_sync: 'on',
shf_host_defined: 'off'
}
end
end
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

0 comments on commit 300aa9f

Please sign in to comment.