Sha256: 156a54038288067b72ce9ad0012148a271d1c878ee65123711cbd3240ca0e32c

Contents?: true

Size: 1.5 KB

Versions: 56

Compression:

Stored size: 1.5 KB

Contents

require 'json'

module VagrantPlugins
  module CommandSnapshot
    module Command
      module PushShared
        def shared_exec(argv, m, opts={})
          with_target_vms(argv) do |vm|
            if !vm.id
              vm.ui.info("Not created. Cannot push snapshot state.")
              next
            end

            vm.env.lock("machine-snapshot-stack") do
              m.call(vm, opts)
            end
          end

          # Success, exit with 0
          0
        end

        def push(machine, opts={})
          snapshot_name = "push_#{Time.now.to_i}_#{rand(10000)}"

          # Save the snapshot. This will raise an exception if it fails.
          machine.action(:snapshot_save, snapshot_name: snapshot_name)
        end

        def pop(machine, opts={})
          # By reverse sorting, we should be able to find the first
          # pushed snapshot.
          name = nil
          snapshots = machine.provider.capability(:snapshot_list)
          snapshots.sort.reverse.each do |snapshot|
            if snapshot =~ /^push_\d+_\d+$/
              name = snapshot
              break
            end
          end

          # If no snapshot was found, we never pushed
          if !name
            machine.ui.info(I18n.t("vagrant.commands.snapshot.no_push_snapshot"))
            return
          end

          # Restore the snapshot and tell the provider to delete it, if required
          opts[:snapshot_name] = name
          machine.action(:snapshot_restore, opts)
        end
      end
    end
  end
end

Version data entries

56 entries across 52 versions & 6 rubygems

Version Path
vagrant-unbundled-2.3.6.0 plugins/commands/snapshot/command/push_shared.rb
tamtam-vagrant-reload-1.2.1 vendor/cache/vagrant-2092df529ae7/plugins/commands/snapshot/command/push_shared.rb
vagrant-unbundled-2.3.3.0 plugins/commands/snapshot/command/push_shared.rb
vagrant-unbundled-2.3.2.0 plugins/commands/snapshot/command/push_shared.rb
vagrant-unbundled-2.2.19.0 plugins/commands/snapshot/command/push_shared.rb
vagrant-unbundled-2.2.18.0 plugins/commands/snapshot/command/push_shared.rb
vagrant-unbundled-2.2.16.0 plugins/commands/snapshot/command/push_shared.rb
vagrant-unbundled-2.2.14.0 plugins/commands/snapshot/command/push_shared.rb
vagrant-aws-mkubenka-0.7.2.pre.24 vendor/bundle/ruby/2.7.0/bundler/gems/vagrant-22795b161bf6/plugins/commands/snapshot/command/push_shared.rb
vagrant-unbundled-2.2.10.0 plugins/commands/snapshot/command/push_shared.rb
vagrant-unbundled-2.2.9.0 plugins/commands/snapshot/command/push_shared.rb
vagrant-unbundled-2.2.8.0 plugins/commands/snapshot/command/push_shared.rb
vagrant-unbundled-2.2.7.0 plugins/commands/snapshot/command/push_shared.rb
vagrant-unbundled-2.2.6.2 plugins/commands/snapshot/command/push_shared.rb
vagrant-unbundled-2.2.6.1 plugins/commands/snapshot/command/push_shared.rb
vagrant-unbundled-2.2.6.0 plugins/commands/snapshot/command/push_shared.rb
vagrant-unbundled-2.2.5.0 plugins/commands/snapshot/command/push_shared.rb
vagrant-unbundled-2.2.4.0 plugins/commands/snapshot/command/push_shared.rb
vagrant-unbundled-2.2.3.0 plugins/commands/snapshot/command/push_shared.rb
vagrant-unbundled-2.2.2.0 plugins/commands/snapshot/command/push_shared.rb