From 5811395a11558cd9f0d579af0c447e8500c9247c Mon Sep 17 00:00:00 2001 From: Mikhail Zholobov Date: Mon, 23 Nov 2015 10:36:35 +0200 Subject: [PATCH] driver/meta: cache Parallels Desktop version Actually, Parallels Desktop version is not changing during the Vagrant run. So, we can cache it on the class level to speed up the execution and avoid extra `prlctl --version` calls. This is a port of upstream PR: https://github.com/mitchellh/vagrant/pull/6552 --- lib/vagrant-parallels/driver/meta.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/vagrant-parallels/driver/meta.rb b/lib/vagrant-parallels/driver/meta.rb index e93628cf..5ad500e7 100644 --- a/lib/vagrant-parallels/driver/meta.rb +++ b/lib/vagrant-parallels/driver/meta.rb @@ -14,6 +14,11 @@ class VMNotFound < StandardError; end # We use forwardable to do all our driver forwarding extend Forwardable + # We cache the Parallels Desktop version here once we have one, + # since during the execution of Vagrant, it likely doesn't change. + @@version = nil + @@version_lock = Mutex.new + # The UUID of the virtual machine we represent attr_reader :uuid @@ -29,12 +34,14 @@ def initialize(uuid=nil) # Read and assign the version of Parallels Desktop we know which # specific driver to instantiate. - @version = read_version || '' - + @@version_lock.synchronize do + @@version = read_version + end + # Instantiate the proper version driver for Parallels Desktop - @logger.debug("Finding driver for Parallels Desktop version: #{@version}") + @logger.debug("Finding driver for Parallels Desktop version: #{@@version}") - major_ver = @version.split('.').first.to_i + major_ver = @@version.split('.').first.to_i driver_klass = case major_ver when 1..7 then raise Errors::ParallelsUnsupportedVersion @@ -55,6 +62,7 @@ def initialize(uuid=nil) @logger.info("Using Parallels driver: #{driver_klass}") @driver = driver_klass.new(@uuid) + @version = @@version if @uuid # Verify the VM exists, and if it doesn't, then don't worry