Sha256: 35eb6b6e5d942846b06894120a1abc04994a2f2ca356037b4047fe620f357538

Contents?: true

Size: 1.85 KB

Versions: 46

Compression:

Stored size: 1.85 KB

Contents

require "log4r"

require "digest/md5"

module VagrantPlugins
  module ProviderVirtualBox
    module Action
      class PrepareCloneSnapshot
        def initialize(app, env)
          @app = app
          @logger = Log4r::Logger.new("vagrant::action::vm::prepare_clone")
        end

        def call(env)
          if !env[:clone_id]
            @logger.info("no clone master, not preparing clone snapshot")
            return @app.call(env)
          end

          # If we're not doing a linked clone, snapshots don't matter
          if !env[:machine].provider_config.linked_clone
            return @app.call(env)
          end

          # We lock so that we don't snapshot in parallel
          lock_key = Digest::MD5.hexdigest("#{env[:clone_id]}-snapshot")
          env[:machine].env.lock(lock_key, retry: true) do
            prepare_snapshot(env)
          end

          # Continue
          @app.call(env)
        end

        protected

        def prepare_snapshot(env)
          name = env[:machine].provider_config.linked_clone_snapshot
          name_set = !!name
          name = "base" if !name
          env[:clone_snapshot] = name

          # Get the snapshots. We're done if it already exists
          snapshots = env[:machine].provider.driver.list_snapshots(env[:clone_id])
          if snapshots.include?(name)
            @logger.info("clone snapshot already exists, doing nothing")
            return
          end

          # If they asked for a specific snapshot, it is an error
          if name_set
            # TODO: Error
          end

          @logger.info("Creating base snapshot for master VM.")
          env[:machine].provider.driver.create_snapshot(
            env[:clone_id], name) do |progress|
              env[:ui].clear_line
              env[:ui].report_progress(progress, 100, false)
          end
        end
      end
    end
  end
end

Version data entries

46 entries across 42 versions & 5 rubygems

Version Path
vagrant-unbundled-2.2.7.0 plugins/providers/virtualbox/action/prepare_clone_snapshot.rb
vagrant-unbundled-2.2.6.2 plugins/providers/virtualbox/action/prepare_clone_snapshot.rb
vagrant-unbundled-2.2.6.1 plugins/providers/virtualbox/action/prepare_clone_snapshot.rb
vagrant-unbundled-2.2.6.0 plugins/providers/virtualbox/action/prepare_clone_snapshot.rb
vagrant-unbundled-2.2.5.0 plugins/providers/virtualbox/action/prepare_clone_snapshot.rb
vagrant-unbundled-2.2.4.0 plugins/providers/virtualbox/action/prepare_clone_snapshot.rb
vagrant-unbundled-2.2.3.0 plugins/providers/virtualbox/action/prepare_clone_snapshot.rb
vagrant-unbundled-2.2.2.0 plugins/providers/virtualbox/action/prepare_clone_snapshot.rb
vagrant-unbundled-2.2.0.0 plugins/providers/virtualbox/action/prepare_clone_snapshot.rb
vagrant-unbundled-2.1.4.0 plugins/providers/virtualbox/action/prepare_clone_snapshot.rb
vagrant-unbundled-2.1.2.0 plugins/providers/virtualbox/action/prepare_clone_snapshot.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.5.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/virtualbox/action/prepare_clone_snapshot.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/virtualbox/action/prepare_clone_snapshot.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/virtualbox/action/prepare_clone_snapshot.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/virtualbox/action/prepare_clone_snapshot.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/virtualbox/action/prepare_clone_snapshot.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/bundler/gems/vagrant-04f7215b5e3f/plugins/providers/virtualbox/action/prepare_clone_snapshot.rb
vagrant-unbundled-2.1.1.0 plugins/providers/virtualbox/action/prepare_clone_snapshot.rb
vagrant-unbundled-2.0.4.0 plugins/providers/virtualbox/action/prepare_clone_snapshot.rb
vagrant-unbundled-2.0.3.0 plugins/providers/virtualbox/action/prepare_clone_snapshot.rb