Skip to content

Commit

Permalink
Merge pull request #429 from Parallels/macos-vm-m1
Browse files Browse the repository at this point in the history
Fixing 'vagrant up' command for m1 mac
  • Loading branch information
legal90 authored Dec 15, 2022
2 parents 0e7230d + 300aa9f commit 360c0b0
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 8 deletions.
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

0 comments on commit 360c0b0

Please sign in to comment.