vagrant-persistent-storage 0.0.2

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.
@@ -0,0 +1 @@
1
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vagrant-persistent-storage.gemspec
4
+ gemspec
@@ -0,0 +1,77 @@
1
+ # Vagrant::Persistent-Storage
2
+
3
+
4
+ A Vagrant plugin that creates a persistent storage and attaches it to guest machine.
5
+
6
+ ## Installation
7
+
8
+ gem 'vagrant-persistent-storage'
9
+
10
+ And then execute:
11
+
12
+ $ bundle
13
+
14
+ Or install it yourself as:
15
+
16
+ $ gem install vagrant-persistent-storage
17
+
18
+ ## Usage
19
+
20
+ After installing you can set the location and size of the persistent storage.
21
+
22
+ The following options will create a persistent storage with 5000 MB:
23
+ ```ruby
24
+ config.persistent_storage.location = "~/development/sourcehdd.vdi"
25
+ config.persistent_storage.size = 5000
26
+ ```
27
+
28
+ Every `vagrant up` will attach this file as hard disk to the guest machine.
29
+ An `vagrant destory` will detach the storage to avoid deletion of the storage by vagrant.
30
+ A `vagrant destory` generally destroys all attached drives. See [VBoxMange unregistervm --delete option][vboxmanage_delete].
31
+
32
+ ### How to initialize the disk with puppet
33
+
34
+ This is a sample puppet setup to create a partition on the guest system:
35
+
36
+ ```puppet
37
+ class sources::persistent {
38
+ exec { "fdisk-sourcehd":
39
+ command => "/sbin/fdisk /dev/sdb << EOF
40
+ o
41
+ n
42
+ p
43
+ 1
44
+
45
+
46
+ w
47
+ EOF",
48
+ unless => "/bin/grep sdb1 /proc/partitions",
49
+ }
50
+
51
+ exec { "mkfs-sourcehd":
52
+ command => "/sbin/mkfs.ext3 -L sources -b 4096 /dev/sdb1",
53
+ unless => "/sbin/dumpe2fs /dev/sdb1"
54
+ }
55
+
56
+ exec { 'fstab-sourcehd':
57
+ command => '/bin/echo "/dev/disk/by-label/sources /mnt/sources ext3 defaults 0 2" >> /etc/fstab',
58
+ unless => '/bin/grep ^/dev/disk/by-label/sources /etc/fstab',
59
+ }
60
+
61
+ exec { 'mount-sourcehd':
62
+ command => '/bin/mkdir -p /mnt/sources; /bin/mount /mnt/sources',
63
+ subscribe => Exec['fstab-sourcehd'],
64
+ refreshonly => true,
65
+ }
66
+
67
+ Exec['fdisk-sourcehd'] -> Exec['mkfs-sourcehd'] -> Exec['fstab-sourcehd'] -> Exec['mount-sourcehd']
68
+ }
69
+ ```
70
+
71
+ ## TODO
72
+
73
+ * There's Always Something to Do
74
+ * Add more options (controller, port, etc.)
75
+
76
+
77
+ [vboxmanage_delete]: http://www.virtualbox.org/manual/ch08.html#vboxmanage-registervm "VBoxManage registervm / unregistervm"
@@ -0,0 +1,12 @@
1
+ require 'vagrant'
2
+ require 'vagrant/action/builder'
3
+ require 'vagrant-persistent-storage/config'
4
+ require 'vagrant-persistent-storage/middleware'
5
+ require 'vagrant-persistent-storage/version'
6
+
7
+ Vagrant.config_keys.register(:persistent_storage) { VagrantPersistentStorage::Config }
8
+ Vagrant.actions[:start].insert_after(Vagrant::Action::VM::ShareFolders, VagrantPersistentStorage::AttachPersistentStorage)
9
+ Vagrant.actions[:destroy].insert_after(Vagrant::Action::VM::PruneNFSExports, VagrantPersistentStorage::DetachPersistentStorage)
10
+
11
+ # Add our custom translations to the load path
12
+ #I18n.load_path << File.expand_path("../../locales/en.yml", __FILE__)
@@ -0,0 +1,7 @@
1
+ module VagrantPersistentStorage
2
+ class Config < Vagrant::Config::Base
3
+ attr_accessor :location
4
+ attr_accessor :size
5
+ end
6
+ end
7
+
@@ -0,0 +1,3 @@
1
+ Dir[File.dirname(__FILE__) + '/middleware/**/*.rb'].each do |file|
2
+ require file
3
+ end
@@ -0,0 +1,26 @@
1
+ module VagrantPersistentStorage
2
+ class AttachPersistentStorage
3
+ def initialize(app, env)
4
+ @app = app
5
+ @env = env
6
+ @vm = env[:vm]
7
+ end
8
+
9
+ def call(env)
10
+ options = @vm.config.persistent_storage
11
+ if !options.location ^ !options.size
12
+ env[:ui].error "Attach Persistent Storage failed. Location and size must be filled out."
13
+ elsif options.location
14
+ if !File.exists?(options.location)
15
+ @vm.config.vm.customize ["createhd", "--filename", options.location, "--size", options.size]
16
+ env[:ui].success "Create Persistent Storage."
17
+ end
18
+ @vm.config.vm.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", 1, "--type", "hdd", "--medium", options.location]
19
+
20
+ env[:ui].info "Attach Persistent Storage #{options.location} (Size: #{options.size}MB)"
21
+ end
22
+
23
+ @app.call(env)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,29 @@
1
+ module VagrantPersistentStorage
2
+ class DetachPersistentStorage
3
+ def initialize(app, env)
4
+ @app = app
5
+ @env = env
6
+ @vm = env[:vm]
7
+ end
8
+
9
+ def call(env)
10
+ options = @vm.config.persistent_storage
11
+ if options.location and read_persistent_storage() == options.location
12
+ @vm.driver.execute("storageattach", @vm.uuid, "--storagectl", "SATA Controller", "--port", "1", "--type", "hdd", "--medium", "none")
13
+ env[:ui].info "Detach Persistent Storage #{options.location} (Size: #{options.size}MB)"
14
+ end
15
+
16
+ @app.call(env)
17
+ end
18
+
19
+ def read_persistent_storage
20
+ info = @vm.driver.execute("showvminfo", @vm.uuid, "--machinereadable", :retryable => true)
21
+ info.split("\n").each do |line|
22
+ return $1.to_s if line =~ /^"SATA Controller-1-0"="(.+?)"$/
23
+ end
24
+
25
+ nil
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module VagrantPersistentStorage
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,4 @@
1
+ # This file is automatically loaded by Vagrant to load any
2
+ # plugins. This file kicks off this plugin.
3
+
4
+ require 'vagrant-persistent-storage'
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant-persistent-storage/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "vagrant-persistent-storage"
8
+ gem.version = VagrantPersistentStorage::VERSION
9
+ gem.authors = ["Sebastian Kusnier"]
10
+ gem.email = ["sebastian@kusnier.net"]
11
+ gem.description = "A Vagrant plugin that creates a persistent storage and attaches it to guest machine."
12
+ gem.summary = gem.description
13
+ gem.homepage = "https://github.com/kusnier/vagrant-persistent-storage"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'vagrant'
21
+
22
+ gem.add_development_dependency 'rake'
23
+ gem.add_development_dependency 'rspec'
24
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-persistent-storage
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Sebastian Kusnier
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-12-04 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: vagrant
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rake
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :development
61
+ version_requirements: *id003
62
+ description: A Vagrant plugin that creates a persistent storage and attaches it to guest machine.
63
+ email:
64
+ - sebastian@kusnier.net
65
+ executables: []
66
+
67
+ extensions: []
68
+
69
+ extra_rdoc_files: []
70
+
71
+ files:
72
+ - .gitignore
73
+ - Gemfile
74
+ - README.md
75
+ - lib/vagrant-persistent-storage.rb
76
+ - lib/vagrant-persistent-storage/config.rb
77
+ - lib/vagrant-persistent-storage/middleware.rb
78
+ - lib/vagrant-persistent-storage/middleware/attachpersistentstorage.rb
79
+ - lib/vagrant-persistent-storage/middleware/detachpersistentstorage.rb
80
+ - lib/vagrant-persistent-storage/version.rb
81
+ - lib/vagrant_init.rb
82
+ - vagrant-persistent-storage.gemspec
83
+ homepage: https://github.com/kusnier/vagrant-persistent-storage
84
+ licenses: []
85
+
86
+ post_install_message:
87
+ rdoc_options: []
88
+
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ requirements: []
110
+
111
+ rubyforge_project:
112
+ rubygems_version: 1.8.24
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: A Vagrant plugin that creates a persistent storage and attaches it to guest machine.
116
+ test_files: []
117
+