From 8dcb3ee4596728b78b1c8c7366276da630d92b4f Mon Sep 17 00:00:00 2001 From: Mikhail Zholobov Date: Sun, 11 May 2014 15:10:01 +0400 Subject: [PATCH 01/14] action: Global refactoring 1) 'CheckAccessible' deleted, because Parallels VMs can not have "inaccessible" state 2) 'CheckParallels' deleted, because it is implemented by "Provider#usable?" method 3) Machine's state checking is implemented via built-in middleware: 'CheckRunning', 'CheckCreated', 'Created', 'IsRunning', 'IsSuspended' have been replaced with 'Vagrant::Buintin::IsState' 4) Message printing is implemented via built-in middleware: 'MessageAlreadyRunning', 'MessageNotRunning', 'MesageNotCreated', 'MessageWillNotDestroy' have been replaced with 'Vagrant::Buintin::Message' --- lib/vagrant-parallels/action.rb | 231 +++++++++--------- .../action/check_accessible.rb | 23 -- lib/vagrant-parallels/action/check_created.rb | 21 -- .../action/check_parallels.rb | 22 -- lib/vagrant-parallels/action/check_running.rb | 21 -- lib/vagrant-parallels/action/created.rb | 20 -- lib/vagrant-parallels/action/is_running.rb | 20 -- lib/vagrant-parallels/action/is_suspended.rb | 21 -- .../action/message_already_running.rb | 16 -- .../action/message_not_created.rb | 16 -- .../action/message_not_running.rb | 16 -- .../action/message_will_not_destroy.rb | 17 -- lib/vagrant-parallels/errors.rb | 4 - locales/en.yml | 5 - 14 files changed, 113 insertions(+), 340 deletions(-) delete mode 100644 lib/vagrant-parallels/action/check_accessible.rb delete mode 100644 lib/vagrant-parallels/action/check_created.rb delete mode 100644 lib/vagrant-parallels/action/check_parallels.rb delete mode 100644 lib/vagrant-parallels/action/check_running.rb delete mode 100644 lib/vagrant-parallels/action/created.rb delete mode 100644 lib/vagrant-parallels/action/is_running.rb delete mode 100644 lib/vagrant-parallels/action/is_suspended.rb delete mode 100644 lib/vagrant-parallels/action/message_already_running.rb delete mode 100644 lib/vagrant-parallels/action/message_not_created.rb delete mode 100644 lib/vagrant-parallels/action/message_not_running.rb delete mode 100644 lib/vagrant-parallels/action/message_will_not_destroy.rb diff --git a/lib/vagrant-parallels/action.rb b/lib/vagrant-parallels/action.rb index d91ffaf4..0ab75a58 100644 --- a/lib/vagrant-parallels/action.rb +++ b/lib/vagrant-parallels/action.rb @@ -11,21 +11,15 @@ module Action # a bootup (i.e. not saved). def self.action_boot Vagrant::Action::Builder.new.tap do |b| - b.use CheckAccessible b.use SetPowerConsumption b.use SetName - # b.use ClearForwardedPorts b.use Provision - b.use EnvSet, :port_collision_repair => true - # b.use PrepareForwardedPortCollisionParams - # b.use HandleForwardedPortCollisions b.use PrepareNFSValidIds b.use SyncedFolderCleanup b.use SyncedFolders b.use PrepareNFSSettings b.use Network b.use ClearNetworkInterfaces - # b.use ForwardPorts b.use SetHostname # b.use SaneDefaults b.use Customize, "pre-boot" @@ -40,26 +34,27 @@ def self.action_boot # freeing the resources of the underlying virtual machine. def self.action_destroy Vagrant::Action::Builder.new.tap do |b| - b.use CheckParallels - b.use Call, Created do |env1, b2| - if !env1[:result] - b2.use MessageNotCreated + b.use ConfigValidate + b.use Call, IsState, :not_created do |env1, b1| + if env1[:result] + b1.use Message, I18n.t("vagrant.commands.common.vm_not_created") next end - b2.use Call, DestroyConfirm do |env2, b3| - if env2[:result] - b3.use CheckAccessible - b3.use EnvSet, :force_halt => true - b3.use action_halt - b3.use Destroy - b3.use DestroyUnusedNetworkInterfaces - b3.use ProvisionerCleanup - b3.use PrepareNFSValidIds - b3.use SyncedFolderCleanup - else - b3.use MessageWillNotDestroy + b1.use Call, DestroyConfirm do |env2, b2| + if !env2[:result] + b2.use Message, I18n.t("vagrant.commands.destroy.will_not_destroy", + :name => env2[:machine].name) + next end + + b2.use EnvSet, :force_halt => true + b2.use action_halt + b2.use Destroy + b2.use DestroyUnusedNetworkInterfaces + b2.use ProvisionerCleanup + b2.use PrepareNFSValidIds + b2.use SyncedFolderCleanup end end end @@ -69,23 +64,23 @@ def self.action_destroy # the virtual machine, gracefully or by force. def self.action_halt Vagrant::Action::Builder.new.tap do |b| - b.use CheckParallels - b.use Call, Created do |env, b2| - if env[:result] - b2.use CheckAccessible + b.use ConfigValidate + b.use Call, IsState, :not_created do |env1, b1| + if env1[:result] + b1.use Message, I18n.t("vagrant.commands.common.vm_not_created") + next + end - b2.use Call, IsSuspended do |env2, b3| - next if !env2[:result] - b3.use Resume + b1.use Call, IsState, :suspended do |env2, b2| + if env2[:result] + b2.use Resume end + end - b2.use Call, GracefulHalt, :stopped, :running do |env2, b3| - if !env2[:result] - b3.use ForcedHalt - end + b1.use Call, GracefulHalt, :stopped, :running do |env2, b2| + if !env2[:result] + b2.use ForcedHalt end - else - b2.use MessageNotCreated end end end @@ -94,22 +89,20 @@ def self.action_halt # This action packages the virtual machine into a single box file. def self.action_package Vagrant::Action::Builder.new.tap do |b| - b.use CheckParallels - b.use Call, Created do |env1, b2| - if !env1[:result] - b2.use MessageNotCreated + b.use ConfigValidate + b.use Call, IsState, :not_created do |env1, b1| + if env1[:result] + b1.use Message, I18n.t("vagrant.commands.common.vm_not_created") next end - b2.use SetupPackageFiles - b2.use CheckAccessible - b2.use action_halt - #b2.use ClearForwardedPorts - b2.use PrepareNFSValidIds - b2.use SyncedFolderCleanup - b2.use Package - b2.use Export - b2.use PackageConfigFiles + b1.use SetupPackageFiles + b1.use action_halt + b1.use PrepareNFSValidIds + b1.use SyncedFolderCleanup + b1.use Package + b1.use Export + b1.use PackageConfigFiles end end end @@ -117,22 +110,20 @@ def self.action_package # This action just runs the provisioners on the machine. def self.action_provision Vagrant::Action::Builder.new.tap do |b| - b.use CheckParallels b.use ConfigValidate - b.use Call, Created do |env1, b2| - if !env1[:result] - b2.use MessageNotCreated + b.use Call, IsState, :not_created do |env1, b1| + if env1[:result] + b1.use Message, I18n.t("vagrant.commands.common.vm_not_created") next end - b2.use Call, IsRunning do |env2, b3| + b1.use Call, IsState, :running do |env2, b2| if !env2[:result] - b3.use MessageNotRunning + b2.use Message, I18n.t("vagrant.commands.common.vm_not_running") next end - b3.use CheckAccessible - b3.use Provision + b2.use Provision end end end @@ -143,16 +134,15 @@ def self.action_provision # machine back up with the new configuration. def self.action_reload Vagrant::Action::Builder.new.tap do |b| - b.use CheckParallels - b.use Call, Created do |env1, b2| - if !env1[:result] - b2.use MessageNotCreated + b.use ConfigValidate + b.use Call, IsState, :not_created do |env1, b1| + if env1[:result] + b1.use Message, I18n.t("vagrant.commands.common.vm_not_created") next end - b2.use ConfigValidate - b2.use action_halt - b2.use action_start + b1.use action_halt + b1.use action_start end end end @@ -161,16 +151,15 @@ def self.action_reload # suspended machines. def self.action_resume Vagrant::Action::Builder.new.tap do |b| - b.use CheckParallels - b.use Call, Created do |env, b2| - if env[:result] - b2.use CheckAccessible - b2.use EnvSet, :port_collision_repair => false - b2.use Resume - b2.use WaitForCommunicator, [:resuming, :running] - else - b2.use MessageNotCreated + b.use ConfigValidate + b.use Call, IsState, :not_created do |env1, b1| + if env1[:result] + b1.use Message, I18n.t("vagrant.commands.common.vm_not_created") + next end + + b1.use Resume + b1.use WaitForCommunicator, [:resuming, :running] end end end @@ -178,22 +167,44 @@ def self.action_resume # This is the action that will exec into an SSH shell. def self.action_ssh Vagrant::Action::Builder.new.tap do |b| - b.use CheckParallels - b.use CheckCreated - b.use CheckAccessible - b.use CheckRunning - b.use SSHExec + b.use ConfigValidate + b.use Call, IsState, :not_created do |env1, b1| + if env1[:result] + b1.use Message, I18n.t("vagrant.commands.common.vm_not_created") + next + end + + b1.use Call, IsState, :running do |env2, b2| + if !env2[:result] + b2.use Message, I18n.t("vagrant.commands.common.vm_not_running") + next + end + + b2.use SSHExec + end + end end end # This is the action that will run a single SSH command. def self.action_ssh_run Vagrant::Action::Builder.new.tap do |b| - b.use CheckParallels - b.use CheckCreated - b.use CheckAccessible - b.use CheckRunning - b.use SSHRun + b.use ConfigValidate + b.use Call, IsState, :not_created do |env1, b1| + if env1[:result] + b1.use Message, I18n.t("vagrant.commands.common.vm_not_created") + next + end + + b1.use Call, IsState, :running do |env2, b2| + if !env2[:result] + b2.use Message, I18n.t("vagrant.commands.common.vm_not_running") + next + end + + b2.use SSHRun + end + end end end @@ -201,26 +212,24 @@ def self.action_ssh_run # A precondition of this action is that the VM exists. def self.action_start Vagrant::Action::Builder.new.tap do |b| - b.use CheckParallels - b.use ConfigValidate b.use BoxCheckOutdated - b.use Call, IsRunning do |env, b2| + b.use Call, IsState, :running do |env1, b1| # If the VM is running, then our work here is done, exit - if env[:result] - b2.use MessageAlreadyRunning + if env1[:result] + b1.use Message, I18n.t("vagrant_parallels.commands.common.vm_already_running") next end - b2.use Call, IsSuspended do |env2, b3| + b1.use Call, IsState, :suspended do |env2, b2| if env2[:result] # The VM is suspended, so just resume it - b3.use action_resume + b2.use action_resume next end # The VM is not saved, so we must have to boot it up # like normal. Boot! - b3.use action_boot + b2.use action_boot end end end @@ -230,14 +239,14 @@ def self.action_start # the virtual machine. def self.action_suspend Vagrant::Action::Builder.new.tap do |b| - b.use CheckParallels - b.use Call, Created do |env, b2| - if env[:result] - b2.use CheckAccessible - b2.use Suspend - else - b2.use MessageNotCreated + b.use ConfigValidate + b.use Call, IsState, :not_created do |env1, b1| + if env1[:result] + b1.use Message, I18n.t("vagrant.commands.common.vm_not_created") + next end + + b1.use Suspend end end end @@ -246,24 +255,21 @@ def self.action_suspend # the box, configuring metadata, and booting. def self.action_up Vagrant::Action::Builder.new.tap do |b| - b.use CheckParallels - # Handle box_url downloading early so that if the Vagrantfile # references any files in the box or something it all just # works fine. - b.use Call, Created do |env, b2| - if !env[:result] - b2.use HandleBox + b.use Call, IsState, :not_created do |env1, b1| + if env1[:result] + b1.use HandleBox end end b.use ConfigValidate - b.use Call, Created do |env, b2| + b.use Call, IsState, :not_created do |env1, b1| # If the VM is NOT created yet, then do the setup steps - if !env[:result] - b2.use CheckAccessible - b2.use Customize, "pre-import" - b2.use Import + if env1[:result] + b1.use Customize, "pre-import" + b1.use Import end end b.use action_start @@ -271,25 +277,14 @@ def self.action_up end autoload :Boot, File.expand_path("../action/boot", __FILE__) - autoload :CheckAccessible, File.expand_path("../action/check_accessible", __FILE__) - autoload :CheckCreated, File.expand_path("../action/check_created", __FILE__) autoload :CheckGuestTools, File.expand_path("../action/check_guest_tools", __FILE__) - autoload :CheckParallels, File.expand_path("../action/check_parallels", __FILE__) - autoload :CheckRunning, File.expand_path("../action/check_running", __FILE__) autoload :ClearNetworkInterfaces, File.expand_path("../action/clear_network_interfaces", __FILE__) - autoload :Created, File.expand_path("../action/created", __FILE__) autoload :Customize, File.expand_path("../action/customize", __FILE__) autoload :Destroy, File.expand_path("../action/destroy", __FILE__) autoload :DestroyUnusedNetworkInterfaces, File.expand_path("../action/destroy_unused_network_interfaces", __FILE__) autoload :Export, File.expand_path("../action/export", __FILE__) autoload :ForcedHalt, File.expand_path("../action/forced_halt", __FILE__) autoload :Import, File.expand_path("../action/import", __FILE__) - autoload :IsSuspended, File.expand_path("../action/is_suspended", __FILE__) - autoload :IsRunning, File.expand_path("../action/is_running", __FILE__) - autoload :MessageAlreadyRunning, File.expand_path("../action/message_already_running", __FILE__) - autoload :MessageNotCreated, File.expand_path("../action/message_not_created", __FILE__) - autoload :MessageNotRunning, File.expand_path("../action/message_not_running", __FILE__) - autoload :MessageWillNotDestroy, File.expand_path("../action/message_will_not_destroy", __FILE__) autoload :Network, File.expand_path("../action/network", __FILE__) autoload :Package, File.expand_path("../action/package", __FILE__) autoload :PackageConfigFiles, File.expand_path("../action/package_config_files", __FILE__) diff --git a/lib/vagrant-parallels/action/check_accessible.rb b/lib/vagrant-parallels/action/check_accessible.rb deleted file mode 100644 index d11e8bfa..00000000 --- a/lib/vagrant-parallels/action/check_accessible.rb +++ /dev/null @@ -1,23 +0,0 @@ -module VagrantPlugins - module Parallels - module Action - class CheckAccessible - def initialize(app, env) - @app = app - end - - def call(env) - if env[:machine].state.id == :inaccessible - # The VM we are attempting to manipulate is inaccessible. This - # is a very bad situation and can only be fixed by the user. It - # also prohibits us from actually doing anything with the virtual - # machine, so we raise an error. - raise VagrantPlugins::Parallels::Errors::VMInaccessible - end - - @app.call(env) - end - end - end - end -end diff --git a/lib/vagrant-parallels/action/check_created.rb b/lib/vagrant-parallels/action/check_created.rb deleted file mode 100644 index e3be106e..00000000 --- a/lib/vagrant-parallels/action/check_created.rb +++ /dev/null @@ -1,21 +0,0 @@ -module VagrantPlugins - module Parallels - module Action - # This middleware checks that the VM is created, and raises an exception - # if it is not, notifying the user that creation is required. - class CheckCreated - def initialize(app, env) - @app = app - end - - def call(env) - if env[:machine].state.id == :not_created - raise Vagrant::Errors::VMNotCreatedError - end - - @app.call(env) - end - end - end - end -end diff --git a/lib/vagrant-parallels/action/check_parallels.rb b/lib/vagrant-parallels/action/check_parallels.rb deleted file mode 100644 index 1b9f9931..00000000 --- a/lib/vagrant-parallels/action/check_parallels.rb +++ /dev/null @@ -1,22 +0,0 @@ -module VagrantPlugins - module Parallels - module Action - # Checks that Parallels is installed and ready to be used. - class CheckParallels - def initialize(app, env) - @app = app - end - - def call(env) - # This verifies that Parallels is installed and the driver is - # ready to function. If not, then an exception will be raised - # which will break us out of execution of the middleware sequence. - env[:machine].provider.driver.verify! - - # Carry on. - @app.call(env) - end - end - end - end -end \ No newline at end of file diff --git a/lib/vagrant-parallels/action/check_running.rb b/lib/vagrant-parallels/action/check_running.rb deleted file mode 100644 index 6f519cf6..00000000 --- a/lib/vagrant-parallels/action/check_running.rb +++ /dev/null @@ -1,21 +0,0 @@ -module VagrantPlugins - module Parallels - module Action - # This middleware checks that the VM is running, and raises an exception - # if it is not, notifying the user that the VM must be running. - class CheckRunning - def initialize(app, env) - @app = app - end - - def call(env) - if env[:machine].state.id != :running - raise Vagrant::Errors::VMNotRunningError - end - - @app.call(env) - end - end - end - end -end diff --git a/lib/vagrant-parallels/action/created.rb b/lib/vagrant-parallels/action/created.rb deleted file mode 100644 index 2bd8365e..00000000 --- a/lib/vagrant-parallels/action/created.rb +++ /dev/null @@ -1,20 +0,0 @@ -module VagrantPlugins - module Parallels - module Action - class Created - def initialize(app, env) - @app = app - end - - def call(env) - # Set the result to be true if the machine is created. - env[:result] = (env[:machine].state.id != :not_created) - - # Call the next if we have one (but we shouldn't, since this - # middleware is built to run with the Call-type middlewares) - @app.call(env) - end - end - end - end -end diff --git a/lib/vagrant-parallels/action/is_running.rb b/lib/vagrant-parallels/action/is_running.rb deleted file mode 100644 index 63b15fb1..00000000 --- a/lib/vagrant-parallels/action/is_running.rb +++ /dev/null @@ -1,20 +0,0 @@ -module VagrantPlugins - module Parallels - module Action - class IsRunning - def initialize(app, env) - @app = app - end - - def call(env) - # Set the result to be true if the machine is running. - env[:result] = env[:machine].state.id == :running - - # Call the next if we have one (but we shouldn't, since this - # middleware is built to run with the Call-type middlewares) - @app.call(env) - end - end - end - end -end diff --git a/lib/vagrant-parallels/action/is_suspended.rb b/lib/vagrant-parallels/action/is_suspended.rb deleted file mode 100644 index da0c0c66..00000000 --- a/lib/vagrant-parallels/action/is_suspended.rb +++ /dev/null @@ -1,21 +0,0 @@ -module VagrantPlugins - module Parallels - module Action - class IsSuspended - def initialize(app, env) - @app = app - end - - def call(env) - - # Set the result to be true if the machine is suspended. - env[:result] = env[:machine].state.id == :suspended - - # Call the next if we have one (but we shouldn't, since this - # middleware is built to run with the Call-type middlewares) - @app.call(env) - end - end - end - end -end diff --git a/lib/vagrant-parallels/action/message_already_running.rb b/lib/vagrant-parallels/action/message_already_running.rb deleted file mode 100644 index e4ea2c5d..00000000 --- a/lib/vagrant-parallels/action/message_already_running.rb +++ /dev/null @@ -1,16 +0,0 @@ -module VagrantPlugins - module Parallels - module Action - class MessageAlreadyRunning - def initialize(app, env) - @app = app - end - - def call(env) - env[:ui].info I18n.t("vagrant_parallels.commands.common.vm_already_running") - @app.call(env) - end - end - end - end -end diff --git a/lib/vagrant-parallels/action/message_not_created.rb b/lib/vagrant-parallels/action/message_not_created.rb deleted file mode 100644 index f1ee9c4f..00000000 --- a/lib/vagrant-parallels/action/message_not_created.rb +++ /dev/null @@ -1,16 +0,0 @@ -module VagrantPlugins - module Parallels - module Action - class MessageNotCreated - def initialize(app, env) - @app = app - end - - def call(env) - env[:ui].info I18n.t("vagrant.commands.common.vm_not_created") - @app.call(env) - end - end - end - end -end diff --git a/lib/vagrant-parallels/action/message_not_running.rb b/lib/vagrant-parallels/action/message_not_running.rb deleted file mode 100644 index 1050b6e9..00000000 --- a/lib/vagrant-parallels/action/message_not_running.rb +++ /dev/null @@ -1,16 +0,0 @@ -module VagrantPlugins - module Parallels - module Action - class MessageNotRunning - def initialize(app, env) - @app = app - end - - def call(env) - env[:ui].info I18n.t("vagrant.commands.common.vm_not_running") - @app.call(env) - end - end - end - end -end diff --git a/lib/vagrant-parallels/action/message_will_not_destroy.rb b/lib/vagrant-parallels/action/message_will_not_destroy.rb deleted file mode 100644 index 0a04529b..00000000 --- a/lib/vagrant-parallels/action/message_will_not_destroy.rb +++ /dev/null @@ -1,17 +0,0 @@ -module VagrantPlugins - module Parallels - module Action - class MessageWillNotDestroy - def initialize(app, env) - @app = app - end - - def call(env) - env[:ui].info I18n.t("vagrant.commands.destroy.will_not_destroy", - :name => env[:machine].name) - @app.call(env) - end - end - end - end -end diff --git a/lib/vagrant-parallels/errors.rb b/lib/vagrant-parallels/errors.rb index 83ad9218..1632346f 100644 --- a/lib/vagrant-parallels/errors.rb +++ b/lib/vagrant-parallels/errors.rb @@ -35,10 +35,6 @@ class ParallelsNoRoomForHighLevelNetwork < VagrantParallelsError error_key(:parallels_no_room_for_high_level_network) end - class VMInaccessible < VagrantParallelsError - error_key(:vm_inaccessible) - end - class VMNameExists < VagrantParallelsError error_key(:vm_name_exists) end diff --git a/locales/en.yml b/locales/en.yml index e816f2d3..b96c39d6 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -48,11 +48,6 @@ en: Vagrant uses the `prlctl` binary that ships with Parallels Desktop, and requires this to be available on the PATH. If Parallels Desktop is installed, please find the `prlctl` binary and add it to the PATH environmental variable. - vm_inaccessible: |- - Your VM has become "inaccessible." Unfortunately, this is a critical error - with Parallels Desktop that Vagrant can not cleanly recover from. - Please open VirtualBox and clear out your inaccessible virtual machines - or find a way to fix them. vm_name_exists: |- Parallels Desktop virtual machine with the name '%{name}' already exists. Please use another name or delete the machine with the existing From 0eea1909afbc6531f3346ad37aa3334aa7ea6e63 Mon Sep 17 00:00:00 2001 From: Mikhail Zholobov Date: Sun, 11 May 2014 16:22:34 +0400 Subject: [PATCH 02/14] guest_cap: Fixed typo in the cabability name --- lib/vagrant-parallels/plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-parallels/plugin.rb b/lib/vagrant-parallels/plugin.rb index 80bd9243..fdafe182 100644 --- a/lib/vagrant-parallels/plugin.rb +++ b/lib/vagrant-parallels/plugin.rb @@ -45,7 +45,7 @@ class Plugin < Vagrant.plugin("2") GuestLinuxCap::MountParallelsSharedFolder end - guest_capability(:linux, :unmount_virtualbox_shared_folder) do + guest_capability(:linux, :unmount_parallels_shared_folder) do require_relative "guest_cap/linux/mount_virtualbox_shared_folder" GuestLinuxCap::MountParallelsSharedFolder end From 06e8fc8cfe1761cd495e144605b9a13d29a6a78d Mon Sep 17 00:00:00 2001 From: Mikhail Zholobov Date: Sun, 11 May 2014 16:27:27 +0400 Subject: [PATCH 03/14] driver: removed 'verify!' method (not in use). --- lib/vagrant-parallels/driver/base.rb | 6 ------ lib/vagrant-parallels/driver/meta.rb | 1 - lib/vagrant-parallels/driver/pd_8.rb | 4 ---- 3 files changed, 11 deletions(-) diff --git a/lib/vagrant-parallels/driver/base.rb b/lib/vagrant-parallels/driver/base.rb index c4fee0b7..b6692e45 100644 --- a/lib/vagrant-parallels/driver/base.rb +++ b/lib/vagrant-parallels/driver/base.rb @@ -244,12 +244,6 @@ def suspend def unshare_folders(names) end - # Verifies that the driver is ready to accept work. - # - # This should raise a VagrantError if things are not ready. - def verify! - end - # Checks if a VM with the given UUID exists. # # @return [Boolean] diff --git a/lib/vagrant-parallels/driver/meta.rb b/lib/vagrant-parallels/driver/meta.rb index d0b95f98..d71c2a7e 100644 --- a/lib/vagrant-parallels/driver/meta.rb +++ b/lib/vagrant-parallels/driver/meta.rb @@ -116,7 +116,6 @@ def initialize(uuid=nil) :start, :suspend, :unregister, - :verify!, :vm_exists? protected diff --git a/lib/vagrant-parallels/driver/pd_8.rb b/lib/vagrant-parallels/driver/pd_8.rb index 71eb5f76..bf282b6d 100644 --- a/lib/vagrant-parallels/driver/pd_8.rb +++ b/lib/vagrant-parallels/driver/pd_8.rb @@ -456,10 +456,6 @@ def unshare_folders(names) end end - def verify! - execute('--version', retryable: true) - end - def vm_exists?(uuid) raw("list", uuid).exit_code == 0 end From 3b16110020c36f230c1a0d8b0b1cedaa933e2c20 Mon Sep 17 00:00:00 2001 From: Mikhail Zholobov Date: Mon, 12 May 2014 11:45:32 +0400 Subject: [PATCH 04/14] action: Added 'is_driver_version' middleware --- lib/vagrant-parallels/action.rb | 1 + .../action/is_driver_version.rb | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 lib/vagrant-parallels/action/is_driver_version.rb diff --git a/lib/vagrant-parallels/action.rb b/lib/vagrant-parallels/action.rb index 0ab75a58..da62cba6 100644 --- a/lib/vagrant-parallels/action.rb +++ b/lib/vagrant-parallels/action.rb @@ -285,6 +285,7 @@ def self.action_up autoload :Export, File.expand_path("../action/export", __FILE__) autoload :ForcedHalt, File.expand_path("../action/forced_halt", __FILE__) autoload :Import, File.expand_path("../action/import", __FILE__) + autoload :IsDriverVersion, File.expand_path("../action/is_driver_version", __FILE__) autoload :Network, File.expand_path("../action/network", __FILE__) autoload :Package, File.expand_path("../action/package", __FILE__) autoload :PackageConfigFiles, File.expand_path("../action/package_config_files", __FILE__) diff --git a/lib/vagrant-parallels/action/is_driver_version.rb b/lib/vagrant-parallels/action/is_driver_version.rb new file mode 100644 index 00000000..a13f13c9 --- /dev/null +++ b/lib/vagrant-parallels/action/is_driver_version.rb @@ -0,0 +1,28 @@ +module VagrantPlugins + module Parallels + module Action + # This middleware is meant to be used with Call and can check if + # a version of Parallels Desktop satisfies the given constraint. + class IsDriverVersion + # @param [String] requirement Can be a full requirement specification, + # like ">= 9.0.24229", or a list of them, like [">= 9","< 10.0.2"]. + def initialize(app, env, requirement, **opts) + @app = app + @logger = Log4r::Logger.new("vagrant::plugins::parallels::is_driver_version") + @requirement = Gem::Requirement.new(requirement) + @invert = !!opts[:invert] + end + + def call(env) + @logger.debug("Checking if 'prlctl' driver version satisfies '#{@requirement}'") + driver_version = Gem::Version.new(env[:machine].provider.driver.version) + @logger.debug("-- 'prlctl' driver version: #{driver_version}") + + env[:result] = @requirement.satisfied_by?(driver_version) + env[:result] = !env[:result] if @invert + @app.call(env) + end + end + end + end +end From 422d070928f58edfbfe96dcd39cd51832766f6b6 Mon Sep 17 00:00:00 2001 From: Mikhail Zholobov Date: Wed, 14 May 2014 00:51:08 +0400 Subject: [PATCH 05/14] guest_cap: Fixed typo in the cabability name --- lib/vagrant-parallels/plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-parallels/plugin.rb b/lib/vagrant-parallels/plugin.rb index fdafe182..19f58caf 100644 --- a/lib/vagrant-parallels/plugin.rb +++ b/lib/vagrant-parallels/plugin.rb @@ -46,7 +46,7 @@ class Plugin < Vagrant.plugin("2") end guest_capability(:linux, :unmount_parallels_shared_folder) do - require_relative "guest_cap/linux/mount_virtualbox_shared_folder" + require_relative "guest_cap/linux/mount_parallels_shared_folder" GuestLinuxCap::MountParallelsSharedFolder end From 27a0b78b2157427b1608e33f845070deb1357654 Mon Sep 17 00:00:00 2001 From: Mikhail Zholobov Date: Wed, 14 May 2014 15:39:25 +0400 Subject: [PATCH 06/14] driver: Refactoring. Modified 'execute' method. Added 'execute_prlctl' & 'execute_prlsrvctl' wrappers --- lib/vagrant-parallels/action/customize.rb | 3 +- lib/vagrant-parallels/driver/base.rb | 75 +++++++---------- lib/vagrant-parallels/driver/meta.rb | 4 +- lib/vagrant-parallels/driver/pd_8.rb | 98 +++++++++++++---------- lib/vagrant-parallels/driver/pd_9.rb | 14 ++-- 5 files changed, 92 insertions(+), 102 deletions(-) diff --git a/lib/vagrant-parallels/action/customize.rb b/lib/vagrant-parallels/action/customize.rb index 7283dd11..0cbac245 100644 --- a/lib/vagrant-parallels/action/customize.rb +++ b/lib/vagrant-parallels/action/customize.rb @@ -26,8 +26,7 @@ def call(env) end begin - env[:machine].provider.driver.execute_command( - processed_command + [retryable: true]) + env[:machine].provider.driver.execute_prlctl(*processed_command) rescue VagrantPlugins::Parallels::Errors::PrlCtlError => e raise Vagrant::Errors::VMCustomizationFailed, { :command => command, diff --git a/lib/vagrant-parallels/driver/base.rb b/lib/vagrant-parallels/driver/base.rb index b6692e45..167e5c67 100644 --- a/lib/vagrant-parallels/driver/base.rb +++ b/lib/vagrant-parallels/driver/base.rb @@ -3,7 +3,6 @@ require 'vagrant/util/busy' require 'vagrant/util/network_ip' require 'vagrant/util/platform' -require 'vagrant/util/retryable' require 'vagrant/util/subprocess' module VagrantPlugins @@ -24,17 +23,11 @@ def initialize # This flag is used to keep track of interrupted state (SIGINT) @interrupted = false - # Set the list of required CLI utils - @cli_paths = { - :prlctl => "prlctl", - :prlsrvctl => "prlsrvctl", - :prl_disk_tool => "prl_disk_tool", - :ifconfig => "ifconfig" - } + @prlctl_path = "prlctl" + @prlsrvctl_path = "prlsrvctl" - @cli_paths.each do |name, path| - @logger.info("CLI utility '#{name}' path: #{path}") - end + @logger.info("prlctl path: #{@prlctl_path}") + @logger.info("prlsrvctl path: #{@prlsrvctl_path}") end # Clears the shared folders that have been set on the virtual machine. @@ -93,7 +86,7 @@ def enable_adapters(adapters) # Raises a prlctl error if it fails. # # @param [Array] command Command to execute. - def execute_command(command) + def execute_prlctl(command) end # Exports the virtual machine to the given path. @@ -250,37 +243,28 @@ def unshare_folders(names) def vm_exists?(uuid) end - # Execute the given subcommand for PrlCtl and return the output. - def execute(*command, &block) - # Get the options hash if it exists - opts = {} - opts = command.pop if command.last.is_a?(Hash) - - tries = opts[:retryable] ? 3 : 0 - - # Variable to store our execution result - r = nil - - retryable(:on => VagrantPlugins::Parallels::Errors::PrlCtlError, :tries => tries, :sleep => 1) do - # If there is an error with PrlCtl, this gets set to true - errored = false - - # Execute the command - r = raw(*command, &block) - - # If the command was a failure, then raise an exception that is - # nicely handled by Vagrant. - if r.exit_code != 0 - if @interrupted - @logger.info("Exit code != 0, but interrupted. Ignoring.") - else - errored = true - end - end + # Wraps 'execute' and returns the output of given 'prlctl' subcommand. + def execute_prlctl(*command, &block) + execute(@prlctl_path, *command, &block) + end - # If there was an error running prlctl, show the error and the - # output. - if errored + #Wraps 'execute' and returns the output of given 'prlsrvctl' subcommand. + def execute_prlsrvctl(*command, &block) + execute(@prlsrvctl_path, *command, &block) + end + + # Execute the given command and return the output. + def execute(*command, &block) + r = raw(*command, &block) + + # If the command was a failure, then raise an exception that is + # nicely handled by Vagrant. + if r.exit_code != 0 + if @interrupted + @logger.info("Exit code != 0, but interrupted. Ignoring.") + else + # If there was an error running prlctl, show the error and the + # output. raise VagrantPlugins::Parallels::Errors::PrlCtlError, :command => command.inspect, :stderr => r.stderr @@ -302,13 +286,8 @@ def raw(*command, &block) # Append in the options for subprocess command << { :notify => [:stdout, :stderr] } - # Get the utility from the first argument: - # 'prlctl' by default - util = @cli_paths.has_key?(command.first) ? command.delete_at(0) : :prlctl - cli = @cli_paths[util] - Vagrant::Util::Busy.busy(int_callback) do - Vagrant::Util::Subprocess.execute(cli, *command, &block) + Vagrant::Util::Subprocess.execute(*command, &block) end end end diff --git a/lib/vagrant-parallels/driver/meta.rb b/lib/vagrant-parallels/driver/meta.rb index d71c2a7e..442a4741 100644 --- a/lib/vagrant-parallels/driver/meta.rb +++ b/lib/vagrant-parallels/driver/meta.rb @@ -84,7 +84,7 @@ def initialize(uuid=nil) :delete_disabled_adapters, :delete_unused_host_only_networks, :enable_adapters, - :execute_command, + :execute_prlctl, :export, :halt, :import, @@ -132,7 +132,7 @@ def read_version # # But we need exactly the first 3 numbers: "x.x.x" - if execute('--version', retryable: true) =~ /prlctl version (\d+\.\d+.\d+)/ + if execute('prlctl', '--version') =~ /prlctl version (\d+\.\d+.\d+)/ return $1 else return nil diff --git a/lib/vagrant-parallels/driver/pd_8.rb b/lib/vagrant-parallels/driver/pd_8.rb index bf282b6d..ce5360ad 100644 --- a/lib/vagrant-parallels/driver/pd_8.rb +++ b/lib/vagrant-parallels/driver/pd_8.rb @@ -18,9 +18,11 @@ def initialize(uuid) def compact(uuid) - used_drives = read_settings.fetch('Hardware', {}).select { |name, _| name.start_with? 'hdd' } + used_drives = read_settings.fetch('Hardware', {}).select do |name, _| + name.start_with? 'hdd' + end used_drives.each_value do |drive_params| - execute(:prl_disk_tool, 'compact', '--hdd', drive_params["image"]) do |type, data| + execute('prl_disk_tool', 'compact', '--hdd', drive_params['image']) do |type, data| lines = data.split("\r") # The progress of the compact will be in the last line. Do a greedy # regular expression to find what we're looking for. @@ -34,13 +36,13 @@ def compact(uuid) def clear_shared_folders share_ids = read_shared_folders.keys share_ids.each do |id| - execute("set", @uuid, "--shf-host-del", id) + execute_prlctl('set', @uuid, '--shf-host-del', id) end end def create_host_only_network(options) # Create the interface - execute(:prlsrvctl, "net", "add", options[:network_id], "--type", "host-only") + execute_prlsrvctl('net', 'add', options[:network_id], '--type', 'host-only') # Configure it args = ["--ip", "#{options[:adapter_ip]}/#{options[:netmask]}"] @@ -50,10 +52,10 @@ def create_host_only_network(options) "--ip-scope-end", options[:dhcp][:upper]]) end - execute(:prlsrvctl, "net", "set", options[:network_id], *args) + execute_prlsrvctl('net', 'set', options[:network_id], *args) # Determine interface to which it has been bound - net_info = json { execute(:prlsrvctl, 'net', 'info', options[:network_id], '--json', retryable: true) } + net_info = json { execute_prlsrvctl('net', 'info', options[:network_id], '--json') } iface_name = net_info['Bound To'] # Return the details @@ -66,13 +68,13 @@ def create_host_only_network(options) end def delete - execute('delete', @uuid) + execute_prlctl('delete', @uuid) end def delete_disabled_adapters read_settings.fetch('Hardware', {}).each do |adapter, params| - if adapter.start_with?('net') and !params.fetch("enabled", true) - execute('set', @uuid, '--device-del', adapter) + if adapter.start_with?('net') and !params.fetch('enabled', true) + execute_prlctl('set', @uuid, '--device-del', adapter) end end end @@ -97,19 +99,21 @@ def delete_unused_host_only_networks networks.each do |net| # Delete the actual host only network interface. - execute(:prlsrvctl, "net", "del", net["Network ID"]) + execute_prlsrvctl('net', 'del', net['Network ID']) end end def enable_adapters(adapters) # Get adapters which have already configured for this VM # Such adapters will be just overridden - existing_adapters = read_settings.fetch('Hardware', {}).keys.select { |name| name.start_with? 'net' } + existing_adapters = read_settings.fetch('Hardware', {}).keys.select do |name| + name.start_with? 'net' + end # Disable all previously existing adapters (except shared 'vnet0') existing_adapters.each do |adapter| if adapter != 'vnet0' - execute('set', @uuid, '--device-set', adapter, '--disable') + execute_prlctl('set', @uuid, '--device-set', adapter, '--disable') end end @@ -141,16 +145,15 @@ def enable_adapters(adapters) args.concat(["--adapter-type", adapter[:nic_type].to_s]) end - execute("set", @uuid, *args) + execute_prlctl("set", @uuid, *args) end end - def execute_command(command) - execute(*command) - end - def export(path, tpl_name) - execute("clone", @uuid, "--name", tpl_name, "--template", "--dst", path.to_s) do |type, data| + execute_prlctl('clone', @uuid, + '--name', tpl_name, + '--template', + '--dst', path.to_s) do |type, data| lines = data.split("\r") # The progress of the export will be in the last line. Do a greedy # regular expression to find what we're looking for. @@ -162,7 +165,7 @@ def export(path, tpl_name) end def halt(force=false) - args = ['stop', @uuid] + args = ['prlctl', 'stop', @uuid] args << '--kill' if force execute(*args) end @@ -171,7 +174,7 @@ def import(template_uuid) template_name = read_vms.key(template_uuid) vm_name = "#{template_name}_#{(Time.now.to_f * 1000.0).to_i}_#{rand(100000)}" - execute("clone", template_uuid, '--name', vm_name) do |type, data| + execute_prlctl('clone', template_uuid, '--name', vm_name) do |type, data| lines = data.split("\r") # The progress of the import will be in the last line. Do a greedy # regular expression to find what we're looking for. @@ -192,7 +195,7 @@ def read_bridged_interfaces bridged_ifaces = [] net_list.keys.each do |iface| info = {} - ifconfig = execute(:ifconfig, iface) + ifconfig = execute('ifconfig', iface) # Assign default values info[:name] = iface info[:ip] = "0.0.0.0" @@ -240,7 +243,7 @@ def read_guest_tools_version end def read_host_info - json { execute('server', 'info', '--json', retryable: true) } + json { execute_prlctl('server', 'info', '--json') } end def read_host_only_interfaces @@ -250,7 +253,7 @@ def read_host_only_interfaces hostonly_ifaces = [] net_list.each do |iface| info = {} - net_info = json { execute(:prlsrvctl, 'net', 'info', iface['Network ID'], '--json') } + net_info = json { execute_prlsrvctl('net', 'info', iface['Network ID'], '--json') } # Really we need to work with bounded virtual interface info[:name] = net_info['Bound To'] info[:ip] = net_info['Parallels adapter']['IP address'] @@ -261,7 +264,8 @@ def read_host_only_interfaces # There may be a fake DHCPv4 parameters # We can trust them only if adapter IP and DHCP IP are in the same subnet dhcp_ip = net_info['DHCPv4 server']['Server address'] - if network_address(info[:ip], info[:netmask]) == network_address(dhcp_ip, info[:netmask]) + if network_address(info[:ip], info[:netmask]) == + network_address(dhcp_ip, info[:netmask]) info[:dhcp] = { :ip => dhcp_ip, :lower => net_info['DHCPv4 server']['IP scope start address'], @@ -319,7 +323,7 @@ def read_network_interfaces end def read_settings - vm = json { execute('list', @uuid, '--info', '--json', retryable: true).gsub(/^INFO/, '') } + vm = json { execute_prlctl('list', @uuid, '--info', '--json').gsub(/^INFO/, '') } vm.last end @@ -328,7 +332,9 @@ def read_shared_interface shared_net = read_virtual_networks.detect { |net| net['Type'] == 'shared' } return nil if !shared_net - net_info = json { execute(:prlsrvctl, 'net', 'info', shared_net['Network ID'], '--json') } + net_info = json do + execute_prlsrvctl('net', 'info', shared_net['Network ID'], '--json') + end info = { name: net_info['Bound To'], ip: net_info['Parallels adapter']['IP address'], @@ -358,22 +364,22 @@ def read_shared_folders end def read_state - vm = json { execute('list', @uuid, '--json', retryable: true).gsub(/^INFO/, '') } + vm = json { execute_prlctl('list', @uuid, '--json').gsub(/^INFO/, '') } return nil if !vm.last vm.last.fetch('status').to_sym end def read_virtual_networks - json { execute(:prlsrvctl, 'net', 'list', '--json', retryable: true) } + json { execute_prlsrvctl('net', 'list', '--json') } end def read_vms results = {} vms_arr = json([]) do - execute('list', '--all', '--json', retryable: true).gsub(/^INFO/, '') + execute_prlctl('list', '--all', '--json').gsub(/^INFO/, '') end templates_arr = json([]) do - execute('list', '--all', '--json', '--template', retryable: true).gsub(/^INFO/, '') + execute_prlctl('list', '--all', '--json', '--template').gsub(/^INFO/, '') end vms = vms_arr | templates_arr vms.each do |item| @@ -383,13 +389,14 @@ def read_vms results end - # Parse the JSON from *all* VMs and templates. Then return an array of objects (without duplicates) + # Parse the JSON from *all* VMs and templates. + # Then return an array of objects (without duplicates) def read_vms_info vms_arr = json([]) do - execute('list', '--all','--info', '--json', retryable: true).gsub(/^INFO/, '') + execute_prlctl('list', '--all','--info', '--json').gsub(/^INFO/, '') end templates_arr = json([]) do - execute('list', '--all','--info', '--json', '--template', retryable: true).gsub(/^INFO/, '') + execute_prlctl('list', '--all','--info', '--json', '--template').gsub(/^INFO/, '') end vms_arr | templates_arr end @@ -406,7 +413,7 @@ def read_vms_paths end def register(pvm_file, regen_src_uuid=false) - args = ['register', pvm_file] + args = ['prlctl', 'register', pvm_file] args << '--regenerate-src-uuid' if regen_src_uuid execute(*args) end @@ -416,21 +423,26 @@ def registered?(uuid) end def resume - execute('resume', @uuid) + execute_prlctl('resume', @uuid) end def set_mac_address(mac) - execute('set', @uuid, '--device-set', 'net0', '--type', 'shared', '--mac', mac) + execute_prlctl('set', @uuid, + '--device-set', 'net0', + '--type', 'shared', + '--mac', mac) end def set_name(name) - execute('set', @uuid, '--name', name, :retryable => true) + execute_prlctl('set', @uuid, '--name', name) end def share_folders(folders) folders.each do |folder| # Add the shared folder - execute('set', @uuid, '--shf-host-add', folder[:name], '--path', folder[:hostpath]) + execute_prlctl('set', @uuid, + '--shf-host-add', folder[:name], + '--path', folder[:hostpath]) end end @@ -439,25 +451,25 @@ def ssh_port(expected_port) end def start - execute('start', @uuid) + execute_prlctl('start', @uuid) end def suspend - execute('suspend', @uuid) + execute_prlctl('suspend', @uuid) end def unregister(uuid) - execute("unregister", uuid) + execute_prlctl('unregister', uuid) end def unshare_folders(names) names.each do |name| - execute("set", @uuid, "--shf-host-del", name) + execute_prlctl('set', @uuid, '--shf-host-del', name) end end def vm_exists?(uuid) - raw("list", uuid).exit_code == 0 + raw('prlctl', 'list', uuid).exit_code == 0 end end end diff --git a/lib/vagrant-parallels/driver/pd_9.rb b/lib/vagrant-parallels/driver/pd_9.rb index 8bb78979..fbea8255 100644 --- a/lib/vagrant-parallels/driver/pd_9.rb +++ b/lib/vagrant-parallels/driver/pd_9.rb @@ -16,12 +16,12 @@ def initialize(uuid) end def read_settings - vm = json { execute('list', @uuid, '--info', '--json', retryable: true) } + vm = json { execute_prlctl('list', @uuid, '--info', '--json') } vm.last end def read_state - vm = json { execute('list', @uuid, '--json', retryable: true) } + vm = json { execute_prlctl('list', @uuid, '--json') } return nil if !vm.last vm.last.fetch('status').to_sym end @@ -29,10 +29,10 @@ def read_state def read_vms results = {} vms_arr = json([]) do - execute('list', '--all', '--json', retryable: true) + execute_prlctl('list', '--all', '--json') end templates_arr = json([]) do - execute('list', '--all', '--json', '--template', retryable: true) + execute_prlctl('list', '--all', '--json', '--template') end vms = vms_arr | templates_arr vms.each do |item| @@ -45,17 +45,17 @@ def read_vms # Parse the JSON from *all* VMs and templates. Then return an array of objects (without duplicates) def read_vms_info vms_arr = json([]) do - execute('list', '--all','--info', '--json', retryable: true) + execute_prlctl('list', '--all','--info', '--json') end templates_arr = json([]) do - execute('list', '--all','--info', '--json', '--template', retryable: true) + execute_prlctl('list', '--all','--info', '--json', '--template') end vms_arr | templates_arr end def set_power_consumption_mode(optimized) state = optimized ? 'on' : 'off' - execute('set', @uuid, '--longer-battery-life', state) + execute_prlctl('set', @uuid, '--longer-battery-life', state) end end end From e0841b52029bfb9a9d3ed9ab1132e5d3bb3086ee Mon Sep 17 00:00:00 2001 From: Mikhail Zholobov Date: Wed, 14 May 2014 16:15:59 +0400 Subject: [PATCH 07/14] errors: Renamed 'PrlCtlError' -> 'ExecutionError' --- lib/vagrant-parallels/action/customize.rb | 2 +- lib/vagrant-parallels/driver/base.rb | 4 ++-- lib/vagrant-parallels/errors.rb | 4 ++-- locales/en.yml | 5 ++--- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/vagrant-parallels/action/customize.rb b/lib/vagrant-parallels/action/customize.rb index 0cbac245..9a5e3534 100644 --- a/lib/vagrant-parallels/action/customize.rb +++ b/lib/vagrant-parallels/action/customize.rb @@ -27,7 +27,7 @@ def call(env) begin env[:machine].provider.driver.execute_prlctl(*processed_command) - rescue VagrantPlugins::Parallels::Errors::PrlCtlError => e + rescue VagrantPlugins::Parallels::Errors::ExecutionError => e raise Vagrant::Errors::VMCustomizationFailed, { :command => command, :error => e.inspect diff --git a/lib/vagrant-parallels/driver/base.rb b/lib/vagrant-parallels/driver/base.rb index 167e5c67..4848ddd4 100644 --- a/lib/vagrant-parallels/driver/base.rb +++ b/lib/vagrant-parallels/driver/base.rb @@ -263,9 +263,9 @@ def execute(*command, &block) if @interrupted @logger.info("Exit code != 0, but interrupted. Ignoring.") else - # If there was an error running prlctl, show the error and the + # If there was an error running command, show the error and the # output. - raise VagrantPlugins::Parallels::Errors::PrlCtlError, + raise VagrantPlugins::Parallels::Errors::ExecutionError, :command => command.inspect, :stderr => r.stderr end diff --git a/lib/vagrant-parallels/errors.rb b/lib/vagrant-parallels/errors.rb index 1632346f..0f70c3df 100644 --- a/lib/vagrant-parallels/errors.rb +++ b/lib/vagrant-parallels/errors.rb @@ -15,8 +15,8 @@ class MacOSXRequired < VagrantParallelsError error_key(:mac_os_x_required) end - class PrlCtlError < VagrantParallelsError - error_key(:prlctl_error) + class ExecutionError < VagrantParallelsError + error_key(:execution_error) end class ParallelsInstallIncomplete < VagrantParallelsError diff --git a/locales/en.yml b/locales/en.yml index b96c39d6..1336d6a1 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -20,9 +20,8 @@ en: Parallels DHCP leases file: %{leases_file} mac_os_x_required: |- Parallels provider only works on OS X (or Mac OS X). - prlctl_error: |- - There was an error while executing `prlctl`, a CLI used by Vagrant - for controlling Parallels Desktop. The command and stderr is shown below. + execution_error: |- + There was an error while command execution. The command and stderr is shown below. Command: %{command} From 590d4a4a8ec4e0f298d6b9aa6201b76c318b18a1 Mon Sep 17 00:00:00 2001 From: Mikhail Zholobov Date: Wed, 14 May 2014 16:16:50 +0400 Subject: [PATCH 08/14] errors: Fixed text for 'mac_os_x_required' error --- locales/en.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/locales/en.yml b/locales/en.yml index 1336d6a1..17d99d3e 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -18,14 +18,14 @@ en: readable for the user that is running Vagrant. Parallels DHCP leases file: %{leases_file} - mac_os_x_required: |- - Parallels provider only works on OS X (or Mac OS X). execution_error: |- There was an error while command execution. The command and stderr is shown below. Command: %{command} Stderr: %{stderr} + mac_os_x_required: |- + Parallels provider works only on OS X (Mac OS X) systems. parallels_install_incomplete: |- Parallels Desktop is complaining that the installation is incomplete. Try to reinstall Parallels Desktop or contact Parallels support. From e0d1f57970f0a157bb33b09730f02a874a78f36d Mon Sep 17 00:00:00 2001 From: Mikhail Zholobov Date: Wed, 14 May 2014 01:01:50 +0400 Subject: [PATCH 09/14] driver: Added 'read_guest_tools_iso_path' method --- lib/vagrant-parallels/driver/base.rb | 7 +++++ lib/vagrant-parallels/driver/meta.rb | 1 + lib/vagrant-parallels/driver/pd_8.rb | 21 +++++++++++++++ lib/vagrant-parallels/errors.rb | 4 +++ locales/en.yml | 6 +++++ .../unit/support/shared/pd_driver_examples.rb | 26 +++++++++++++++++++ 6 files changed, 65 insertions(+) diff --git a/lib/vagrant-parallels/driver/base.rb b/lib/vagrant-parallels/driver/base.rb index 4848ddd4..99ede66e 100644 --- a/lib/vagrant-parallels/driver/base.rb +++ b/lib/vagrant-parallels/driver/base.rb @@ -124,6 +124,13 @@ def max_network_adapters def read_bridged_interfaces end + # Returns path to the Parallels Tools ISO file. + # + # @param [String] guest_os Guest os type: "linux", "darwin" or "windows" + # @return [String] Path to the ISO. + def read_guest_tools_iso_path(guest_os) + end + # Returns the guest tools version that is installed on this VM. # # @return [String] diff --git a/lib/vagrant-parallels/driver/meta.rb b/lib/vagrant-parallels/driver/meta.rb index 442a4741..3335f3d6 100644 --- a/lib/vagrant-parallels/driver/meta.rb +++ b/lib/vagrant-parallels/driver/meta.rb @@ -90,6 +90,7 @@ def initialize(uuid=nil) :import, :read_bridged_interfaces, :read_guest_tools_version, + :read_guest_tools_iso_path, :read_guest_ip, :read_guest_property, :read_host_only_interfaces, diff --git a/lib/vagrant-parallels/driver/pd_8.rb b/lib/vagrant-parallels/driver/pd_8.rb index ce5360ad..9f9ef872 100644 --- a/lib/vagrant-parallels/driver/pd_8.rb +++ b/lib/vagrant-parallels/driver/pd_8.rb @@ -237,6 +237,27 @@ def read_guest_ip nil end + def read_guest_tools_iso_path(guest_os) + guest_os = guest_os.to_sym + iso_name ={ + :linux => "prl-tools-lin.iso", + :darwin => "prl-tools-mac.iso", + :windows => "prl-tools-win.iso" + } + return nil if !iso_name[guest_os] + + bundle_id = 'com.parallels.desktop.console' + bundle_path = execute('mdfind', "kMDItemCFBundleIdentifier == #{bundle_id}") + iso_path = File.expand_path("./Contents/Resources/Tools/#{iso_name[guest_os]}", + bundle_path.split("\n")[0]) + + if !File.exist?(iso_path) + raise Errors::ParallelsToolsIsoNotFound, :iso_path => iso_path + end + + iso_path + end + def read_guest_tools_version tools_version = read_settings.fetch('GuestTools', {}).fetch('version', '') tools_version[/(^\d+\.\d+.\d+)/] diff --git a/lib/vagrant-parallels/errors.rb b/lib/vagrant-parallels/errors.rb index 0f70c3df..bafbc5d4 100644 --- a/lib/vagrant-parallels/errors.rb +++ b/lib/vagrant-parallels/errors.rb @@ -35,6 +35,10 @@ class ParallelsNoRoomForHighLevelNetwork < VagrantParallelsError error_key(:parallels_no_room_for_high_level_network) end + class ParallelsToolsIsoNotFound < VagrantParallelsError + error_key(:parallels_tools_iso_not_found) + end + class VMNameExists < VagrantParallelsError error_key(:vm_name_exists) end diff --git a/locales/en.yml b/locales/en.yml index 17d99d3e..698de252 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -47,6 +47,12 @@ en: Vagrant uses the `prlctl` binary that ships with Parallels Desktop, and requires this to be available on the PATH. If Parallels Desktop is installed, please find the `prlctl` binary and add it to the PATH environmental variable. + parallels_tools_iso_not_found: |- + Parallels Tools ISO file does not exists. The Parallels provider uses it + to install or update Parallels Tools in the guest machine. Try to + reinstall Parallels Desktop. + + Expected ISO path: "%{iso_path}" vm_name_exists: |- Parallels Desktop virtual machine with the name '%{name}' already exists. Please use another name or delete the machine with the existing diff --git a/test/unit/support/shared/pd_driver_examples.rb b/test/unit/support/shared/pd_driver_examples.rb index e82ef2be..724d2e1b 100644 --- a/test/unit/support/shared/pd_driver_examples.rb +++ b/test/unit/support/shared/pd_driver_examples.rb @@ -181,6 +181,32 @@ end end + describe "read_guest_tools_iso_path" do + before do + subprocess.stub(:execute). + with("mdfind", /^kMDItemCFBundleIdentifier ==/, an_instance_of(Hash)). + and_return(subprocess_result(stdout: "/Applications/Parallels Desktop.app")) + end + + it "returns a valid path to the ISO" do + File.stub(:exist?).and_return(true) + iso_path = subject.read_guest_tools_iso_path("linux") + iso_path.should be_kind_of(String) + iso_path.should match(/prl-tools-lin\.iso$/) + end + + it "raises an exception if ISO file does not exists" do + File.stub(:exist?).and_return(false) + expect { subject.read_guest_tools_iso_path("windows") }. + to raise_error(VagrantPlugins::Parallels::Errors::ParallelsToolsIsoNotFound) + end + + it "returns nil if guest OS is unsupported or invalid" do + subject.read_guest_tools_iso_path("").should be_nil + subject.read_guest_tools_iso_path("bolgenos").should be_nil + end + end + describe "read_mac_addresses" do it "returns MAC addresses of all network interface cards" do subject.read_mac_addresses.should be_kind_of(Hash) From ea96bc5dfb24ebe956c413abd61b625853e15d10 Mon Sep 17 00:00:00 2001 From: Mikhail Zholobov Date: Wed, 14 May 2014 01:11:26 +0400 Subject: [PATCH 10/14] action: 'CheckGuestTools' replaced with 'HandleGuestTools' 'HandleGuestTools' supports checking and installing/updating guest tools as well --- lib/vagrant-parallels/action.rb | 4 +- .../action/check_guest_tools.rb | 37 -------------- .../action/handle_guest_tools.rb | 51 +++++++++++++++++++ lib/vagrant-parallels/config.rb | 6 +++ lib/vagrant-parallels/driver/base.rb | 17 ++++--- lib/vagrant-parallels/driver/meta.rb | 3 +- lib/vagrant-parallels/driver/pd_8.rb | 7 +-- locales/en.yml | 39 +++++++------- test/unit/driver/pd_8_test.rb | 3 ++ test/unit/driver/pd_9_test.rb | 3 ++ .../unit/support/shared/pd_driver_examples.rb | 16 +++--- 11 files changed, 108 insertions(+), 78 deletions(-) delete mode 100644 lib/vagrant-parallels/action/check_guest_tools.rb create mode 100644 lib/vagrant-parallels/action/handle_guest_tools.rb diff --git a/lib/vagrant-parallels/action.rb b/lib/vagrant-parallels/action.rb index da62cba6..c0448173 100644 --- a/lib/vagrant-parallels/action.rb +++ b/lib/vagrant-parallels/action.rb @@ -26,7 +26,7 @@ def self.action_boot b.use Boot b.use Customize, "post-boot" b.use WaitForCommunicator, [:starting, :running] - b.use CheckGuestTools + b.use HandleGuestTools end end @@ -277,7 +277,7 @@ def self.action_up end autoload :Boot, File.expand_path("../action/boot", __FILE__) - autoload :CheckGuestTools, File.expand_path("../action/check_guest_tools", __FILE__) + autoload :HandleGuestTools, File.expand_path("../action/handle_guest_tools", __FILE__) autoload :ClearNetworkInterfaces, File.expand_path("../action/clear_network_interfaces", __FILE__) autoload :Customize, File.expand_path("../action/customize", __FILE__) autoload :Destroy, File.expand_path("../action/destroy", __FILE__) diff --git a/lib/vagrant-parallels/action/check_guest_tools.rb b/lib/vagrant-parallels/action/check_guest_tools.rb deleted file mode 100644 index 540d9f9c..00000000 --- a/lib/vagrant-parallels/action/check_guest_tools.rb +++ /dev/null @@ -1,37 +0,0 @@ -module VagrantPlugins - module Parallels - module Action - class CheckGuestTools - def initialize(app, env) - @app = app - @logger = Log4r::Logger.new("vagrant::plugins::parallels::check_guest_tools") - end - - def call(env) - if !env[:machine].provider_config.check_guest_tools - @logger.info("Not checking guest tools because configuration") - return @app.call(env) - end - - env[:ui].output(I18n.t("vagrant_parallels.parallels.checking_guest_tools")) - - tools_version = env[:machine].provider.driver.read_guest_tools_version - if !tools_version - env[:ui].warn I18n.t("vagrant_parallels.actions.vm.check_guest_tools.not_detected") - else - pd_version = env[:machine].provider.driver.version - if Gem::Version.new(pd_version) != Gem::Version.new(tools_version) - env[:ui].warn(I18n.t("vagrant_parallels.actions.vm.check_guest_tools.version_mismatch", - :tools_version => tools_version, - :parallels_version => pd_version)) - end - end - - # Continue - @app.call(env) - end - - end - end - end -end diff --git a/lib/vagrant-parallels/action/handle_guest_tools.rb b/lib/vagrant-parallels/action/handle_guest_tools.rb new file mode 100644 index 00000000..d118b74c --- /dev/null +++ b/lib/vagrant-parallels/action/handle_guest_tools.rb @@ -0,0 +1,51 @@ +module VagrantPlugins + module Parallels + module Action + class HandleGuestTools + def initialize(app, env) + @app = app + @logger = Log4r::Logger.new("vagrant::plugins::parallels::handle_guest_tools") + end + + def call(env) + @machine = env[:machine] + + if !@machine.provider_config.check_guest_tools + @logger.info("Not checking Parallels Tools because of configuration") + return @app.call(env) + end + + env[:ui].output(I18n.t("vagrant_parallels.actions.vm.handle_guest_tools.checking")) + + tools_state = @machine.provider.driver.read_guest_tools_state + + if tools_state == :installed + @logger.info("The proper version of Parallels Tools is already installed") + return @app.call(env) + elsif tools_state == :outdated + env[:ui].warn(I18n.t("vagrant_parallels.actions.vm.handle_guest_tools.outdated")) + else + env[:ui].warn(I18n.t("vagrant_parallels.actions.vm.handle_guest_tools.not_detected")) + end + + if !@machine.provider_config.update_guest_tools + @logger.info("Not updating Parallels Tools because of configuration") + return @app.call(env) + end + + # Update/Install Parallels Tools + if @machine.guest.capability?(:install_parallels_tools) + env[:ui].output(I18n.t("vagrant_parallels.actions.vm.handle_guest_tools.installing")) + @machine.guest.capability(:install_parallels_tools) + else + env[:ui].warn(I18n.t("vagrant_parallels.actions.vm.handle_guest_tools.cant_install")) + end + + # Continue + @app.call(env) + end + + end + end + end +end diff --git a/lib/vagrant-parallels/config.rb b/lib/vagrant-parallels/config.rb index 0560b276..2ff37f90 100644 --- a/lib/vagrant-parallels/config.rb +++ b/lib/vagrant-parallels/config.rb @@ -8,6 +8,7 @@ class Config < Vagrant.plugin("2", :config) attr_accessor :optimize_power_consumption attr_accessor :name attr_reader :network_adapters + attr_accessor :update_guest_tools # Compatibility with virtualbox provider's syntax @@ -21,6 +22,7 @@ def initialize @network_adapters = {} @name = UNSET_VALUE @optimize_power_consumption = UNSET_VALUE + @update_guest_tools = UNSET_VALUE network_adapter(0, :shared) end @@ -70,6 +72,10 @@ def finalize! end @name = nil if @name == UNSET_VALUE + + if @update_guest_tools == UNSET_VALUE + @update_guest_tools = false + end end def validate(machine) diff --git a/lib/vagrant-parallels/driver/base.rb b/lib/vagrant-parallels/driver/base.rb index 99ede66e..be159d09 100644 --- a/lib/vagrant-parallels/driver/base.rb +++ b/lib/vagrant-parallels/driver/base.rb @@ -124,6 +124,17 @@ def max_network_adapters def read_bridged_interfaces end + # Returns the state of guest tools that is installed on this VM. + # Can be any of: + # * "installed" + # * "not_installed" + # * "possibly_installed" + # * "outdated" + # + # @return [String] + def read_guest_tools_state + end + # Returns path to the Parallels Tools ISO file. # # @param [String] guest_os Guest os type: "linux", "darwin" or "windows" @@ -131,12 +142,6 @@ def read_bridged_interfaces def read_guest_tools_iso_path(guest_os) end - # Returns the guest tools version that is installed on this VM. - # - # @return [String] - def read_guest_tools_version - end - # Returns a list of available host only interfaces. # # @return [Hash] diff --git a/lib/vagrant-parallels/driver/meta.rb b/lib/vagrant-parallels/driver/meta.rb index 3335f3d6..239375f3 100644 --- a/lib/vagrant-parallels/driver/meta.rb +++ b/lib/vagrant-parallels/driver/meta.rb @@ -89,10 +89,9 @@ def initialize(uuid=nil) :halt, :import, :read_bridged_interfaces, - :read_guest_tools_version, + :read_guest_tools_state, :read_guest_tools_iso_path, :read_guest_ip, - :read_guest_property, :read_host_only_interfaces, :read_mac_address, :read_mac_addresses, diff --git a/lib/vagrant-parallels/driver/pd_8.rb b/lib/vagrant-parallels/driver/pd_8.rb index 9f9ef872..601d78ce 100644 --- a/lib/vagrant-parallels/driver/pd_8.rb +++ b/lib/vagrant-parallels/driver/pd_8.rb @@ -258,9 +258,10 @@ def read_guest_tools_iso_path(guest_os) iso_path end - def read_guest_tools_version - tools_version = read_settings.fetch('GuestTools', {}).fetch('version', '') - tools_version[/(^\d+\.\d+.\d+)/] + def read_guest_tools_state + state = read_settings.fetch('GuestTools', {}).fetch('state', nil) + state = "not_installed" if !state + state.to_sym end def read_host_info diff --git a/locales/en.yml b/locales/en.yml index 698de252..4a5e84ef 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -1,8 +1,6 @@ en: vagrant_parallels: parallels: - checking_guest_tools: |- - Checking for Parallels Tools installed on the VM... power_consumption: set_mode: |- Setting power consumption mode: "%{mode}" @@ -101,23 +99,26 @@ en: #------------------------------------------------------------------------------- actions: vm: - check_guest_tools: + handle_guest_tools: + cant_install: |- + Vagrant doesn't support installing Parallels Tools for the guest OS + running in the machine. Vagrant attempt to continue, assuming that + Parallels Tools will be installed later. + checking: |- + Checking for Parallels Tools installed on the VM... + installing: |- + Installing the proper version of Parallels Tools. This may take a few minutes... not_detected: |- - No Parallels Tools were detected on the base box for this VM! Parallels - Tools are required for forwarded ports, shared folders, host only - networking, and more. If SSH fails on this machine, please install - the Parallels Tools and repackage the box to continue. - - This is not an error message; everything may continue to work properly, - in which case you may ignore this message. - version_mismatch: |- - The Parallels Tools on this VM do not match the installed version of - Parallels Desktop! In most cases this is fine, but in rare cases it can - cause things such as shared folders to not work properly. If you see - shared folder errors, please update the Parallels Tools within the - virtual machine and reload your VM. - - Parallels Tools Version: %{tools_version} - Parallels Desktop Version: %{parallels_version} + Parallels Tools were not detected on this VM! They are required + for forwarded ports, shared folders, host only networking and more. + If SSH fails or shared folders are not working on this machine, + please install Parallels Tools within the virtual machine and + reload your VM. + outdated: |- + Parallels Tools installed on this VM are outdated! In most cases + this is fine but in rare cases it can cause things such as shared + folders to not work properly. If you see shared folder errors, + please update Parallels Tools within the virtual machine and + reload your VM. export: compacting: Compacting exported HDDs... diff --git a/test/unit/driver/pd_8_test.rb b/test/unit/driver/pd_8_test.rb index a30cdec5..d9ef7d5c 100644 --- a/test/unit/driver/pd_8_test.rb +++ b/test/unit/driver/pd_8_test.rb @@ -9,6 +9,7 @@ let(:tpl_uuid) {'1234-some-template-uuid-5678'} let(:tpl_name) {'Some_Template_Name'} + let(:tools_state) {'installed'} let(:tools_version) {'8.0.18615.123456'} let(:hostonly_iface) {'vnic10'} @@ -75,6 +76,7 @@ "State": "stopped", "Home": "/path/to/#{vm_name}.pvm/", "GuestTools": { + "state": "#{tools_state}", "version": "#{tools_version}" }, "Hardware": { @@ -135,6 +137,7 @@ "State": "stopped", "Home": "/path/to/#{tpl_name}.pvm/", "GuestTools": { + "state": "#{tools_state}", "version": "#{tools_version}" }, "Hardware": { diff --git a/test/unit/driver/pd_9_test.rb b/test/unit/driver/pd_9_test.rb index 3e0762f0..bc973f88 100644 --- a/test/unit/driver/pd_9_test.rb +++ b/test/unit/driver/pd_9_test.rb @@ -9,6 +9,7 @@ let(:tpl_uuid) {'1234-some-template-uuid-5678'} let(:tpl_name) {'Some_Template_Name'} + let(:tools_state) {'installed'} let(:tools_version) {'9.0.23062.123456'} let(:hostonly_iface) {'vnic10'} @@ -75,6 +76,7 @@ "State": "stopped", "Home": "/path/to/#{vm_name}.pvm/", "GuestTools": { + "state": "#{tools_state}", "version": "#{tools_version}" }, "Hardware": { @@ -135,6 +137,7 @@ "State": "stopped", "Home": "/path/to/#{tpl_name}.pvm/", "GuestTools": { + "state": "#{tools_state}", "version": "#{tools_version}" }, "Hardware": { diff --git a/test/unit/support/shared/pd_driver_examples.rb b/test/unit/support/shared/pd_driver_examples.rb index 724d2e1b..aa68942f 100644 --- a/test/unit/support/shared/pd_driver_examples.rb +++ b/test/unit/support/shared/pd_driver_examples.rb @@ -146,18 +146,16 @@ end end - describe "read_guest_tools_version" do - let(:tools_version) {'9.0.23062.123456-something-else'} + describe "read_guest_tools_state" do + let(:tools_state) {'outdated'} - it "returns Guest Tools version in semantic format: 'x.y.z'" do - subject.read_guest_tools_version.should match(/^\d+.\d+\.\d+$/) - subject.read_guest_tools_version.should == "9.0.23062" + it "returns Guest Tools state as a symbol" do + subject.read_guest_tools_state.should be(:outdated) end - it "returns nil if Guest Tools version is invalid" do - settings = {"GuestTools" => {"vesion" => "something_wrong"}} - driver.should_receive(:read_settings).and_return(settings) - subject.read_guest_tools_version.should be_nil + it "returns :not_installed if Guest Tools state can't be reached" do + driver.should_receive(:read_settings).and_return(exit_code: 0) + subject.read_guest_tools_state.should be(:not_installed) end end From 22d1e8a7e22b00444362fdd0ed2753c73c02654c Mon Sep 17 00:00:00 2001 From: Mikhail Zholobov Date: Wed, 14 May 2014 01:17:47 +0400 Subject: [PATCH 11/14] guest_cap: Added "install_parallels_tools" capability for linux guests [GH-70] --- .../linux/install_parallels_tools.rb | 53 +++++++++++++++++++ lib/vagrant-parallels/plugin.rb | 5 ++ 2 files changed, 58 insertions(+) create mode 100644 lib/vagrant-parallels/guest_cap/linux/install_parallels_tools.rb diff --git a/lib/vagrant-parallels/guest_cap/linux/install_parallels_tools.rb b/lib/vagrant-parallels/guest_cap/linux/install_parallels_tools.rb new file mode 100644 index 00000000..1b12df21 --- /dev/null +++ b/lib/vagrant-parallels/guest_cap/linux/install_parallels_tools.rb @@ -0,0 +1,53 @@ +module VagrantPlugins + module Parallels + module GuestLinuxCap + class InstallParallelsTools + + def self.install_parallels_tools(machine) + if ptiagent_usable?(machine) + # Argument '--info' means that Parallels Tools version will be + # checked before the installing. + machine.communicate.sudo("ptiagent-cmd --info") + else + machine.communicate.tap do |comm| + tools_iso_path = File.expand_path( + machine.provider.driver.read_guest_tools_iso_path("linux"), + machine.env.root_path + ) + remote_file = "/tmp/prl-tools-lin.iso" + mount_point = "/media/prl-tools-lin_#{rand(100000)}/" + + comm.upload(tools_iso_path, remote_file) + + # Create mount point directory if needed + if !comm.test("test -d \"#{mount_point}\"", :sudo => true) + comm.sudo("mkdir -p \"#{mount_point}\"") + end + + # Mount ISO and install Parallels Tools + comm.sudo("mount -o loop #{remote_file} #{mount_point}") + comm.sudo("#{mount_point}/install --install-unattended-with-deps") + comm.sudo("umount -f \"#{mount_point}\"") + + comm.sudo("rm -Rf \"#{mount_point}\"") + comm.sudo("rm -f \"#{remote_file}\"") + end + end + end + + private + + # This helper detects is Parallels Tools Installation Agent (PTIAgent) + # available and can be used + def self.ptiagent_usable?(machine) + # Parallels Desktop 9 or higher should be installed on the host and + # 'ptiagent-cmd' binary should be available on the guest + + machine.provider_name == :parallels && + Gem::Version.new(machine.provider.driver.version) >= Gem::Version.new("9") && + machine.communicate.test("which ptiagent-cmd", :sudo => true) + end + end + end + end +end diff --git a/lib/vagrant-parallels/plugin.rb b/lib/vagrant-parallels/plugin.rb index 19f58caf..1a0ae711 100644 --- a/lib/vagrant-parallels/plugin.rb +++ b/lib/vagrant-parallels/plugin.rb @@ -50,6 +50,11 @@ class Plugin < Vagrant.plugin("2") GuestLinuxCap::MountParallelsSharedFolder end + guest_capability(:linux, :install_parallels_tools) do + require_relative "guest_cap/linux/install_parallels_tools" + GuestLinuxCap::InstallParallelsTools + end + provider_capability(:parallels, :public_address) do require_relative "cap/public_address" Cap::PublicAddress From 5c2a9d6978cd4a4ae8392ce9a05519bafa7d5715 Mon Sep 17 00:00:00 2001 From: Mikhail Zholobov Date: Mon, 12 May 2014 11:50:57 +0400 Subject: [PATCH 12/14] action/set_power_consumption: Removed PD version checking. Use 'IsDriverVersion' middleware instead. --- lib/vagrant-parallels/action.rb | 7 +++++-- lib/vagrant-parallels/action/set_power_consumption.rb | 8 ++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/vagrant-parallels/action.rb b/lib/vagrant-parallels/action.rb index c0448173..a1d918ee 100644 --- a/lib/vagrant-parallels/action.rb +++ b/lib/vagrant-parallels/action.rb @@ -11,7 +11,6 @@ module Action # a bootup (i.e. not saved). def self.action_boot Vagrant::Action::Builder.new.tap do |b| - b.use SetPowerConsumption b.use SetName b.use Provision b.use PrepareNFSValidIds @@ -21,7 +20,11 @@ def self.action_boot b.use Network b.use ClearNetworkInterfaces b.use SetHostname - # b.use SaneDefaults + b.use Call, IsDriverVersion, '>= 9' do |env1, b1| + if env1[:result] + b1.use SetPowerConsumption + end + end b.use Customize, "pre-boot" b.use Boot b.use Customize, "post-boot" diff --git a/lib/vagrant-parallels/action/set_power_consumption.rb b/lib/vagrant-parallels/action/set_power_consumption.rb index d99a200f..098c5cfd 100644 --- a/lib/vagrant-parallels/action/set_power_consumption.rb +++ b/lib/vagrant-parallels/action/set_power_consumption.rb @@ -1,6 +1,8 @@ module VagrantPlugins module Parallels module Action + # Important: It works only with Parallels Desktop >= 9 ! + # Use "IsDriverVersion" middleware to wrap it. class SetPowerConsumption def initialize(app, env) @logger = Log4r::Logger.new("vagrant::plugins::parallels::power_consumption") @@ -8,12 +10,6 @@ def initialize(app, env) end def call(env) - pd_version = env[:machine].provider.driver.version - if Gem::Version.new(pd_version) < Gem::Version.new("9") - @logger.info("Power consumption management is available only for Parallels Desktop >= 9") - return @app.call(env) - end - # Optimization of power consumption is defined by "Longer Battery Life" state. vm_settings = env[:machine].provider.driver.read_settings From eca4a9ed7be174c450359e2a40854f70b4e96ebd Mon Sep 17 00:00:00 2001 From: Mikhail Zholobov Date: Thu, 15 May 2014 11:31:48 +0400 Subject: [PATCH 13/14] errors: Text for 'VMImportFailure' customized. Default message from vagrant contains a virtualbox-specific phrase --- lib/vagrant-parallels/action/import.rb | 2 +- lib/vagrant-parallels/errors.rb | 4 ++++ locales/en.yml | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/vagrant-parallels/action/import.rb b/lib/vagrant-parallels/action/import.rb index 6b541987..14f85274 100644 --- a/lib/vagrant-parallels/action/import.rb +++ b/lib/vagrant-parallels/action/import.rb @@ -15,7 +15,7 @@ def call(env) unregister_template # Flag as erroneous and return if import failed - raise Vagrant::Errors::VMImportFailure if !env[:machine].id + raise VagrantPlugins::Parallels::Errors::VMImportFailure if !env[:machine].id # Import completed successfully. Continue the chain @app.call(env) diff --git a/lib/vagrant-parallels/errors.rb b/lib/vagrant-parallels/errors.rb index bafbc5d4..3ba622df 100644 --- a/lib/vagrant-parallels/errors.rb +++ b/lib/vagrant-parallels/errors.rb @@ -39,6 +39,10 @@ class ParallelsToolsIsoNotFound < VagrantParallelsError error_key(:parallels_tools_iso_not_found) end + class VMImportFailure < VagrantParallelsError + error_key(:vm_import_failure) + end + class VMNameExists < VagrantParallelsError error_key(:vm_name_exists) end diff --git a/locales/en.yml b/locales/en.yml index 4a5e84ef..a309db1a 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -51,6 +51,10 @@ en: reinstall Parallels Desktop. Expected ISO path: "%{iso_path}" + vm_import_failure: |- + The VM import failed! Please verify that the box you're using is not + corrupted and try again. + vm_name_exists: |- Parallels Desktop virtual machine with the name '%{name}' already exists. Please use another name or delete the machine with the existing From e7719ca49223abd23b7ecf259e52c45bf871bc30 Mon Sep 17 00:00:00 2001 From: Mikhail Zholobov Date: Thu, 15 May 2014 14:23:57 +0400 Subject: [PATCH 14/14] Version bumped to v1.1.0 --- lib/vagrant-parallels/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant-parallels/version.rb b/lib/vagrant-parallels/version.rb index 001cb673..f4572375 100644 --- a/lib/vagrant-parallels/version.rb +++ b/lib/vagrant-parallels/version.rb @@ -1,5 +1,5 @@ module VagrantPlugins module Parallels - VERSION = "1.0.9.rc1" + VERSION = "1.1.0" end end