vagrant-zfs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .vagrant
2
+ .bundle
3
+ bin/
4
+ pkg/
5
+ tmp/
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ #before_script:
3
+ # - sudo apt-get -y install linux-headers-$(uname -r)
4
+ # - sudo apt-get install virtualbox
5
+ script: "bundle exec rake test:unit"
6
+ rvm:
7
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vagrant-zfs (0.0.1)
5
+ zfs
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ archive-tar-minitar (0.5.2)
11
+ childprocess (0.3.7)
12
+ ffi (~> 1.0, >= 1.0.6)
13
+ erubis (2.7.0)
14
+ ffi (1.3.1)
15
+ i18n (0.6.1)
16
+ json (1.5.4)
17
+ log4r (1.1.10)
18
+ minitest (3.5.0)
19
+ net-scp (1.0.4)
20
+ net-ssh (>= 1.99.1)
21
+ net-ssh (2.2.2)
22
+ rake (0.9.2.2)
23
+ vagrant (1.0.6)
24
+ archive-tar-minitar (= 0.5.2)
25
+ childprocess (~> 0.3.1)
26
+ erubis (~> 2.7.0)
27
+ i18n (~> 0.6.0)
28
+ json (~> 1.5.1)
29
+ log4r (~> 1.1.9)
30
+ net-scp (~> 1.0.4)
31
+ net-ssh (~> 2.2.2)
32
+ zfs (0.1.1)
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ minitest
39
+ rake
40
+ vagrant (= 1.0.6)
41
+ vagrant-zfs!
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 JD Harrington
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # Vagrant-ZFS
2
+
3
+ Vagrant-ZFS is a plugin for [Vagrant][1] to automate cloning and sharing
4
+ ZFS filesystems from the host machine to a guest VM. This is useful for
5
+ things like bringing up multiple VMs to test database clustering without
6
+ requiring you to manually copy large amounts of data into multiple
7
+ locations on your host machine or syncing data from host to VMs.
8
+
9
+ This project is still in the very early stages, so proceed with caution.
10
+
11
+ ## Using Vagrant-ZFS in your project
12
+
13
+ 1. Install the vagrant-zfs gem into Vagrant's isolated environment.
14
+
15
+ ```
16
+ $ vagrant gem install vagrant-zfs
17
+ ```
18
+
19
+ 2. Configure filesystems to be cloned and shared in your Vagrantfile.
20
+
21
+ ```ruby
22
+ Vagrant::Config.run do |config|
23
+ ...
24
+
25
+ logical_name = "mysql"
26
+ guest_path = "/data/mysql"
27
+ zfs_name = "mysql/baseline" # Expects pool/filesystem_name
28
+
29
+ config.zfs.share_cloned_folder logical_name, guest_path, zfs_name
30
+
31
+ ...
32
+ end
33
+ ```
34
+
35
+ ## Trying out Vagrant-ZFS
36
+
37
+ 1. Make sure you have ZFS. On OS X, you can install [Zevo][2].
38
+ 2. You'll also need [VirtualBox][3] and [Vagrant][1] installed.
39
+ 3. Get the vagrant-zfs repository.
40
+
41
+ ```
42
+ $ git clone https://github.com/psi/vagrant-zfs
43
+ $ cd vagrant-zfs
44
+ $ bundle install
45
+ ```
46
+
47
+ 3. Create a sandbox zpool and filesystem.
48
+
49
+ ```
50
+ $ bundle exec rake sandbox:create
51
+ ```
52
+
53
+ 4. Bring up a test VM.
54
+
55
+ ```
56
+ $ bundle exec vagrant up
57
+ $ bundle exec vagrant ssh
58
+
59
+ # Take a look in /data/vagrant-zfs-test on the VM and you'll
60
+ # see the on_zfs.txt file that we touched earlier.
61
+ #
62
+ # Now, exit the VM...
63
+
64
+ $ zfs list | grep vagrant_zfs_test/test
65
+ vagrant_zfs_test/test 33.5Ki 27.2Mi 33.5Ki /Volumes/vagrant_zfs_test/test
66
+ vagrant_zfs_test/test-94813591-df75-4cc9-8067-faaaff291bd7 1Ki 27.2Mi 33.5Ki /Volumes/vagrant_zfs_test/test-94813591-df75-4cc9-8067-faaaff291bd7
67
+
68
+ # Notice the original filesystem you created and the cloned filesystem
69
+ # that is now attached to the VM. The UUID of the Vagrant instance is
70
+ # appended to the clone name so you can bring up multiple VMs, each with
71
+ # their own clone of the original filesystem.
72
+ ```
73
+
74
+ 5. Destroy your VM and cleanup
75
+
76
+ ```
77
+ $ bundle exec vagrant destroy
78
+
79
+ $ zfs list | grep vagrant_zfs_test/test
80
+ vagrant_zfs_test/test 33.5Ki 27.1Mi 33.5Ki /Volumes/vagrant_zfs_test/test
81
+
82
+ # Destroying the VM also destroys the cloned filesystem and the snapshot
83
+ # that was used to make it so you won't end up with tons of crufty clones.
84
+
85
+ $ bundle exec rake sandbox:destroy
86
+ ```
87
+
88
+ [1]: http://www.vagrantup.com/
89
+ [2]: http://getgreenbytes.com/solutions/zevo/
90
+ [3]: https://www.virtualbox.org/
data/Rakefile ADDED
@@ -0,0 +1,69 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ require "zfs"
4
+
5
+ task :default => "test:unit"
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.name = "test:all"
9
+ t.pattern = "test/**/*_test.rb"
10
+ end
11
+
12
+ Rake::TestTask.new do |t|
13
+ t.name = "test:unit"
14
+ t.pattern = "test/unit/**/*_test.rb"
15
+ end
16
+
17
+ Rake::TestTask.new do |t|
18
+ t.name = "test:integration"
19
+ t.pattern = "test/integration/**/*_test.rb"
20
+ end
21
+
22
+ task "test:integration_setup" => %w(sandbox:create vagrant:up)
23
+ task "test:integration_teardown" => %w(vagrant:destroy sandbox:destroy)
24
+
25
+ namespace :vagrant do
26
+ desc "Bring test Vagrant VM up"
27
+ task :up do
28
+ system "bundle exec vagrant up"
29
+ end
30
+
31
+ desc "Destroy test Vagrant VM"
32
+ task :destroy do
33
+ system "bundle exec vagrant destroy -f"
34
+ end
35
+ end
36
+
37
+ def test_vdev_path
38
+ File.expand_path("../tmp/test_vdev", __FILE__)
39
+ end
40
+
41
+ namespace :sandbox do
42
+ desc "Create a ZFS filesystem for testing"
43
+ task :create do
44
+ # Create a zpool
45
+ sh "mkfile 64m #{test_vdev_path}"
46
+ sh "zpool create vagrant_zfs_test #{test_vdev_path}"
47
+
48
+ # Create a filesystem
49
+ fs = ZFS("vagrant_zfs_test/test")
50
+ fs.create
51
+
52
+ # Populate the filesystem
53
+ sh "touch #{fs.mountpoint}/on_zfs.txt"
54
+ end
55
+
56
+ desc "Destroy ZFS filesystem created for testing"
57
+ task :destroy do
58
+ # Destroy the filesystem
59
+ fs = ZFS("vagrant_zfs_test/test")
60
+ fs.destroy!
61
+
62
+ # Destroy the zpool
63
+
64
+ # With Zevo on OS X 10.8.x, `zpool create` works as a normal user, but
65
+ # `zpool destroy` appears to require root privileges, so we sudo here.
66
+ sh "sudo zpool destroy -f vagrant_zfs_test"
67
+ sh "rm #{test_vdev_path}"
68
+ end
69
+ end
data/Vagrantfile ADDED
@@ -0,0 +1,6 @@
1
+ Vagrant::Config.run do |config|
2
+ config.vm.box = "opscode_centos_6.3"
3
+ config.vm.box_url = "https://opscode-vm.s3.amazonaws.com/vagrant/opscode_centos-6.3_chef-10.18.2.box"
4
+
5
+ config.zfs.share_cloned_folder "vagrant-zfs-test", "/data/vagrant-zfs-test", "vagrant_zfs_test/test"
6
+ end
@@ -0,0 +1 @@
1
+ require "vagrant_zfs"
@@ -0,0 +1,5 @@
1
+ require "zfs"
2
+
3
+ require "vagrant_zfs/version"
4
+ require "vagrant_zfs/config"
5
+ require "vagrant_zfs/middleware"
@@ -0,0 +1,19 @@
1
+ module VagrantZFS
2
+ class Config < Vagrant::Config::Base
3
+ attr_accessor :cloned_folders
4
+
5
+ def cloned_folders
6
+ @cloned_folders ||= {}
7
+ end
8
+
9
+ def share_cloned_folder(name, guestpath, filesystem, options = {})
10
+ self.cloned_folders[name] = {
11
+ :guestpath => guestpath,
12
+ :filesystem => filesystem,
13
+ :options => options
14
+ }
15
+ end
16
+ end
17
+ end
18
+
19
+ Vagrant.config_keys.register(:zfs) { VagrantZFS::Config }
@@ -0,0 +1,3 @@
1
+ Dir[File.dirname(__FILE__) + '/middleware/**/*.rb'].each do |file|
2
+ require file
3
+ end
@@ -0,0 +1,27 @@
1
+ module VagrantZFS
2
+ module Middleware
3
+ class CloneZFS
4
+ def initialize(app, env)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ uuid = env[:vm].uuid
10
+
11
+ env[:vm].config.zfs.cloned_folders.each do |name, data|
12
+ source_fs = ZFS(data[:filesystem])
13
+
14
+ snapshot = source_fs.snapshot(uuid)
15
+ new_fs = snapshot.clone!("#{data[:filesystem]}-#{uuid}")
16
+
17
+ env[:vm].config.vm.share_folder name, data[:guestpath], new_fs.mountpoint, data[:options]
18
+ end
19
+
20
+ @app.call(env)
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ Vagrant.actions[:start].insert_before Vagrant::Action::VM::ShareFolders,
27
+ VagrantZFS::Middleware::CloneZFS
@@ -0,0 +1,27 @@
1
+ module VagrantZFS
2
+ module Middleware
3
+ class DestroyZFS
4
+ def initialize(app, env)
5
+ @app = app
6
+ @env = env
7
+ end
8
+
9
+ def call(env)
10
+ uuid = @env[:vm].uuid
11
+
12
+ env[:vm].config.zfs.cloned_folders.each do |name, data|
13
+ new_fs = ZFS("#{data[:filesystem]}-#{uuid}")
14
+ snapshot = new_fs.origin
15
+
16
+ new_fs.destroy!
17
+ snapshot.destroy!
18
+ end
19
+
20
+ @app.call(env)
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ Vagrant.actions[:destroy].insert_before Vagrant::Action::VM::Destroy,
27
+ VagrantZFS::Middleware::DestroyZFS
@@ -0,0 +1,3 @@
1
+ module VagrantZFS
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + "/../test_helper"
2
+
3
+ describe "When bringing up a VM" do
4
+ before do
5
+ unless $vm_booted
6
+ system "bundle exec rake test:integration_setup"
7
+ $vm_booted = true
8
+ end
9
+ end
10
+
11
+ MiniTest::Unit.after_tests do
12
+ system "bundle exec rake test:integration_teardown"
13
+ end
14
+
15
+ it "attaches a clone to the VM" do
16
+ assert system("bundle exec vagrant ssh --command 'ls /data/vagrant-zfs-test/on_zfs.txt' >/dev/null")
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ require "minitest/autorun"
2
+ require "vagrant"
3
+
4
+ include Vagrant::TestHelpers
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + "/../../test_helper"
2
+ require "vagrant_zfs/middleware/clone_zfs"
3
+
4
+ describe VagrantZFS::Middleware::CloneZFS do
5
+ it "should rule" do
6
+ assert true
7
+ end
8
+ end
data/tmp/.gitkeep ADDED
File without changes
@@ -0,0 +1,34 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'vagrant_zfs/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "vagrant-zfs"
7
+ gem.version = VagrantZFS::VERSION
8
+ gem.authors = ["JD Harrington"]
9
+ gem.email = ["jd@jdharrington.net"]
10
+
11
+ gem.description = <<-EOF
12
+ Vagrant-ZFS is a plugin for Vagrant to automate cloning and sharing
13
+ ZFS filesystems from the host machine to a guest VM. This is useful
14
+ for things like bringing up multiple VMs to test database clustering
15
+ without requiring you to manually copy large amounts of data into
16
+ multiple locations on your host or syncing data from host to VMs.
17
+
18
+ This project is still in the very early stages, so proceed with caution.
19
+ EOF
20
+
21
+ gem.summary = "A Vagrant plugin to automate cloning and sharing ZFS filesystems with VMs"
22
+ gem.homepage = "http://github.com/psi/vagrant-zfs"
23
+
24
+ gem.files = `git ls-files`.split($/)
25
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
26
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
27
+ gem.require_paths = ["lib"]
28
+
29
+ gem.add_dependency "zfs"
30
+
31
+ gem.add_development_dependency "rake"
32
+ gem.add_development_dependency "minitest"
33
+ gem.add_development_dependency "vagrant", "1.0.6"
34
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-zfs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - JD Harrington
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: zfs
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: vagrant
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 1.0.6
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 1.0.6
78
+ description: ! " Vagrant-ZFS is a plugin for Vagrant to automate cloning and sharing\n
79
+ \ ZFS filesystems from the host machine to a guest VM. This is useful\n for
80
+ things like bringing up multiple VMs to test database clustering\n without requiring
81
+ you to manually copy large amounts of data into\n multiple locations on your
82
+ host or syncing data from host to VMs.\n\n This project is still in the very
83
+ early stages, so proceed with caution.\n"
84
+ email:
85
+ - jd@jdharrington.net
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .travis.yml
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - Vagrantfile
98
+ - lib/vagrant_init.rb
99
+ - lib/vagrant_zfs.rb
100
+ - lib/vagrant_zfs/config.rb
101
+ - lib/vagrant_zfs/middleware.rb
102
+ - lib/vagrant_zfs/middleware/clone_zfs.rb
103
+ - lib/vagrant_zfs/middleware/destroy_zfs.rb
104
+ - lib/vagrant_zfs/version.rb
105
+ - test/integration/integration_test.rb
106
+ - test/test_helper.rb
107
+ - test/unit/middleware/clone_zfs_test.rb
108
+ - tmp/.gitkeep
109
+ - vagrant-zfs.gemspec
110
+ homepage: http://github.com/psi/vagrant-zfs
111
+ licenses: []
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ segments:
123
+ - 0
124
+ hash: 1065014889121101321
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ segments:
132
+ - 0
133
+ hash: 1065014889121101321
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 1.8.23
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: A Vagrant plugin to automate cloning and sharing ZFS filesystems with VMs
140
+ test_files:
141
+ - test/integration/integration_test.rb
142
+ - test/test_helper.rb
143
+ - test/unit/middleware/clone_zfs_test.rb