vagrant-prison 0.0.1
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +57 -0
- data/Rakefile +1 -0
- data/lib/vagrant/prison.rb +136 -0
- data/lib/vagrant/prison/config_proxy.rb +79 -0
- data/lib/vagrant/prison/version.rb +5 -0
- data/vagrant-prison.gemspec +21 -0
- metadata +70 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Erik Hollensbe
|
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,57 @@
|
|
1
|
+
# Vagrant::Prison
|
2
|
+
|
3
|
+
Drive vagrant configuration directly from your test suite, rakefiles, etc.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'vagrant-prison'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install vagrant-prison
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
See the documentation for Vagrant::Prison for extended usage, but here's an
|
22
|
+
example!
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
# construct a vagrant environment from the configuration and start all the
|
26
|
+
# boxes within it. Upon exiting (via ^C), destroy the boxes and the directory.
|
27
|
+
|
28
|
+
require 'vagrant/prison'
|
29
|
+
prison = Vagrant::Prison.new
|
30
|
+
|
31
|
+
prison.configure do |config|
|
32
|
+
config.vm.box = "ubuntu"
|
33
|
+
|
34
|
+
config.vm.define :test, :primary => true do |test_config|
|
35
|
+
test_config.vm.network :hostonly, "192.168.33.10"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# if you don't set :ui_class here, it still works, it just provides no output.
|
40
|
+
Vagrant::Command::Up.new(
|
41
|
+
[],
|
42
|
+
prison.construct(:ui_class => Vagrant::UI::Basic)
|
43
|
+
).execute
|
44
|
+
|
45
|
+
begin
|
46
|
+
sleep
|
47
|
+
rescue Interrupt
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
1. Fork it
|
54
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
55
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
56
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
57
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
require 'vagrant/prison/version'
|
3
|
+
require 'vagrant/prison/config_proxy'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'tempfile'
|
6
|
+
require 'erb'
|
7
|
+
|
8
|
+
Vagrant::Prison::Vagrantfile = <<-EOF
|
9
|
+
dumped_config = <%= @config.inspect %>
|
10
|
+
|
11
|
+
Vagrant::Config.run do |config|
|
12
|
+
Marshal.load(dumped_config).eval(config)
|
13
|
+
end
|
14
|
+
EOF
|
15
|
+
|
16
|
+
class Vagrant::Prison
|
17
|
+
attr_reader :dir
|
18
|
+
|
19
|
+
#
|
20
|
+
# Construct a new Vagrant sandbox. Takes two arguments: (the third should be
|
21
|
+
# avoided)
|
22
|
+
#
|
23
|
+
# * `dir` is a directory name; it will be created for you if it does not
|
24
|
+
# already exist, and if left as nil it will be created using Dir.mktmpdir.
|
25
|
+
# * if `cleanup_on_exit` is set to true, vagrant will be told to destroy the
|
26
|
+
# environment and the sandbox directory will be deleted. This occurs when
|
27
|
+
# the program exits, or when this object is garbage collected, which ever
|
28
|
+
# comes first.
|
29
|
+
#
|
30
|
+
def initialize(dir=nil, cleanup_on_exit=true, env=nil)
|
31
|
+
@dir = dir ||= Dir.mktmpdir
|
32
|
+
@initial_config = nil
|
33
|
+
@env = env
|
34
|
+
@cleanup_on_exit = cleanup_on_exit
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.cleanup(dir, env)
|
38
|
+
Vagrant::Prison.new(dir, false, env).cleanup
|
39
|
+
end
|
40
|
+
|
41
|
+
#
|
42
|
+
# Clean up the sandbox. Vagrant will be asked to destroy the environment and
|
43
|
+
# the directory will be deleted.
|
44
|
+
#
|
45
|
+
def cleanup
|
46
|
+
destroy
|
47
|
+
FileUtils.rm_r(dir)
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# Configures a Vagrantfile.
|
52
|
+
#
|
53
|
+
# You can do this two ways: either supply a string of Ruby to configure the
|
54
|
+
# object, or a block.
|
55
|
+
#
|
56
|
+
# For example:
|
57
|
+
#
|
58
|
+
# obj.configure <<-EOF
|
59
|
+
# Vagrant::Config.run do |config|
|
60
|
+
# config.vm.box = "ubuntu"
|
61
|
+
#
|
62
|
+
# config.vm.define :test, :primary => true do |test_config|
|
63
|
+
# test_config.vm.network :hostonly, "192.168.33.10"
|
64
|
+
# end
|
65
|
+
# EOF
|
66
|
+
#
|
67
|
+
# OR
|
68
|
+
#
|
69
|
+
# obj.configure do |config|
|
70
|
+
# config.vm.box = "ubuntu"
|
71
|
+
#
|
72
|
+
# config.vm.define :test, :primary => true do |test_config|
|
73
|
+
# test_config.vm.network :hostonly, "192.168.33.10"
|
74
|
+
# end
|
75
|
+
# end
|
76
|
+
#
|
77
|
+
def configure(arg=nil)
|
78
|
+
if arg
|
79
|
+
@initial_config = arg
|
80
|
+
elsif block_given?
|
81
|
+
@initial_config ||= ConfigProxy.new
|
82
|
+
yield @initial_config
|
83
|
+
else
|
84
|
+
raise "You must supply a string of configuration or a block."
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
#
|
89
|
+
# Construct the sandbox. This:
|
90
|
+
#
|
91
|
+
# * creates your directory (if necessary)
|
92
|
+
# * supplies a pre-built Vagrantfile with your configuration supplied from
|
93
|
+
# the `configure` call
|
94
|
+
# * returns a Vagrant::Environment referencing these items
|
95
|
+
# * if you set `cleanup_on_exit` in the constructor, runs `cleanup` on
|
96
|
+
# garbage collection of this object or program exit, which ever comes first.
|
97
|
+
#
|
98
|
+
def construct(env_opts={})
|
99
|
+
FileUtils.mkdir_p(dir)
|
100
|
+
|
101
|
+
to_write = if @initial_config.kind_of?(ConfigProxy)
|
102
|
+
@config = Marshal.dump(@initial_config)
|
103
|
+
ERB.new(Vagrant::Prison::Vagrantfile).result(binding)
|
104
|
+
else
|
105
|
+
@initial_config
|
106
|
+
end
|
107
|
+
|
108
|
+
File.binwrite(File.join(dir, "Vagrantfile"), to_write)
|
109
|
+
|
110
|
+
@env = Vagrant::Environment.new(env_opts.merge(:cwd => dir))
|
111
|
+
|
112
|
+
if @cleanup_on_exit
|
113
|
+
# clean up after garbage collection or if the system exits
|
114
|
+
ObjectSpace.define_finalizer(self) do
|
115
|
+
Vagrant::Prison.cleanup(dir, env)
|
116
|
+
end
|
117
|
+
|
118
|
+
obj = self # look ma, closures
|
119
|
+
|
120
|
+
at_exit do
|
121
|
+
obj.cleanup
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
return @env
|
126
|
+
end
|
127
|
+
|
128
|
+
#
|
129
|
+
# Destroy the environment. This does not delete the directory, please see
|
130
|
+
# `cleanup` for a one-shot way to orchestrate that.
|
131
|
+
#
|
132
|
+
def destroy
|
133
|
+
Dir.chdir(dir)
|
134
|
+
Vagrant::Command::Destroy.new(%w[-f], @env).execute
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
class Vagrant::Prison
|
2
|
+
# this is a sort-of proc-to-ast with certain constraints only available to
|
3
|
+
# "dsls" which configure things
|
4
|
+
#
|
5
|
+
# * blocks yielded to never care about the return value
|
6
|
+
# * blocks only yield one argument
|
7
|
+
# * it's presumed the yielded argument will be acted on through method calls
|
8
|
+
# * method chains can be re-evaluated in any order, as long as the chain is
|
9
|
+
# preserved
|
10
|
+
class ConfigProxy
|
11
|
+
def initialize
|
12
|
+
@hash = { }
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(sym, *args)
|
16
|
+
@hash[sym] ||= []
|
17
|
+
yield_proxy = ConfigProxy.new
|
18
|
+
new_proxy = ConfigProxy.new
|
19
|
+
@hash[sym].push(
|
20
|
+
{
|
21
|
+
:args => args,
|
22
|
+
:yields => yield_proxy,
|
23
|
+
:retval => new_proxy
|
24
|
+
}
|
25
|
+
)
|
26
|
+
|
27
|
+
if block_given?
|
28
|
+
yield yield_proxy
|
29
|
+
end
|
30
|
+
|
31
|
+
return new_proxy
|
32
|
+
end
|
33
|
+
|
34
|
+
def eval(object)
|
35
|
+
@hash.each do |key, values|
|
36
|
+
values.each do |value|
|
37
|
+
retval = if value[:yields].__has_statements__
|
38
|
+
object.send(key, *value[:args]) do |obj|
|
39
|
+
value[:yields].eval(obj)
|
40
|
+
end
|
41
|
+
else
|
42
|
+
object.send(key, *value[:args])
|
43
|
+
end
|
44
|
+
|
45
|
+
if value[:retval].__has_statements__
|
46
|
+
value[:retval].eval(retval)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def __has_statements__
|
53
|
+
@hash.keys.count > 0
|
54
|
+
end
|
55
|
+
|
56
|
+
def inspect(indent = 0)
|
57
|
+
ret_str = ""
|
58
|
+
do_indent = " " * indent
|
59
|
+
@hash.each do |key, values|
|
60
|
+
ret_str += do_indent + key.inspect
|
61
|
+
ret_str += do_indent + " => [\n"
|
62
|
+
values.each do |value|
|
63
|
+
ret_str += do_indent + "{\n"
|
64
|
+
if value[:args]
|
65
|
+
ret_str += do_indent + " " + :args.inspect + " => " + value[:args].inspect + "\n"
|
66
|
+
end
|
67
|
+
[:yields, :retval].each do |blah|
|
68
|
+
if value[blah].__has_statements__
|
69
|
+
ret_str += do_indent + " " + blah.inspect + " =>\n" + value[blah].inspect(indent + 3) + "\n"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
ret_str += do_indent + "}\n"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
return ret_str
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vagrant/prison/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "vagrant-prison"
|
8
|
+
gem.version = Vagrant::Prison::VERSION
|
9
|
+
gem.authors = ["Erik Hollensbe"]
|
10
|
+
gem.email = ["erik+github@hollensbe.org"]
|
11
|
+
gem.description = %q{A programmatic way to configure and sandbox Vagrant}
|
12
|
+
gem.summary = %q{A programmatic way to configure and sandbox Vagrant}
|
13
|
+
gem.homepage = ""
|
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', '~> 1.0'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-prison
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Erik Hollensbe
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: vagrant
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.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: '1.0'
|
30
|
+
description: A programmatic way to configure and sandbox Vagrant
|
31
|
+
email:
|
32
|
+
- erik+github@hollensbe.org
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- lib/vagrant/prison.rb
|
43
|
+
- lib/vagrant/prison/config_proxy.rb
|
44
|
+
- lib/vagrant/prison/version.rb
|
45
|
+
- vagrant-prison.gemspec
|
46
|
+
homepage: ''
|
47
|
+
licenses: []
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.8.24
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: A programmatic way to configure and sandbox Vagrant
|
70
|
+
test_files: []
|