knife-killer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +2 -0
- data/LICENSE +13 -0
- data/README.md +33 -0
- data/knife-killer.gemspec +15 -0
- data/lib/chef/knife/killer_execute.rb +19 -0
- data/lib/chef/knife/killer_slaughter.rb +35 -0
- data/lib/knife-killer.rb +25 -0
- data/lib/knife-killer/version.rb +3 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 50b235eede535ea5802bc9275fdd8529d64ff318
|
4
|
+
data.tar.gz: 97e65def414fca298bd14c82d1c89270645938a5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 45537f54fa7eba470c55d6113eb7ffc57829a1a303464b0431f355a6c09dc14732c916c972d303a534b49399faa02e77f2de1de862e66bbf4fcb6b8741ee9b77
|
7
|
+
data.tar.gz: f54dff0d3abef68dd1dcfb1f12199883971965c99f0ba432069dc477bec4d318ef63df82a88f54541b6800f638dda24b0b6ded8c53523ab133d32ad48e75eb50
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2014 Chris Roberts
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
## Knife Killer
|
2
|
+
|
3
|
+
Simple knife helper to fully kill nodes (including their corresponding
|
4
|
+
client data) from the chef server. It provides two commands for this:
|
5
|
+
|
6
|
+
```bash
|
7
|
+
$ knife killer execute NODE_NAME1 NODE_NAME2
|
8
|
+
```
|
9
|
+
|
10
|
+
This is used for removing instances explicitly. However, you may just want
|
11
|
+
to remove them with a search:
|
12
|
+
|
13
|
+
```bash
|
14
|
+
$ knife killer slaughter "roles:fubar"
|
15
|
+
```
|
16
|
+
|
17
|
+
Or perhaps you just want to kill things that haven't checked in for more
|
18
|
+
than 60 minutes:
|
19
|
+
|
20
|
+
```bash
|
21
|
+
$ knife killer slaughter -M 60
|
22
|
+
```
|
23
|
+
|
24
|
+
Which you can combine with the searching:
|
25
|
+
|
26
|
+
```bash
|
27
|
+
$ knife killer slaughter -M 60 "roles:fubar"
|
28
|
+
```
|
29
|
+
|
30
|
+
Pretty simple plugin just to make common process faster.
|
31
|
+
|
32
|
+
## Info
|
33
|
+
Repository: https://github.com/chrisroberts/knife-killer
|
@@ -0,0 +1,15 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) + '/lib/'
|
2
|
+
require 'knife-killer/version'
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'knife-killer'
|
5
|
+
s.version = KnifeKiller::VERSION.version
|
6
|
+
s.summary = 'Knife cleanup helper'
|
7
|
+
s.author = 'Chris Roberts'
|
8
|
+
s.email = 'code@chrisroberts.org'
|
9
|
+
s.homepage = 'http://github.com/chrisroberts/knife-killer'
|
10
|
+
s.description = 'Knife cleanup helper'
|
11
|
+
s.license = 'Apache 2.0'
|
12
|
+
s.require_path = 'lib'
|
13
|
+
s.add_dependency 'chef'
|
14
|
+
s.files = Dir['lib/**/*'] + %w(knife-killer.gemspec README.md CHANGELOG.md LICENSE)
|
15
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'knife-killer'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class KillerExecute < Knife
|
6
|
+
|
7
|
+
include KnifeKiller::Common
|
8
|
+
|
9
|
+
banner 'knife killer execute NODE_NAME[ NODE_NAME...]'
|
10
|
+
|
11
|
+
def run
|
12
|
+
name_args.each do |name|
|
13
|
+
scrub(name)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'knife-killer'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class KillerSlaughter < Knife
|
6
|
+
|
7
|
+
include KnifeKiller::Common
|
8
|
+
|
9
|
+
banner 'knife killer slaughter SEARCH'
|
10
|
+
|
11
|
+
option(:over_minutes,
|
12
|
+
:short => '-M INT',
|
13
|
+
:long => '--minutes-since-checkin INT',
|
14
|
+
:description => 'Kill all that have not checked for more than given time'
|
15
|
+
)
|
16
|
+
|
17
|
+
def run
|
18
|
+
if(config[:over_minutes])
|
19
|
+
cutoff = Time.now.to_f - (config[:over_minutes].to_i * 60)
|
20
|
+
term = "ohai_time:[0.0 TO #{cutoff}]"
|
21
|
+
end
|
22
|
+
result = Chef::Search::Query.new.search(:node, [name_args.first, term].flatten.compact.join(' AND '))
|
23
|
+
if(result.first.empty?)
|
24
|
+
warn 'No results found!'
|
25
|
+
else
|
26
|
+
confirm "Found #{result.first.size} matches. Proceed"
|
27
|
+
result.first.each do |node|
|
28
|
+
scrub(node.name)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/knife-killer.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'knife-killer/version'
|
2
|
+
|
3
|
+
module KnifeKiller
|
4
|
+
module Common
|
5
|
+
|
6
|
+
def scrub(name)
|
7
|
+
confirm "Delete node and client for #{name}"
|
8
|
+
begin
|
9
|
+
node = Chef::Node.load(name)
|
10
|
+
node.destroy
|
11
|
+
ui.info "Node #{name}: #{ui.color('deleted', :red)}"
|
12
|
+
rescue => e
|
13
|
+
ui.warn "Node #{name}: #{ui.color('FAILED!', :bold)} - #{e.class}: #{e}"
|
14
|
+
end
|
15
|
+
begin
|
16
|
+
client = Chef::ApiClient.load(name)
|
17
|
+
client.destroy
|
18
|
+
ui.info "Client #{name}: #{ui.color('deleted', :red)}"
|
19
|
+
rescue => e
|
20
|
+
ui.warn "Client #{name}: #{ui.color('FAILED!', :bold)} - #{e.class}: #{e}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knife-killer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Roberts
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: chef
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Knife cleanup helper
|
28
|
+
email: code@chrisroberts.org
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- CHANGELOG.md
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- knife-killer.gemspec
|
37
|
+
- lib/chef/knife/killer_execute.rb
|
38
|
+
- lib/chef/knife/killer_slaughter.rb
|
39
|
+
- lib/knife-killer.rb
|
40
|
+
- lib/knife-killer/version.rb
|
41
|
+
homepage: http://github.com/chrisroberts/knife-killer
|
42
|
+
licenses:
|
43
|
+
- Apache 2.0
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 2.2.2
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: Knife cleanup helper
|
65
|
+
test_files: []
|
66
|
+
has_rdoc:
|