From 3be28bc978419c9a2de6b3cd793e34ed45c37238 Mon Sep 17 00:00:00 2001 From: Aleksandr Sursiakov Date: Wed, 29 Jun 2022 11:39:08 +0300 Subject: [PATCH 1/2] Test macOS VM on ARM --- lib/vagrant-parallels/action/box_register.rb | 14 ++++++-- lib/vagrant-parallels/action/sane_defaults.rb | 32 ++++++++++--------- locales/en.yml | 2 +- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/lib/vagrant-parallels/action/box_register.rb b/lib/vagrant-parallels/action/box_register.rb index 16df1642..73bfd08f 100644 --- a/lib/vagrant-parallels/action/box_register.rb +++ b/lib/vagrant-parallels/action/box_register.rb @@ -40,6 +40,14 @@ def call(env) def box_path(env) pvm = Dir.glob(env[:machine].box.directory.join('*.pvm')).first + mac_vm_m1 = false + + if !pvm + pvm = Dir.glob(env[:machine].box.directory.join('*.macvm')).first + if pvm + mac_vm_m1 = true + end + end if !pvm raise Errors::BoxImageNotFound, name: env[:machine].box.name @@ -121,8 +129,10 @@ def register_box(env) end # Convert template to VM (compatibility with old-styled boxes) - env[:machine].provider.driver.execute_prlctl( - 'set', env[:clone_id], '--template', 'off') + # 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 diff --git a/lib/vagrant-parallels/action/sane_defaults.rb b/lib/vagrant-parallels/action/sane_defaults.rb index 28334232..364116dd 100644 --- a/lib/vagrant-parallels/action/sane_defaults.rb +++ b/lib/vagrant-parallels/action/sane_defaults.rb @@ -28,21 +28,23 @@ def call(env) def default_settings { - 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' + # 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' } end end diff --git a/locales/en.yml b/locales/en.yml index 711fa423..e3e756d6 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -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: |- From 300aa9f735ba4257bcfbbd34d2f5fa954487461a Mon Sep 17 00:00:00 2001 From: Bineesh N Date: Tue, 13 Dec 2022 12:32:39 +0400 Subject: [PATCH 2/2] Fix vagrant up command for macOS guests in Apple Silicon host --- lib/vagrant-parallels/action/box_register.rb | 19 ++-------- lib/vagrant-parallels/action/import.rb | 4 +- .../action/prepare_clone_snapshot.rb | 7 ++++ lib/vagrant-parallels/action/sane_defaults.rb | 37 ++++++++++--------- lib/vagrant-parallels/plugin.rb | 1 + lib/vagrant-parallels/util/common.rb | 15 ++++++++ 6 files changed, 49 insertions(+), 34 deletions(-) create mode 100644 lib/vagrant-parallels/util/common.rb diff --git a/lib/vagrant-parallels/action/box_register.rb b/lib/vagrant-parallels/action/box_register.rb index 73bfd08f..221a940f 100644 --- a/lib/vagrant-parallels/action/box_register.rb +++ b/lib/vagrant-parallels/action/box_register.rb @@ -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) @@ -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 diff --git a/lib/vagrant-parallels/action/import.rb b/lib/vagrant-parallels/action/import.rb index 823031dd..d25330a1 100644 --- a/lib/vagrant-parallels/action/import.rb +++ b/lib/vagrant-parallels/action/import.rb @@ -4,6 +4,7 @@ module VagrantPlugins module Parallels module Action class Import + include VagrantPlugins::Parallels::Util::Common @@lock = Mutex.new def initialize(app, env) @@ -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 diff --git a/lib/vagrant-parallels/action/prepare_clone_snapshot.rb b/lib/vagrant-parallels/action/prepare_clone_snapshot.rb index d6ceda25..50a86fbf 100644 --- a/lib/vagrant-parallels/action/prepare_clone_snapshot.rb +++ b/lib/vagrant-parallels/action/prepare_clone_snapshot.rb @@ -6,6 +6,7 @@ module VagrantPlugins module Parallels module Action class PrepareCloneSnapshot + include VagrantPlugins::Parallels::Util::Common @@lock = Mutex.new def initialize(app, env) @@ -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) diff --git a/lib/vagrant-parallels/action/sane_defaults.rb b/lib/vagrant-parallels/action/sane_defaults.rb index 364116dd..ae97d6b2 100644 --- a/lib/vagrant-parallels/action/sane_defaults.rb +++ b/lib/vagrant-parallels/action/sane_defaults.rb @@ -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 @@ -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 diff --git a/lib/vagrant-parallels/plugin.rb b/lib/vagrant-parallels/plugin.rb index 45c39ff9..06afd644 100644 --- a/lib/vagrant-parallels/plugin.rb +++ b/lib/vagrant-parallels/plugin.rb @@ -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 diff --git a/lib/vagrant-parallels/util/common.rb b/lib/vagrant-parallels/util/common.rb new file mode 100644 index 00000000..80af6749 --- /dev/null +++ b/lib/vagrant-parallels/util/common.rb @@ -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