vagrant-vbox-snapshot 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- M2Q3MjFmMjUyYjY1Yzk1OThlOGRlZWI3YWU1YTM3YmY4NDNjYTFjNg==
5
- data.tar.gz: !binary |-
6
- YzlmYjhjN2M1MjY2OWUyNGE2MzU2OGQzYmFiOWU2MTBlYmU3NzYyMg==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NDU4ZmZkMTdlMjVjNzc5ZWMxNTIzZDYzNTViNDRkYThkODYzMmUyN2NkMzcx
10
- NzBhNWI5ZGY5ZWExYTE5NGNmMWQ3NTY0YTY1YzJkN2I3MGJkMmMzMGY3NzZl
11
- NTllMGU4M2Q2NGQwZWI1YTlmNDk1NzA5NDYyOTlhYjM2MWFlNTA=
12
- data.tar.gz: !binary |-
13
- MTU2ZDY1NzgxOWM5YmUxNzYyZDg5Y2RhNmVhYTUxYTlhYTIzOGI5YjhiYzBj
14
- NmQzNjE4Yjc5NzRmNDgxMWQ1OWRlZDExMGZiNTFjNDJkNzA4NjlhYmFiNWI4
15
- NWMzMjdmZTgwNGM0MTMxZTkxYjUwZjYzMTEwYjMwMWY5MzNjZDE=
2
+ SHA1:
3
+ metadata.gz: 59803a44c1dfd4762ad171ac328e8281b5b0798c
4
+ data.tar.gz: 8ff585dcf406ac9c1932310283c695dabc0a5a68
5
+ SHA512:
6
+ metadata.gz: 2ff4aea7a11ac98f5f934c259e66723b3041fe3a57dd131873e6edda4f3a6da9c36f47d08458c391be3dd5bd914d36ebca5b3a47114644ea446e156cc37a3669
7
+ data.tar.gz: 35c4d93a36cb0c04e3074ce272ddfde3ec260105d15893cde898b372f5af0f979c5eb7117cf3703d7b0f92291c99ab8a76edaeaa08d201120b8c95424837842e
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ ## [0.0.3](https://github.com/dergachev/vagrant-vbox-snapshot/compare/v0.0.2...v0.0.3) (Sep 3, 2013)
2
+
3
+ BACKWARDS INCOMPATIBILITIES:
4
+
5
+ - none
6
+
7
+ FEATURES:
8
+
9
+ - Add multi-vm support [#6](https://github.com/dergachev/vagrant-vbox-snapshot/pull/6)
10
+
11
+ IMPROVEMENTS:
12
+
13
+ - Run `vagrant reload` when restoring snapshots with changed config [#2](https://github.com/dergachev/vagrant-vbox-snapshot/issues/2)
data/DEVNOTES.md CHANGED
@@ -26,3 +26,43 @@ Vagrant source code:
26
26
  ## other ideas related to snapshots
27
27
 
28
28
  * http://code.chrisroberts.org/blog/2012/05/09/cooking-up-partial-run-lists-with-chef/
29
+
30
+ ## Reviewing a pull request
31
+
32
+ ```
33
+ git clone https://github.com/dergachev/vagrant-vbox-snapshot.git
34
+ cd vagrant-vbox-snapshot
35
+ # consider branching if you aren't sure about merging it (not the case here, of course!)
36
+ # git checkout dubious-pull-request
37
+ git pull https://github.com/fgrehm/vagrant-vbox-snapshot multi-vm-environments-support
38
+ # test, fix stuff, etc
39
+ git push -u origin master
40
+ ```
41
+
42
+ ## Pushing out a new release of the gem
43
+
44
+ ```
45
+ # make commits
46
+ # consider creating/updating CHANGELOG.txt
47
+ vim lib/vagrant-vbox-snapshot/version.rb +/VERSION # increment version counter, eg to 0.0.3
48
+ gem build vagrant-vbox-snapshot.gemspec # creates vagrant-vbox-snapshot-0.0.3.gem
49
+
50
+ # test the gem locally, in a random vagrant project
51
+ cd ~/code/screengif
52
+ vagrant plugin uninstall vagrant-vbox-snapshot
53
+ vagrant plugin install ~/code/vagrant-vbox-snapshot/vagrant-vbox-snapshot-0.0.3.gem
54
+ # test it out, ensure basic sanity, eg for 0.0.3:
55
+ vagrant snapshot list -h
56
+ # cleanup
57
+ vagrant plugin uninstall
58
+
59
+ cd ~/code/vagrant-vbox-snapshot/
60
+ gem push vagrant-vbox-snapshot-0.0.3.gem
61
+ git tag 0.0.3
62
+ git push --tags
63
+
64
+ # test installing from rubygems
65
+ cd ~/code/screengif
66
+ vagrant plugin install vagrant-vbox-snapshot
67
+ vagrant plugin list
68
+ ```
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in vagrant-snap.gemspec
4
4
  gemspec
5
+
6
+ gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
data/README.md CHANGED
@@ -12,31 +12,47 @@ Ensure you have Vagrant 1.1+ installed, then run:
12
12
 
13
13
  The following commands are added by this plugin:
14
14
 
15
- vagrant snapshot take [NAME] # take snapshot, labeled by NAME
16
- vagrant snapshot list # list snapshots
17
- vagrant snapshot back # restore last taken snapshot
18
- vagrant snapshot delete SNAP_NAME # delete specified snapshot
19
- vagrant snapshot go SNAP_NAME # restore specified snapshot
15
+ vagrant snapshot take [vm-name] [NAME] # take snapshot, labeled by NAME
16
+ vagrant snapshot list [vm-name] # list snapshots
17
+ vagrant snapshot back [vm-name] # restore last taken snapshot
18
+ vagrant snapshot delete [vm-name] [NAME] # delete specified snapshot
19
+ vagrant snapshot go [vm-name] [NAME] # restore specified snapshot
20
20
 
21
21
  ## Caveats
22
22
 
23
23
  * Not compatible with Vagrant <1.1. If you need this, try [another solution](#other-solutions).
24
- * Does not support multiple VMs. (Pull requests encouraged).
25
24
  * Only minimally tested.
26
25
 
27
26
  ## Other solutions
28
27
 
29
- There have been a number of similar plugins, but none worked for Vagrant 1.1:
28
+ This plugin is primarily a port of vagrant-snap to Vagrant 1.1.
30
29
 
31
30
  * [vagrant-snap](https://github.com/t9md/vagrant-snap)
32
- - originally published as a gist: https://gist.github.com/t9md/1008031
33
- - fork of above gist, with Vagrant 1.0.6 compatibility: https://gist.github.com/tombh/5142237
34
- - [source](https://github.com/mitchellh/vagrant/issues/143#issuecomment-14781762)
35
- - primary inspiration for vagrant-vbox-snapshot
31
+ - fork with Vagrant 1.0.4-1.0.7 compatibility: https://gist.github.com/tombh/5142237 [source](https://github.com/mitchellh/vagrant/issues/143#issuecomment-14781762)
36
32
  * [sahara](https://github.com/jedi4ever/sahara)
37
33
  - fork exists with 1.1 functionality: https://github.com/ryuzee/sahara
38
34
 
39
35
  ## Development
40
36
 
37
+ To develop on this plugin, do the following:
38
+
39
+ ```
40
+ # get the repo, and then make a feature branch (REPLACE WITH YOUR FORK)
41
+ git clone https://github.com/dergachev/vagrant-vbox-snapshot.git
42
+ cd vagrant-vbox-snapshot
43
+ git checkout -b MY-NEW-FEATURE
44
+
45
+ # installs the vagrant gem, which is a dev dependency
46
+ bundle install
47
+
48
+ # hack on the plugin
49
+ vim lib/vagrant-vbox-snapshot.rb # or any other file
50
+
51
+ # test out your changes, in the context provided by the development vagrant gem, and the local Vagrantfile.
52
+ bundle exec vagrant snapshot ...
53
+
54
+ # commit, push, and do a pull-request
55
+ ```
56
+
41
57
  See [DEVNOTES.md](https://github.com/dergachev/vagrant-vbox-snapshot/blob/master/DEVNOTES.md)
42
58
  for the notes I compiled while developing this plugin.
data/Vagrantfile ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: ruby -*-
3
+ # vi: set ft=ruby :
4
+
5
+ require_relative 'lib/vagrant-vbox-snapshot.rb'
6
+
7
+ Vagrant.configure("2") do |config|
8
+
9
+ TEST_MULTI_VM = false
10
+ TEST_SHARED_FOLDERS = false
11
+
12
+ if TEST_MULTI_VM
13
+ config.vm.define :web do |web|
14
+ web.vm.box = "precise64"
15
+ end
16
+ config.vm.define :db do |web|
17
+ web.vm.box = "precise64"
18
+ end
19
+ else
20
+ config.vm.box = "precise64"
21
+ config.vm.box_url = "http://files.vagrantup.com/precise64.box"
22
+ end
23
+
24
+ if TEST_SHARED_FOLDERS
25
+ config.vm.synced_folder "/tmp", "/tmp/host-tmp"
26
+ config.vm.synced_folder "/tmp", "/tmp/host-tmp2"
27
+ end
28
+ end
@@ -8,13 +8,13 @@ module VagrantPlugins
8
8
  opts = OptionParser.new do |opts|
9
9
  opts.banner = "Back to current snapshot"
10
10
  opts.separator ""
11
- opts.separator "Usage: vagrant snapshot back"
11
+ opts.separator "Usage: vagrant snapshot back [vm-name]"
12
12
  end
13
13
  # Parse the options
14
14
  argv = parse_options(opts)
15
15
  return if !argv
16
16
 
17
- with_target_vms do |machine|
17
+ with_target_vms(argv, single_target: true) do |machine|
18
18
  vm_id = machine.id
19
19
  system "VBoxManage snapshot #{vm_id} list --details"
20
20
  system "VBoxManage controlvm #{vm_id} poweroff"
@@ -1,27 +1,28 @@
1
+ require_relative 'multi_vm_args'
2
+
1
3
  module VagrantPlugins
2
4
  module VBoxSnapshot
3
5
  module Command
4
6
  class Delete < Vagrant.plugin(2, :command)
7
+ include MultiVmArgs
8
+
5
9
  def execute
6
10
  options = {}
7
11
 
8
12
  opts = OptionParser.new do |opts|
9
13
  opts.banner = "Delete snapshot"
10
14
  opts.separator ""
11
- opts.separator "Usage: vagrant snapshot delete <SNAPSHOT_NAME>"
15
+ opts.separator "Usage: vagrant snapshot delete [vm-name] <SNAPSHOT_NAME>"
12
16
  end
13
17
  # Parse the options
14
18
  argv = parse_options(opts)
15
19
  return if !argv
16
20
 
17
- if !argv[0]
18
- @env.ui.info(opts.help, :prefix => false)
19
- return
20
- end
21
+ vm_name, snapshot_name = parse_vm_and_snapshot_options(argv, opts)
22
+ return if !snapshot_name
21
23
 
22
- with_target_vms do |machine|
24
+ with_target_vms(vm_name, single_target: true) do |machine|
23
25
  vm_id = machine.id
24
- snapshot_name = argv[0]
25
26
  system "VBoxManage snapshot #{vm_id} delete #{snapshot_name}"
26
27
  end
27
28
  end
@@ -1,30 +1,75 @@
1
+ require_relative 'multi_vm_args'
2
+
1
3
  module VagrantPlugins
2
4
  module VBoxSnapshot
3
5
  module Command
4
6
  class Go < Vagrant.plugin(2, :command)
7
+ include MultiVmArgs
8
+
9
+ def get_shared_folders(vm_id)
10
+ shared_folders = []
11
+ info = `VBoxManage showvminfo #{vm_id} --machinereadable`
12
+ info.split("\n").each do |line|
13
+ if line =~ /^SharedFolderNameMachineMapping\d+="(.+?)"$/
14
+ shared_folders << $1.to_s
15
+ end
16
+ end
17
+ return shared_folders
18
+ end
19
+
20
+ def before_restore(vm_id)
21
+ @shared_folders_before = get_shared_folders(vm_id)
22
+ end
23
+
24
+ def after_restore(vm_id)
25
+ @shared_folders_after = get_shared_folders(vm_id)
26
+ if @shared_folders_before != @shared_folders_after
27
+ missing_folders = @shared_folders_before - @shared_folders_after
28
+ @env.ui.warn("Synced folders have changed after restoring snapshot. Consider running 'vagrant reload'.")
29
+ @env.ui.warn(" Before restore: #{@shared_folders_before}")
30
+ @env.ui.warn(" After restore: #{@shared_folders_after}")
31
+ end
32
+ end
33
+
5
34
  def execute
6
35
  options = {}
36
+ options[:reload] = false
7
37
 
8
38
  opts = OptionParser.new do |opts|
9
39
  opts.banner = "Go to specified snapshot"
10
40
  opts.separator ""
11
- opts.separator "Usage: vagrant snapshot go <SNAPSHOT_NAME>"
41
+ opts.separator "Usage: vagrant snapshot go [vm-name] <SNAPSHOT_NAME>"
42
+
43
+ opts.on("-r", "--reload", "Runs 'vagrant reload --no-provision' after restoring snapshot to ensure Vagrantfile config is applied.") do |reload|
44
+ options[:reload] = reload
45
+ end
46
+
12
47
  end
13
48
  # Parse the options
14
49
  argv = parse_options(opts)
15
50
  return if !argv
16
51
 
17
- if !argv[0]
18
- @env.ui.info(opts.help, :prefix => false)
19
- return
20
- end
52
+ vm_name, snapshot_name = parse_vm_and_snapshot_options(argv, opts)
53
+ return if !snapshot_name
21
54
 
22
- with_target_vms do |machine|
55
+ with_target_vms(vm_name, single_target: true) do |machine|
23
56
  vm_id = machine.id
24
- snapshot_name = argv[0]
57
+
58
+ before_restore(vm_id)
59
+
25
60
  system "VBoxManage controlvm #{vm_id} poweroff"
26
- system "VBoxManage snapshot #{vm_id} restore #{snapshot_name}"
27
- system "VBoxManage startvm #{vm_id} --type headless"
61
+ system "VBoxManage snapshot #{vm_id} restore #{snapshot_name}"
62
+
63
+ if options[:reload]
64
+ @env.ui.info("Reloading VM")
65
+ machine.action(:reload, :provision_enabled => false)
66
+ else
67
+ @env.ui.info("Starting VM from restored snapshot (#{snapshot_name})")
68
+ @logger.info("starting VM")
69
+ system "VBoxManage startvm #{vm_id} --type headless"
70
+ end
71
+
72
+ after_restore(vm_id)
28
73
  end
29
74
  end
30
75
  end
@@ -14,7 +14,7 @@ module VagrantPlugins
14
14
  argv = parse_options(opts)
15
15
  return if !argv
16
16
 
17
- with_target_vms do |machine|
17
+ with_target_vms(argv, single_target: true) do |machine|
18
18
  vm_id = machine.id
19
19
  system "VBoxManage snapshot #{vm_id} list --details"
20
20
  end
@@ -0,0 +1,20 @@
1
+ module VagrantPlugins
2
+ module VBoxSnapshot
3
+ module Command
4
+ module MultiVmArgs
5
+ def parse_vm_and_snapshot_options(argv, opts)
6
+ unless [1, 2].include?(argv.size)
7
+ @env.ui.info(opts.help, :prefix => false)
8
+ return
9
+ end
10
+
11
+ if argv.size == 1
12
+ [nil, argv[0]]
13
+ else
14
+ [argv[0], argv[1]]
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,27 +1,28 @@
1
+ require_relative 'multi_vm_args'
2
+
1
3
  module VagrantPlugins
2
4
  module VBoxSnapshot
3
5
  module Command
4
6
  class Take < Vagrant.plugin(2, :command)
7
+ include MultiVmArgs
8
+
5
9
  def execute
6
10
  options = {}
7
11
 
8
12
  opts = OptionParser.new do |opts|
9
13
  opts.banner = "Take snapshot"
10
14
  opts.separator ""
11
- opts.separator "Usage: vagrant snapshot take <SNAPSHOT_NAME>"
15
+ opts.separator "Usage: vagrant snapshot take [vm-name] <SNAPSHOT_NAME>"
12
16
  end
13
17
  # Parse the options
14
18
  argv = parse_options(opts)
15
19
  return if !argv
16
20
 
17
- if !argv[0]
18
- @env.ui.info(opts.help, :prefix => false)
19
- return
20
- end
21
+ vm_name, snapshot_name = parse_vm_and_snapshot_options(argv, opts)
22
+ return if !snapshot_name
21
23
 
22
- with_target_vms do |machine|
24
+ with_target_vms(vm_name, single_target: true) do |machine|
23
25
  vm_id = machine.id
24
- snapshot_name = argv[0]
25
26
  system "VBoxManage snapshot #{vm_id} take #{snapshot_name} --pause"
26
27
  end
27
28
  end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module VBoxSnapshot
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-vbox-snapshot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Dergachev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-22 00:00:00.000000000 Z
11
+ date: 2013-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: Vagrant plugin that exposes the `VBoxManage snapshot` command.
@@ -45,15 +45,18 @@ extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
47
  - .gitignore
48
+ - CHANGELOG.md
48
49
  - DEVNOTES.md
49
50
  - Gemfile
50
51
  - README.md
51
52
  - Rakefile
53
+ - Vagrantfile
52
54
  - lib/vagrant-vbox-snapshot.rb
53
55
  - lib/vagrant-vbox-snapshot/commands/back.rb
54
56
  - lib/vagrant-vbox-snapshot/commands/delete.rb
55
57
  - lib/vagrant-vbox-snapshot/commands/go.rb
56
58
  - lib/vagrant-vbox-snapshot/commands/list.rb
59
+ - lib/vagrant-vbox-snapshot/commands/multi_vm_args.rb
57
60
  - lib/vagrant-vbox-snapshot/commands/root.rb
58
61
  - lib/vagrant-vbox-snapshot/commands/take.rb
59
62
  - lib/vagrant-vbox-snapshot/plugin.rb
@@ -69,12 +72,12 @@ require_paths:
69
72
  - lib
70
73
  required_ruby_version: !ruby/object:Gem::Requirement
71
74
  requirements:
72
- - - ! '>='
75
+ - - '>='
73
76
  - !ruby/object:Gem::Version
74
77
  version: '0'
75
78
  required_rubygems_version: !ruby/object:Gem::Requirement
76
79
  requirements:
77
- - - ! '>='
80
+ - - '>='
78
81
  - !ruby/object:Gem::Version
79
82
  version: '0'
80
83
  requirements: []