diff --git a/Gemfile b/Gemfile index 096cf3a5..49ccd190 100644 --- a/Gemfile +++ b/Gemfile @@ -9,5 +9,5 @@ group :development do # We depend on Vagrant for development, but we don't add it as a # gem dependency because we expect to be installed within the # Vagrant environment itself using `vagrant plugin`. - gem 'vagrant', :git => 'git://github.com/mitchellh/vagrant.git' + gem 'vagrant', git: 'git://github.com/mitchellh/vagrant.git', tag: 'v1.7.1' end diff --git a/lib/vagrant-parallels/action/handle_guest_tools.rb b/lib/vagrant-parallels/action/handle_guest_tools.rb index b713d3ad..1e1720ac 100644 --- a/lib/vagrant-parallels/action/handle_guest_tools.rb +++ b/lib/vagrant-parallels/action/handle_guest_tools.rb @@ -17,7 +17,7 @@ def call(env) env[:ui].output(I18n.t("vagrant_parallels.actions.vm.handle_guest_tools.checking")) - tools_state = @machine.provider.driver.read_guest_tools_state + tools_state = parallels_tools_state if tools_state == :installed @logger.info("The proper version of Parallels Tools is already installed") @@ -50,6 +50,24 @@ def call(env) @app.call(env) end + private + + # Determines the state of Parallels Tools + # + # @return [Symbol] Parallels Tools state (ex. :installed, :outdated, + # :not_installed, :possibly_installed) + def parallels_tools_state + # Sometimes tools can define their state with a little delay. + # If it is 'possibly_installed', then just wait a bit and try again. + 3.times do + state = @machine.provider.driver.read_guest_tools_state + return state if state != :possibly_installed + sleep 2 + end + + @machine.provider.driver.read_guest_tools_state + end + end end end diff --git a/lib/vagrant-parallels/action/import.rb b/lib/vagrant-parallels/action/import.rb index c95f7906..d5960d29 100644 --- a/lib/vagrant-parallels/action/import.rb +++ b/lib/vagrant-parallels/action/import.rb @@ -58,9 +58,7 @@ def recover(env) def register_template(tpl_path_s) @logger.info("Register the box template: '#{tpl_path_s}'") - regen_uuid = @machine.provider_config.regen_box_uuid - - @machine.provider.driver.register(tpl_path_s, regen_uuid) + @machine.provider.driver.register(tpl_path_s) end def template_path @@ -96,6 +94,11 @@ def import(env, tpl_name) # Clear the line one last time since the progress meter doesn't disappear # immediately. env[:ui].clear_line + + if @machine.provider_config.regen_src_uuid + @logger.info("Regenerate SourceVmUuid") + @machine.provider.driver.regenerate_src_uuid + end end def unregister_template(tpl_name) diff --git a/lib/vagrant-parallels/config.rb b/lib/vagrant-parallels/config.rb index 45624d5a..75534eae 100644 --- a/lib/vagrant-parallels/config.rb +++ b/lib/vagrant-parallels/config.rb @@ -8,12 +8,15 @@ class Config < Vagrant.plugin("2", :config) attr_accessor :optimize_power_consumption attr_accessor :name attr_reader :network_adapters - attr_accessor :regen_box_uuid + attr_accessor :regen_src_uuid attr_accessor :update_guest_tools # Compatibility with virtualbox provider's syntax alias :check_guest_additions= :check_guest_tools= + # Compatibility with old names + alias :regen_box_uuid= :regen_src_uuid= + def initialize @check_guest_tools = UNSET_VALUE @customizations = [] @@ -22,7 +25,7 @@ def initialize @network_adapters = {} @name = UNSET_VALUE @optimize_power_consumption = UNSET_VALUE - @regen_box_uuid = UNSET_VALUE + @regen_src_uuid = UNSET_VALUE @update_guest_tools = UNSET_VALUE network_adapter(0, :shared) @@ -47,6 +50,10 @@ def cpus=(count) customize("pre-boot", ["set", :id, "--cpus", count.to_i]) end + def regen_box_uuid=(value) + @regen_src_uuid = value + end + def merge(other) super.tap do |result| c = customizations.dup @@ -74,7 +81,7 @@ def finalize! @name = nil if @name == UNSET_VALUE - @regen_box_uuid = true if @regen_box_uuid == UNSET_VALUE + @regen_src_uuid = true if @regen_src_uuid == UNSET_VALUE if @update_guest_tools == UNSET_VALUE @update_guest_tools = false diff --git a/lib/vagrant-parallels/driver/base.rb b/lib/vagrant-parallels/driver/base.rb index 28e617ae..5684306c 100644 --- a/lib/vagrant-parallels/driver/base.rb +++ b/lib/vagrant-parallels/driver/base.rb @@ -193,13 +193,15 @@ def read_vm_option(option, uuid=@uuid) def read_vms end + # Regenerates 'SourceVmUuid' to avoid SMBIOS UUID collision [GH-113] + # + def regenerate_src_uuid + end + # Registers the virtual machine # # @param [String] pvm_file Path to the machine image (*.pvm) - # @param [Boolean] regen_src_uuid Regenerate 'SourceVmUuid' to avoid - # SMBIOS UUID collision, or let it unchanged to keep activation status - # for Windows-based guests [GH-113] - def register(pvm_file, regen_src_uuid) + def register(pvm_file) end # Resumes the virtual machine. diff --git a/lib/vagrant-parallels/driver/meta.rb b/lib/vagrant-parallels/driver/meta.rb index 7191b5fd..9c18b61e 100644 --- a/lib/vagrant-parallels/driver/meta.rb +++ b/lib/vagrant-parallels/driver/meta.rb @@ -105,6 +105,7 @@ def initialize(uuid=nil) :read_vms, :read_vms_info, :read_vms_paths, + :regenerate_src_uuid, :register, :resume, :set_power_consumption_mode, diff --git a/lib/vagrant-parallels/driver/pd_8.rb b/lib/vagrant-parallels/driver/pd_8.rb index 03c16ccd..7df377c3 100644 --- a/lib/vagrant-parallels/driver/pd_8.rb +++ b/lib/vagrant-parallels/driver/pd_8.rb @@ -1,4 +1,6 @@ require 'log4r' +require 'nokogiri' +require 'securerandom' require 'vagrant/util/platform' @@ -430,9 +432,22 @@ def read_vms_paths list end - def register(pvm_file, regen_src_uuid=false) + def regenerate_src_uuid + settings = read_settings + vm_config = File.join(settings.fetch('Home'), 'config.pvs') + + # Generate and put new SourceVmUuid + xml = Nokogiri::XML(File.open(vm_config)) + p = '//ParallelsVirtualMachine/Identification/SourceVmUuid' + xml.xpath(p).first.content = "{#{SecureRandom.uuid}}" + + File.open(vm_config, 'w') do |f| + f.write xml.to_xml + end + end + + def register(pvm_file) args = ['prlctl', 'register', pvm_file] - args << '--regenerate-src-uuid' if regen_src_uuid 3.times do result = raw(*args) diff --git a/lib/vagrant-parallels/version.rb b/lib/vagrant-parallels/version.rb index 088a4788..6f51b9a3 100644 --- a/lib/vagrant-parallels/version.rb +++ b/lib/vagrant-parallels/version.rb @@ -1,5 +1,5 @@ module VagrantPlugins module Parallels - VERSION = "1.3.4" + VERSION = '1.3.5' end end diff --git a/test/unit/support/shared/pd_driver_examples.rb b/test/unit/support/shared/pd_driver_examples.rb index e229e8d5..a6065d8b 100644 --- a/test/unit/support/shared/pd_driver_examples.rb +++ b/test/unit/support/shared/pd_driver_examples.rb @@ -249,15 +249,6 @@ subject.register("/path/to/vm_image.pvm") end - - it "registers specified virtual machine or template and regen src uuid" do - subprocess.should_receive(:execute). - with("prlctl", "register", an_instance_of(String), - "--regenerate-src-uuid", an_instance_of(Hash)). - and_return(subprocess_result(exit_code: 0)) - - subject.register("/path/to/vm_image.pvm", regen_src_uuid=true) - end end describe "set_mac_address" do