Class: VagrantPlugins::Parallels::Action::Import
- Inherits:
-
Object
- Object
- VagrantPlugins::Parallels::Action::Import
- Defined in:
- lib/vagrant-parallels/action/import.rb
Constant Summary collapse
- @@lock =
Mutex.new
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ Import
constructor
A new instance of Import.
- #recover(env) ⇒ Object
Constructor Details
#initialize(app, env) ⇒ Import
Returns a new instance of Import.
9 10 11 12 |
# File 'lib/vagrant-parallels/action/import.rb', line 9 def initialize(app, env) @app = app @logger = Log4r::Logger.new('vagrant_parallels::action::import') end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/vagrant-parallels/action/import.rb', line 14 def call(env) = {} # Disable requiring password for register and clone actions [GH-67]. acts = ['clone-vm'] @logger.info("Disabling password restrictions: #{acts.join(', ')}") env[:machine].provider.driver.disable_password_restrictions(acts) if env[:machine].provider_config.regen_src_uuid [:regenerate_src_uuid] = true end # Linked clones are supported only for PD 11 and higher # Linked clones are not supported in macvms if env[:machine].provider_config.linked_clone and !Util::Common::is_macvm(env[:machine]) # Linked clone creation should not be concurrent [GH-206] [:snapshot_id] = env[:clone_snapshot_id] [:linked] = true @@lock.synchronize do lock_key = Digest::MD5.hexdigest("#{env[:clone_id]}-linked-clone") env[:machine].env.lock(lock_key, retry: true) do env[:ui].info I18n.t('vagrant_parallels.actions.vm.clone.linked') clone(env, ) end end else env[:ui].info I18n.t('vagrant_parallels.actions.vm.clone.full') clone(env, ) end # If we got interrupted, then the import could have been # interrupted and its not a big deal. Just return out. return if env[:interrupted] # Flag as erroneous and return if import failed raise Errors::VMCloneFailure if !env[:machine].id # Remove 'Icon\r' file from VM home (bug in PD 11.0.0) if env[:machine].provider.pd_version_satisfies?('= 11.0.0') vm_home = env[:machine].provider.driver.read_settings.fetch('Home') broken_icns = Dir[File.join(vm_home, 'Icon*')] FileUtils.rm(broken_icns, :force => true) end # Copy the SSH key from the clone machine if we can if env[:clone_machine] key_path = env[:clone_machine].data_dir.join('private_key') if key_path.file? FileUtils.cp(key_path, env[:machine].data_dir.join('private_key')) end end # Import completed successfully. Continue the chain @app.call(env) end |
#recover(env) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/vagrant-parallels/action/import.rb', line 70 def recover(env) if env[:machine] && env[:machine].state.id != :not_created return if env['vagrant.error'].is_a?(Vagrant::Errors::VagrantError) return if env['vagrant_parallels.error'].is_a?(Errors::VagrantParallelsError) # If we're not supposed to destroy on error then just return return if !env[:destroy_on_error] # Interrupted, destroy the VM. We note that we don't want to # validate the configuration here, and we don't want to confirm # we want to destroy. destroy_env = env.clone destroy_env[:config_validate] = false destroy_env[:force_confirm_destroy] = true env[:action_runner].run(Action.action_destroy, destroy_env) end end |