vagrant_bootstrap 0.1.10 → 0.1.11

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.
@@ -1,12 +1,12 @@
1
1
  require 'vagrant_bootstrap'
2
2
  require 'vagrant_bootstrap/bootstrap'
3
+ require 'vagrant_bootstrap/tap_bridge'
3
4
  require 'trollop'
4
5
  require 'ostruct'
5
6
 
6
7
  module VagrantBootstrap
7
8
  class CLI
8
9
 
9
- DEFAULT_BRIDGE = 'br0'
10
10
  DEFAULT_TEMPLATE_FILE = 'default.erb'
11
11
 
12
12
  BANNER = <<-EOS
@@ -25,7 +25,7 @@ hostname of the VM, e.g. 'vagrant_bootstrap taco' will yield a directory and hos
25
25
  trollopts = Trollop::options do
26
26
  version VagrantBootstrap::VERSION
27
27
  banner BANNER % {:name => VagrantBootstrap.vm_name('taco')}
28
- opt :bridge, 'The bridge to attach the VM to', :default => DEFAULT_BRIDGE
28
+ opt :bridge, 'The bridge to attach the VM to', :default => TapBridge.new.iface
29
29
  opt :quiet, "Don't output anything unless there's a problem", :default => false
30
30
  opt :verbose, "More verbose output", :default => false
31
31
  opt :template_file, 'Specify a different template file', :type => String
@@ -36,7 +36,7 @@ hostname of the VM, e.g. 'vagrant_bootstrap taco' will yield a directory and hos
36
36
  opts.name = VagrantBootstrap.vm_name(ARGV[0])
37
37
  opts.template_file = DEFAULT_TEMPLATE_FILE if opts.template_file.nil?
38
38
 
39
- puts "Your vagrant is called #{opts.name}" unless opts.quiet
39
+ puts "Your vagrant is called #{opts.name} and your adapter is #{opts.bridge}" unless opts.quiet
40
40
  VagrantBootstrap::Bootstrap.new opts
41
41
  end
42
42
  end
@@ -0,0 +1,54 @@
1
+ module VagrantBootstrap
2
+ class TapBridge
3
+
4
+ BRIDGE = 'br0'
5
+
6
+ def me
7
+ @me ||= `whoami`.strip
8
+ end
9
+
10
+ def iface
11
+ @iface ||= "tap-#{me}"
12
+ end
13
+
14
+ def iface_exists?
15
+ `ip tuntap|grep "#{iface}" 2>/dev/null`
16
+ $?.exitstatus == 0
17
+ end
18
+
19
+ def create_iface
20
+ `sudo ip tuntap add mode tap user #{me} #{iface}`
21
+ end
22
+
23
+ def bridge_exists?
24
+ `brctl show #{BRIDGE} 2>/dev/null | grep "No such device" 2>/dev/null`
25
+ $? == 1
26
+ end
27
+
28
+ def create_bridge
29
+ `sudo brctl addbr #{BRIDGE}`
30
+ `sudo ip link set #{BRIDGE} up`
31
+ end
32
+
33
+ def bridge_configured?
34
+ `brctl show #{BRIDGE} 2>/dev/null | grep #{iface} 2>/dev/null`
35
+ $?.exitstatus == 0
36
+ end
37
+
38
+ def link_up(link)
39
+ `sudo ip link set #{link} up`
40
+ end
41
+
42
+ def configure_bridge
43
+ create_bridge unless bridge_exists?
44
+ `sudo brctl addif #{BRIDGE} #{iface}`
45
+ link_up BRIDGE
46
+ link_up iface
47
+ end
48
+
49
+ def initialize
50
+ create_iface unless iface_exists?
51
+ configure_bridge unless bridge_configured?
52
+ end
53
+ end
54
+ end
@@ -1,3 +1,3 @@
1
1
  module VagrantBootstrap
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.11"
3
3
  end
@@ -15,4 +15,5 @@ Gem::Specification.new do |gem|
15
15
  gem.version = VagrantBootstrap::VERSION
16
16
 
17
17
  gem.add_dependency 'trollop'
18
+ gem.add_dependency 'vagrant'
18
19
  end
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.1.10
4
+ version: 0.1.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-18 00:00:00.000000000 Z
12
+ date: 2012-08-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: trollop
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: vagrant
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  description: Easily generate a Vagrantfile in a namespaced directory
31
47
  email:
32
48
  - justin.force@gmail.com
@@ -44,6 +60,7 @@ files:
44
60
  - lib/vagrant_bootstrap.rb
45
61
  - lib/vagrant_bootstrap/bootstrap.rb
46
62
  - lib/vagrant_bootstrap/cli.rb
63
+ - lib/vagrant_bootstrap/tap_bridge.rb
47
64
  - lib/vagrant_bootstrap/version.rb
48
65
  - templates/default.erb
49
66
  - vagrant_bootstrap.gemspec