vagrant-chefnode 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NGZkMDRmNjg5NjgyYjVlMDk2ZDIwZTJiMzQwMTI3ZjM5OGRmYTBiYw==
5
+ data.tar.gz: !binary |-
6
+ YWM2ZmJiMjJiYjU5ZmI1YTBmZDgzZGM1Mzc3MDZmMDkxMjA1NmU1Nw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YzcwNjQyNTZhYzllYzA3ZWIxMTk1ODU4NTk5ODZjYzI4ZmNhODVlZWY4Y2Qz
10
+ ODg0YjZlYTM4NWNmOTYxYWFmYzllOThkMDU1Y2QyODc2OGRjOTExYTQwYjY4
11
+ NjQwYTU5Y2U5NmJlZWI2YzU3M2UwMjEwZDdkMWVlNGRjZWFjZjM=
12
+ data.tar.gz: !binary |-
13
+ YzIyNDZmMWRkZjQ0NzQxN2RkNTE5ZWZiZTIyZGZmODg5OWMzNzRlNDc0YWRm
14
+ MGM0ZDEwNjA5ODI1NWYyN2ZiNmIwNDVmOGUwZjFkN2U4MGM2YTVlNGYzODRi
15
+ MjUyOTQ0MDM0Y2M1ZGVjZDdjYmNhODA2MmY3ZTJiZDk0ZjRmNTU=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vagrant-chefnode.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Ryutaro YOSHIBA
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,22 @@
1
+ # vagrant-chefnode
2
+
3
+ This gemfile enables you to remove nodes and clients from Chef Server when instances are destroyed.
4
+
5
+ ## Installation
6
+
7
+ execute:
8
+
9
+ vagrant plugin install 'vagrant-chefnode'
10
+
11
+ ## Usage
12
+
13
+ You should set up "knife" command.
14
+ knife.rb has to be placed on $HOME/.chef/ .
15
+
16
+ ## Contributing
17
+
18
+ 1. Fork it
19
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
20
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
21
+ 4. Push to the branch (`git push origin my-new-feature`)
22
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # vim: set fileencoding=utf-8
3
+
4
+ require "vagrant"
5
+ require "vagrant-chefnode/command"
6
+
7
+ module VagrantChefnode
8
+ class Plugin < Vagrant.plugin("2")
9
+ name "Chefnode"
10
+ description <<-DESC
11
+ Remove nodes and clients from Chef Server
12
+ DESC
13
+
14
+ action_hook(self::ALL_ACTIONS) do |hook|
15
+ hook.after(VagrantPlugins::ProviderVirtualBox::Action::Destroy, VagrantChefnode::Command)
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,61 @@
1
+ # coding: utf-8
2
+ # vim: set fileencoding=utf-8
3
+
4
+ module VagrantChefnode
5
+ class Command
6
+
7
+ def initialize(app, env)
8
+ @app = app
9
+ @env = env
10
+ end
11
+
12
+ def call(env)
13
+ require 'chef'
14
+ require 'chef/config'
15
+ require 'chef/knife'
16
+ knife_config = File.expand_path("../../../../../../.chef/knife.rb", File.dirname(__FILE__))
17
+ ::Chef::Config.from_file(knife_config)
18
+
19
+ chef_server_url = ::Chef::Config[:chef_server_url]
20
+ defined_chef_server_url = ""
21
+
22
+ provisioners = env[:machine].config.vm.provisioners.map do |provisioner|
23
+ if provisioner.name == :chef_client then
24
+ defined_chef_server_url = provisioner.config.chef_server_url
25
+ end
26
+ end
27
+
28
+ if chef_server_url == "" || defined_chef_server_url == "" || chef_server_url != defined_chef_server_url then
29
+ @app.call(env)
30
+ return
31
+ end
32
+
33
+ node = env[:machine].config.vm.hostname
34
+ message = "Are you sure you want to remove node and client named '#{node}' from chef server ? [y/N] "
35
+ choice = env[:ui].ask(message)
36
+ if choice.upcase != "Y" then
37
+ @app.call(env)
38
+ return
39
+ end
40
+
41
+ ["client", "node"].each do |elm|
42
+ env[:ui].info "Attempting to remove #{elm} '#{node}' from chef server."
43
+ begin
44
+ ::Chef::REST.new(chef_server_url).delete_rest("#{elm}s/#{node}")
45
+ rescue Net::HTTPServerException => e
46
+ if e.message == '404 "Not Found"'
47
+ env[:ui].info "#{elm} '#{node}' not found."
48
+ else
49
+ env[:ui].error "An error occured. You will have to remove the #{elm} manually."
50
+ end
51
+ rescue Exception => e
52
+ env[:ui].error "An error occured. You will have to remove the #{elm} manually."
53
+ else
54
+ env[:ui].info "#{elm} '#{node}' successfully removed from chef server."
55
+ end
56
+ end
57
+
58
+ @app.call(env)
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,5 @@
1
+ module Vagrant
2
+ module Chefnode
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ require File.expand_path('../lib/vagrant-chefnode/version', __FILE__)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "vagrant-chefnode"
6
+ spec.version = Vagrant::Chefnode::VERSION
7
+ spec.authors = ["Ryutaro YOSHIBA"]
8
+ spec.email = ["ryuzee@gmail.com"]
9
+ spec.description = %q{Remove nodes and clients from Chef Server when instances are destroyed}
10
+ spec.summary = %q{Remove nodes and clients from Chef Server when instances are destroyed}
11
+ spec.homepage = ""
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files`.split("\n")
15
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "rake"
21
+ spec.add_dependency "chef", ">= 11.4.0"
22
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-chefnode
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Ryutaro YOSHIBA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: chef
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 11.4.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 11.4.0
55
+ description: Remove nodes and clients from Chef Server when instances are destroyed
56
+ email:
57
+ - ryuzee@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/vagrant-chefnode.rb
68
+ - lib/vagrant-chefnode/command.rb
69
+ - lib/vagrant-chefnode/version.rb
70
+ - vagrant-chefnode.gemspec
71
+ homepage: ''
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.0.1
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Remove nodes and clients from Chef Server when instances are destroyed
95
+ test_files: []