vagrant_bootstrap 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,30 @@
1
+ require 'optparse'
2
+ require 'vagrant'
3
+ require 'chef/knife'
4
+ require 'chef/api_client'
5
+ require 'chef/node'
6
+
7
+ module VagrantBootstrap
8
+ module Action
9
+ class Destroy
10
+ def initialize(app, env)
11
+ @app = app
12
+ end
13
+
14
+ def call(env)
15
+ @client_name = env[:vm].config.keys[:vm].host_name
16
+ remove_chef_client_and_node!
17
+ end
18
+
19
+ private
20
+
21
+ def remove_chef_client_and_node!
22
+ knife = Chef::Knife.new
23
+ knife.configure_chef
24
+ knife.config[:yes] = true
25
+ knife.delete_object Chef::ApiClient, @client_name
26
+ knife.delete_object Chef::Node, @client_name
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,7 +1,6 @@
1
1
  require 'erb'
2
2
  require 'fileutils'
3
3
  require 'ostruct'
4
- require 'log4r'
5
4
 
6
5
  module VagrantBootstrap
7
6
  class Bootstrap
@@ -10,12 +9,33 @@ module VagrantBootstrap
10
9
  end
11
10
 
12
11
  def setup
12
+ puts "Setting up a Vagrant environment with"
13
+ puts
14
+ puts " directory: #{@opts[:name]}"
15
+ puts " bridge: #{@opts[:bridge]}"
16
+ puts
13
17
  make_directory
14
18
  render
19
+ full_path = File.expand_path @opts[:name]
20
+ puts HELP_TEXT % {name: @opts[:name]}
15
21
  end
16
22
 
17
23
  private
18
24
 
25
+ HELP_TEXT = <<-HELP
26
+ You're ready to go.
27
+
28
+ cd %{name}
29
+ vagrant up
30
+
31
+ When you're finished with the VM for good, remember to
32
+
33
+ cd %{name}
34
+ vagrant destroy
35
+
36
+ This also deletes the node and client from Chef.
37
+ HELP
38
+
19
39
  def make_directory
20
40
  dir = @opts[:name]
21
41
  FileUtils.rm_rf dir if @opts[:force]
@@ -14,7 +14,7 @@ module VagrantBootstrap
14
14
  o.separator ''
15
15
 
16
16
  o.on('-b', '--bridge BRIDGE',
17
- "Specify a bridge interface. Default is tap-#{whoami}") do |b|
17
+ "Specify a bridge interface. Default is tap-#{VagrantBootstrap.whoami}") do |b|
18
18
  options[:bridge] = b
19
19
  end
20
20
 
@@ -29,16 +29,10 @@ module VagrantBootstrap
29
29
 
30
30
  options[:template] ||= 'default.erb'
31
31
  options[:bridge] ||= VagrantBootstrap::TapBridge.new.iface
32
- options[:name] = "vagrant-#{whoami}-#{argv[0].strip}"
32
+ options[:name] = "vagrant-#{VagrantBootstrap.whoami}-#{argv[0].strip}"
33
33
 
34
34
  VagrantBootstrap::Bootstrap.new(options).setup
35
35
  end
36
-
37
- private
38
-
39
- def whoami
40
- @whoami ||= `whoami`.strip
41
- end
42
36
  end
43
37
  end
44
38
  end
@@ -1,3 +1,5 @@
1
+ require 'vagrant_bootstrap'
2
+
1
3
  module VagrantBootstrap
2
4
  class TapBridge
3
5
 
@@ -11,7 +13,7 @@ module VagrantBootstrap
11
13
  end
12
14
 
13
15
  def iface
14
- @iface ||= "tap-#{me}"
16
+ @iface ||= "tap-#{VagrantBootstrap.whoami}"
15
17
  end
16
18
 
17
19
  private
@@ -25,17 +27,13 @@ module VagrantBootstrap
25
27
  end
26
28
  end
27
29
 
28
- def me
29
- @me ||= `whoami`.strip
30
- end
31
-
32
30
  def iface_exists?
33
31
  `ip tuntap|grep "#{iface}" 2>&1 > /dev/null`
34
32
  $?.exitstatus == 0
35
33
  end
36
34
 
37
35
  def create_iface
38
- `sudo ip tuntap add mode tap user #{me} #{iface}`
36
+ `sudo ip tuntap add mode tap user #{VagrantBootstrap.whoami} #{iface}`
39
37
  end
40
38
 
41
39
  def bridge_exists?
@@ -1,3 +1,3 @@
1
1
  module VagrantBootstrap
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -7,5 +7,9 @@ module VagrantBootstrap
7
7
  name = "-#{name}" if name
8
8
  "vagrant-#{`whoami`.strip}#{name}"
9
9
  end
10
+
11
+ def whoami
12
+ @@whoami ||= `whoami`.strip
13
+ end
10
14
  end
11
15
  end
data/lib/vagrant_init.rb CHANGED
@@ -1,4 +1,10 @@
1
1
  require 'vagrant'
2
2
  require 'vagrant_bootstrap/commands/bootstrap'
3
+ require 'vagrant_bootstrap/action/destroy'
3
4
 
4
5
  Vagrant.commands.register(:bootstrap) { VagrantBootstrap::Commands::Bootstrap }
6
+
7
+ Vagrant.actions[:destroy].insert_after(
8
+ Vagrant::Action::VM::Destroy,
9
+ VagrantBootstrap::Action::Destroy
10
+ )
@@ -14,8 +14,10 @@ Gem::Specification.new do |gem|
14
14
  gem.require_paths = ["lib"]
15
15
  gem.version = VagrantBootstrap::VERSION
16
16
 
17
- gem.add_dependency 'vagrant'
18
- gem.add_dependency 'log4r'
17
+ gem.add_dependency 'vagrant', '~> 1.0'
18
+ gem.add_dependency 'chef', '~> 10.12'
19
19
 
20
+ gem.requirements << 'Ubuntu 10.10 or greater'
20
21
  gem.requirements << 'brctl binary'
22
+ gem.requirements << 'admin on your chef repo'
21
23
  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.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,40 +9,40 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-28 00:00:00.000000000 Z
12
+ date: 2012-08-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: vagrant
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: '1.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
29
+ version: '1.0'
30
30
  - !ruby/object:Gem::Dependency
31
- name: log4r
31
+ name: chef
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - ! '>='
35
+ - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: '0'
37
+ version: '10.12'
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ! '>='
43
+ - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: '0'
45
+ version: '10.12'
46
46
  description: Easily generate a Vagrantfile in a namespaced directory
47
47
  email:
48
48
  - justin.force@gmail.com
@@ -58,6 +58,7 @@ files:
58
58
  - Rakefile
59
59
  - bin/vagrant_bootstrap
60
60
  - lib/vagrant_bootstrap.rb
61
+ - lib/vagrant_bootstrap/action/destroy.rb
61
62
  - lib/vagrant_bootstrap/bootstrap.rb
62
63
  - lib/vagrant_bootstrap/commands/bootstrap.rb
63
64
  - lib/vagrant_bootstrap/tap_bridge.rb
@@ -84,7 +85,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
85
  - !ruby/object:Gem::Version
85
86
  version: '0'
86
87
  requirements:
88
+ - Ubuntu 10.10 or greater
87
89
  - brctl binary
90
+ - admin on your chef repo
88
91
  rubyforge_project:
89
92
  rubygems_version: 1.8.24
90
93
  signing_key: