lib/vagrant-parallels/driver/meta.rb in vagrant-parallels-1.4.1 vs lib/vagrant-parallels/driver/meta.rb in vagrant-parallels-1.4.2

- old
+ new

@@ -31,30 +31,27 @@ # specific driver to instantiate. @version = read_version || '' # Instantiate the proper version driver for Parallels Desktop @logger.debug("Finding driver for Parallels Desktop version: #{@version}") - driver_map = { - '8' => PD_8, - '9' => PD_9, - '10' => PD_10, - '11' => PD_11 - } - driver_klass = nil - driver_map.each do |key, klass| - if @version.start_with?(key) - driver_klass = klass - break + driver_klass = + case @version.split('.').first + when '8' then PD_8 + when '9' then PD_9 + when '10' then PD_10 + when '11' then PD_11 + else raise Errors::ParallelsUnsupportedVersion end - end - if !driver_klass - supported_versions = driver_map.keys.sort - - raise VagrantPlugins::Parallels::Errors::ParallelsInvalidVersion, - supported_versions: supported_versions.join(", ") + # Starting since PD 11 only Pro and Business editions have CLI + # functionality and can be used with Vagrant. + if @version.split('.').first.to_i >= 11 + edition = read_edition + if !edition || !%w(any pro business).include?(edition) + raise Errors::ParallelsUnsupportedEdition + end end @logger.info("Using Parallels driver: #{driver_klass}") @driver = driver_klass.new(@uuid) @@ -112,10 +109,22 @@ :unregister, :vm_exists? protected + # Returns the edition of Parallels Desktop that is running. It makes + # sense only for Parallels Desktop 11 and later. For older versions + # it returns nil. + # + # @return [String] + def read_edition + lic_info = json({}) do + execute(@prlsrvctl_path, 'info', '--license', '--json') + end + lic_info['edition'] + end + # This returns the version of Parallels Desktop that is running. # # @return [String] def read_version # The version string is usually in one of the following formats: @@ -123,15 +132,16 @@ # * prlctl version 8.0.12345.123456 # * prlctl version 9.0.12345.123456 # * prlctl version 10.0.0 (12345) rev 123456 # # But we need exactly the first 3 numbers: "x.x.x" + output = execute(@prlctl_path, '--version') - if execute(@prlctl_path, '--version') =~ /prlctl version (\d+\.\d+.\d+)/ - return $1 + if output =~ /prlctl version (\d+\.\d+.\d+)/ + Regexp.last_match(1) + else + raise Errors::ParallelsInvalidVersion, output: output end - - nil end end end end end