vagrant_bootstrap 0.1.11 → 0.2.0
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/lib/vagrant_bootstrap/bootstrap.rb +19 -10
- data/lib/vagrant_bootstrap/commands/bootstrap.rb +44 -0
- data/lib/vagrant_bootstrap/tap_bridge.rb +28 -16
- data/lib/vagrant_bootstrap/version.rb +1 -1
- data/lib/vagrant_init.rb +4 -0
- data/vagrant_bootstrap.gemspec +3 -1
- metadata +8 -6
- data/lib/vagrant_bootstrap/cli.rb +0 -44
@@ -1,34 +1,43 @@
|
|
1
1
|
require 'erb'
|
2
2
|
require 'fileutils'
|
3
3
|
require 'ostruct'
|
4
|
+
require 'log4r'
|
4
5
|
|
5
6
|
module VagrantBootstrap
|
6
7
|
class Bootstrap
|
7
8
|
def initialize(opts)
|
8
|
-
|
9
|
+
@opts = opts
|
10
|
+
end
|
11
|
+
|
12
|
+
def setup
|
13
|
+
make_directory
|
14
|
+
render
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def make_directory
|
20
|
+
dir = @opts[:name]
|
21
|
+
FileUtils.rm_rf dir if @opts[:force]
|
9
22
|
begin
|
10
|
-
puts "Making directory #{dir}..." if opts.verbose
|
11
23
|
FileUtils.mkdir_p dir
|
12
24
|
rescue
|
13
25
|
STDERR.puts "FATAL: #{dir} already exists!"
|
14
26
|
exit false
|
15
27
|
end
|
16
|
-
render opts.template_file, "#{dir}/Vagrantfile", opts
|
17
28
|
end
|
18
29
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
file
|
30
|
+
def render
|
31
|
+
template_file = @opts[:template]
|
32
|
+
target = "#{@opts[:name]}/Vagrantfile"
|
33
|
+
file = template_path(template_file)
|
23
34
|
if file.nil?
|
24
35
|
STDERR.puts "FATAL: Couldn't find a template matching `#{template_file}'!"
|
25
36
|
exit false
|
26
37
|
end
|
27
|
-
puts "Rendering #{target} from #{file}..." if opts.verbose
|
28
38
|
template = open(file, 'r') {|f| f.read}
|
29
|
-
render = ERB.new(template).result(opts.instance_eval {binding})
|
39
|
+
render = ERB.new(template).result(OpenStruct.new(@opts).instance_eval {binding})
|
30
40
|
open(target, 'w') {|f| f.write render}
|
31
|
-
puts "Done rendering #{target}." if opts.verbose
|
32
41
|
end
|
33
42
|
|
34
43
|
def template_path(file)
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'vagrant'
|
3
|
+
require 'vagrant_bootstrap/bootstrap'
|
4
|
+
require 'vagrant_bootstrap/tap_bridge'
|
5
|
+
|
6
|
+
module VagrantBootstrap
|
7
|
+
module Commands
|
8
|
+
class Bootstrap < Vagrant::Command::Base
|
9
|
+
def execute
|
10
|
+
options = {}
|
11
|
+
|
12
|
+
opts = OptionParser.new do |o|
|
13
|
+
o.banner = 'Usage: vagrant bootstrap <name>'
|
14
|
+
o.separator ''
|
15
|
+
|
16
|
+
o.on('-b', '--bridge BRIDGE',
|
17
|
+
"Specify a bridge interface. Default is tap-#{whoami}") do |b|
|
18
|
+
options[:bridge] = b
|
19
|
+
end
|
20
|
+
|
21
|
+
o.on '-t', '--template TEMPLATE', 'Supply your own TEMPLATE' do |t|
|
22
|
+
options[:template] = t
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
argv = parse_options(opts)
|
27
|
+
return if !argv
|
28
|
+
raise Vagrant::Errors::CLIInvalidUsage, help: opts.help.chomp if argv.length < 1
|
29
|
+
|
30
|
+
options[:template] ||= 'default.erb'
|
31
|
+
options[:bridge] ||= VagrantBootstrap::TapBridge.new.iface
|
32
|
+
options[:name] = "vagrant-#{whoami}-#{argv[0].strip}"
|
33
|
+
|
34
|
+
VagrantBootstrap::Bootstrap.new(options).setup
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def whoami
|
40
|
+
@whoami ||= `whoami`.strip
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -3,16 +3,34 @@ module VagrantBootstrap
|
|
3
3
|
|
4
4
|
BRIDGE = 'br0'
|
5
5
|
|
6
|
-
def
|
7
|
-
|
6
|
+
def initialize
|
7
|
+
check_for_bins
|
8
|
+
create_iface unless iface_exists?
|
9
|
+
create_bridge unless bridge_exists?
|
10
|
+
configure_bridge unless bridge_configured?
|
8
11
|
end
|
9
12
|
|
10
13
|
def iface
|
11
14
|
@iface ||= "tap-#{me}"
|
12
15
|
end
|
13
16
|
|
17
|
+
private
|
18
|
+
|
19
|
+
def check_for_bins
|
20
|
+
%w[brctl ip grep].each do |bin|
|
21
|
+
unless $?.exitstatus == 0
|
22
|
+
STDERR.puts "Required bin #{bin} not found in PATH. Install it or fix your PATH and try again."
|
23
|
+
exit false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def me
|
29
|
+
@me ||= `whoami`.strip
|
30
|
+
end
|
31
|
+
|
14
32
|
def iface_exists?
|
15
|
-
`ip tuntap|grep "#{iface}" 2
|
33
|
+
`ip tuntap|grep "#{iface}" 2>&1 > /dev/null`
|
16
34
|
$?.exitstatus == 0
|
17
35
|
end
|
18
36
|
|
@@ -21,34 +39,28 @@ module VagrantBootstrap
|
|
21
39
|
end
|
22
40
|
|
23
41
|
def bridge_exists?
|
24
|
-
`brctl show #{BRIDGE} 2
|
25
|
-
|
42
|
+
`brctl show #{BRIDGE} 2>&1 | grep "No such device" 2>&1 > /dev/null`
|
43
|
+
$?.exitstatus != 0
|
26
44
|
end
|
27
45
|
|
28
46
|
def create_bridge
|
29
|
-
`sudo brctl addbr #{BRIDGE}`
|
30
|
-
`sudo ip link set #{BRIDGE} up`
|
47
|
+
`sudo brctl addbr #{BRIDGE} 2>&1 > /dev/null`
|
48
|
+
`sudo ip link set #{BRIDGE} up 2>&1 > /dev/null`
|
31
49
|
end
|
32
50
|
|
33
51
|
def bridge_configured?
|
34
|
-
`brctl show #{BRIDGE} 2
|
52
|
+
`brctl show #{BRIDGE} 2>&1 | grep #{iface} 2>&1 > /dev/null`
|
35
53
|
$?.exitstatus == 0
|
36
54
|
end
|
37
55
|
|
38
56
|
def link_up(link)
|
39
|
-
`sudo ip link set #{link} up`
|
57
|
+
`sudo ip link set #{link} up 2>&1 > /dev/null`
|
40
58
|
end
|
41
59
|
|
42
60
|
def configure_bridge
|
43
|
-
|
44
|
-
`sudo brctl addif #{BRIDGE} #{iface}`
|
61
|
+
`sudo brctl addif #{BRIDGE} #{iface} 2>&1 > /dev/null`
|
45
62
|
link_up BRIDGE
|
46
63
|
link_up iface
|
47
64
|
end
|
48
|
-
|
49
|
-
def initialize
|
50
|
-
create_iface unless iface_exists?
|
51
|
-
configure_bridge unless bridge_configured?
|
52
|
-
end
|
53
65
|
end
|
54
66
|
end
|
data/lib/vagrant_init.rb
ADDED
data/vagrant_bootstrap.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant_bootstrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,10 +9,10 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: vagrant
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
@@ -28,7 +28,7 @@ dependencies:
|
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: log4r
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
@@ -59,9 +59,10 @@ files:
|
|
59
59
|
- bin/vagrant_bootstrap
|
60
60
|
- lib/vagrant_bootstrap.rb
|
61
61
|
- lib/vagrant_bootstrap/bootstrap.rb
|
62
|
-
- lib/vagrant_bootstrap/
|
62
|
+
- lib/vagrant_bootstrap/commands/bootstrap.rb
|
63
63
|
- lib/vagrant_bootstrap/tap_bridge.rb
|
64
64
|
- lib/vagrant_bootstrap/version.rb
|
65
|
+
- lib/vagrant_init.rb
|
65
66
|
- templates/default.erb
|
66
67
|
- vagrant_bootstrap.gemspec
|
67
68
|
homepage: https://github.com/SmartReceipt/vagrant_bootstrap
|
@@ -82,7 +83,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
83
|
- - ! '>='
|
83
84
|
- !ruby/object:Gem::Version
|
84
85
|
version: '0'
|
85
|
-
requirements:
|
86
|
+
requirements:
|
87
|
+
- brctl binary
|
86
88
|
rubyforge_project:
|
87
89
|
rubygems_version: 1.8.24
|
88
90
|
signing_key:
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'vagrant_bootstrap'
|
2
|
-
require 'vagrant_bootstrap/bootstrap'
|
3
|
-
require 'vagrant_bootstrap/tap_bridge'
|
4
|
-
require 'trollop'
|
5
|
-
require 'ostruct'
|
6
|
-
|
7
|
-
module VagrantBootstrap
|
8
|
-
class CLI
|
9
|
-
|
10
|
-
DEFAULT_TEMPLATE_FILE = 'default.erb'
|
11
|
-
|
12
|
-
BANNER = <<-EOS
|
13
|
-
Easily generate a Vagrantfile in a namespaced directory
|
14
|
-
|
15
|
-
Usage:
|
16
|
-
vagrant_bootstrap [name] [-b adapter]
|
17
|
-
|
18
|
-
If specified, the name will be used to calculate the directory name and
|
19
|
-
hostname of the VM, e.g. 'vagrant_bootstrap taco' will yield a directory and hostname of
|
20
|
-
'%{name}')
|
21
|
-
EOS
|
22
|
-
|
23
|
-
class << self
|
24
|
-
def start
|
25
|
-
trollopts = Trollop::options do
|
26
|
-
version VagrantBootstrap::VERSION
|
27
|
-
banner BANNER % {:name => VagrantBootstrap.vm_name('taco')}
|
28
|
-
opt :bridge, 'The bridge to attach the VM to', :default => TapBridge.new.iface
|
29
|
-
opt :quiet, "Don't output anything unless there's a problem", :default => false
|
30
|
-
opt :verbose, "More verbose output", :default => false
|
31
|
-
opt :template_file, 'Specify a different template file', :type => String
|
32
|
-
end
|
33
|
-
opts = OpenStruct.new(trollopts)
|
34
|
-
|
35
|
-
# sanitize options
|
36
|
-
opts.name = VagrantBootstrap.vm_name(ARGV[0])
|
37
|
-
opts.template_file = DEFAULT_TEMPLATE_FILE if opts.template_file.nil?
|
38
|
-
|
39
|
-
puts "Your vagrant is called #{opts.name} and your adapter is #{opts.bridge}" unless opts.quiet
|
40
|
-
VagrantBootstrap::Bootstrap.new opts
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|