vagrant-butcher 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .idea/
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Gem Version](https://badge.fury.io/rb/vagrant-butcher.png)](http://badge.fury.io/rb/vagrant-butcher)
2
+
1
3
  # Vagrant::Butcher
2
4
 
3
5
  If you're using Vagrant with the Chef-Client provisioner, e.g. for creating cookbooks, it creates a client and a node on the Chef server. Once you destroy the VM, both the client and node will be kept on the server, which may cause problems if you fire up the same VM again.
@@ -10,7 +12,7 @@ Installation will depend on whether you're using bundler or not.
10
12
 
11
13
  ### If you're using Bundler
12
14
 
13
- Add this line to your application's Gemfile:
15
+ Add this line to your cookbook's Gemfile:
14
16
 
15
17
  gem 'vagrant-butcher'
16
18
 
@@ -22,7 +24,7 @@ And then execute:
22
24
 
23
25
  You have to install this plugin via Vagrant:
24
26
 
25
- $ vagrant gem 'vagrant-butcher'
27
+ $ vagrant gem install 'vagrant-butcher'
26
28
 
27
29
  Explanation for that is found on the [Vagrant Plugins Documentation](http://vagrantup.com/v1/docs/extending/types.html)
28
30
 
@@ -6,21 +6,33 @@ module Vagrant
6
6
  def knife_config; @knife_config || "#{ENV['HOME']}/.chef/knife.rb"; end
7
7
  end
8
8
 
9
- def cleanup_chef_server(host_name)
9
+ def cleanup_chef_server(node_name)
10
10
  chef_api = ::Chef::REST.new(::Chef::Config[:chef_server_url])
11
11
  %w(node client).each do |resource|
12
- env[:ui].info "Removing Chef #{resource} \"#{host_name}\"..."
12
+ env[:ui].info "Removing Chef #{resource} \"#{node_name}\"..."
13
13
  begin
14
- chef_api.delete_rest("#{resource}s/#{host_name}")
14
+ chef_api.delete_rest("#{resource}s/#{node_name}")
15
15
  rescue Exception => e
16
- env[:ui].warn "Could not remove #{resource} #{host_name}: #{e.message}"
16
+ env[:ui].warn "Could not remove #{resource} #{node_name}: #{e.message}"
17
17
  end
18
18
  end
19
19
  end
20
20
 
21
21
  def cleanup
22
22
  ::Chef::Config.from_file(config.knife_config)
23
- cleanup_chef_server(env[:vm].config.vm.host_name)
23
+ conf = env[:vm].config.vm
24
+
25
+ # If a node_name is given to the chef-client provisioner, use it
26
+ chef_provisioner = conf.provisioners.find { |p| p.provisioner.name == "Vagrant::Provisioners::ChefClient" }
27
+ victim = chef_provisioner.config.node_name
28
+
29
+ # If no node_name, fall back to host_name or box
30
+ if not victim then
31
+ env[:ui].info "No chef.node_name set, falling back to vm.host_name or vm.box."
32
+ victim ||= conf.host_name || conf.box
33
+ end
34
+
35
+ cleanup_chef_server(victim)
24
36
  end
25
37
  end
26
38
  end
@@ -1,5 +1,5 @@
1
1
  module Vagrant
2
2
  module Butcher
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-butcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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: 2013-01-01 00:00:00.000000000 Z
12
+ date: 2013-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: vagrant
@@ -87,4 +87,3 @@ summary: When a Vagrant VM that was spun up using Chef-Client is destroyed, it l
87
87
  behind a client and a node on the Chef server. What butcher does is to clean up
88
88
  those during the destroy operation.
89
89
  test_files: []
90
- has_rdoc: