forked from kusnier/vagrant-persistent-storage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fcb0e14
Showing
10 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in vagrant-persistent-storage.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Vagrant::Persistent-Storage | ||
|
||
|
||
A Vagrant plugin that creates a persistent storage and attaches it to guest machine. | ||
|
||
## Installation | ||
|
||
gem 'vagrant-persistent-storage' | ||
|
||
And then execute: | ||
|
||
$ bundle | ||
|
||
Or install it yourself as: | ||
|
||
$ gem install vagrant-persistent-storage | ||
|
||
## Usage | ||
|
||
After installing you can set the location and size of the persistent storage. | ||
|
||
The following options will create a persistent storage with 5000 MB: | ||
```ruby | ||
config.persistent_storage.location = "~/development/sourcehdd.vdi" | ||
config.persistent_storage.size = 5000 | ||
``` | ||
|
||
Every `vagrant up` will attach this file as hard disk to the guest machine. | ||
An `vagrant destory` will detach the storage to avoid deletion of the storage by vagrant. | ||
A `vagrant destory` generally destroys all attached drives. See [VBoxMange unregistervm --delete option][vboxmanage_delete]. | ||
|
||
## TODO | ||
|
||
* There's Always Something to Do | ||
|
||
|
||
[vboxmanage_delete]: http://www.virtualbox.org/manual/ch08.html#vboxmanage-registervm "VBoxManage registervm / unregistervm" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'vagrant' | ||
require 'vagrant/action/builder' | ||
require 'vagrant-persistent-storage/config' | ||
require 'vagrant-persistent-storage/middleware' | ||
require 'vagrant-persistent-storage/version' | ||
|
||
Vagrant.config_keys.register(:persistent_storage) { VagrantPersistentStorage::Config } | ||
Vagrant.actions[:start].insert_after(Vagrant::Action::VM::ShareFolders, VagrantPersistentStorage::AttachPersistentStorage) | ||
Vagrant.actions[:destroy].insert_after(Vagrant::Action::VM::PruneNFSExports, VagrantPersistentStorage::DetachPersistentStorage) | ||
|
||
# Add our custom translations to the load path | ||
#I18n.load_path << File.expand_path("../../locales/en.yml", __FILE__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module VagrantPersistentStorage | ||
class Config < Vagrant::Config::Base | ||
attr_accessor :location | ||
attr_accessor :size | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Dir[File.dirname(__FILE__) + '/middleware/**/*.rb'].each do |file| | ||
require file | ||
end |
27 changes: 27 additions & 0 deletions
27
lib/vagrant-persistent-storage/middleware/attachpersistentstorage.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module VagrantPersistentStorage | ||
class AttachPersistentStorage | ||
def initialize(app, env) | ||
@app = app | ||
@env = env | ||
@vm = env[:vm] | ||
end | ||
|
||
def call(env) | ||
options = @vm.config.persistent_storage | ||
if !options.location ^ !options.size | ||
env[:ui].error "Attach Persistent Storage failed. Location and size must be filled out." | ||
else | ||
|
||
if !File.exists?(options.location) | ||
@vm.config.vm.customize ["createhd", "--filename", options.location, "--size", options.size] | ||
env[:ui].success "Create Persistent Storage." | ||
end | ||
@vm.config.vm.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", 1, "--type", "hdd", "--medium", options.location] | ||
|
||
env[:ui].info "Attach Persistent Storage #{options.location} (Size: #{options.size}MB)" | ||
end | ||
|
||
@app.call(env) | ||
end | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
lib/vagrant-persistent-storage/middleware/detachpersistentstorage.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module VagrantPersistentStorage | ||
class DetachPersistentStorage | ||
def initialize(app, env) | ||
@app = app | ||
@env = env | ||
@vm = env[:vm] | ||
end | ||
|
||
def call(env) | ||
options = @vm.config.persistent_storage | ||
if options.location and read_persistent_storage() == options.location | ||
@vm.driver.execute("storageattach", @vm.uuid, "--storagectl", "SATA Controller", "--port", "1", "--type", "hdd", "--medium", "none") | ||
env[:ui].info "Detach Persistent Storage #{options.location} (Size: #{options.size}MB)" | ||
end | ||
|
||
@app.call(env) | ||
end | ||
|
||
def read_persistent_storage | ||
info = @vm.driver.execute("showvminfo", @vm.uuid, "--machinereadable", :retryable => true) | ||
info.split("\n").each do |line| | ||
return $1.to_s if line =~ /^"SATA Controller-1-0"="(.+?)"$/ | ||
end | ||
|
||
nil | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module VagrantPersistentStorage | ||
VERSION = "0.0.1" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# This file is automatically loaded by Vagrant to load any | ||
# plugins. This file kicks off this plugin. | ||
|
||
require 'vagrant-persistent-storage' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*- encoding: utf-8 -*- | ||
lib = File.expand_path('../lib', __FILE__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
require 'vagrant-persistent-storage/version' | ||
|
||
Gem::Specification.new do |gem| | ||
gem.name = "vagrant-persistent-storage" | ||
gem.version = VagrantPersistentStorage::VERSION | ||
gem.authors = ["Sebastian Kusnier"] | ||
gem.email = ["sebastian@kusnier.net"] | ||
gem.description = "A Vagrant plugin that creates a persistent storage and attaches it to guest machine." | ||
gem.summary = gem.description | ||
gem.homepage = "https://github.com/kusnier/vagrant-persistent-storage" | ||
|
||
gem.files = `git ls-files`.split($/) | ||
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } | ||
gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) | ||
gem.require_paths = ["lib"] | ||
|
||
gem.add_dependency 'vagrant' | ||
|
||
gem.add_development_dependency 'rake' | ||
gem.add_development_dependency 'rspec' | ||
end |