/
cluster_kill.rb
84 lines (72 loc) · 3.03 KB
/
cluster_kill.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#
# Author:: Chris Howe (<howech@infochimps.com>)
# Copyright:: Copyright (c) 2011 Infochimps, Inc
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require File.expand_path('ironfan_script', File.dirname(File.realdirpath(__FILE__)))
class Chef
class Knife
class ClusterKill < Ironfan::Script
import_banner_and_options(Ironfan::Script)
option :kill_bogus,
:long => "--kill-bogus",
:description => "Kill bogus servers (ones that exist, but are not defined in the clusters file)",
:boolean => true,
:default => false
option :cloud,
:long => '--[no-]cloud',
:description => "Kill machines from cloud (default is yes, terminate machines; use --no-cloud to skip)",
:boolean => true,
:default => true
option :chef,
:long => "--[no-]chef",
:description => "Delete the chef node and client (default is yes, delete chef objects; use --no-chef to skip)",
:boolean => true,
:default => true
def relevant?(server)
server.killable?
end
# Execute every last mf'ing one of em
def perform_execution(target)
if config[:cloud]
section("Killing Cloud Computers")
target.kill :providers => :iaas
end
if config[:chef]
section("Killing Chef")
target.kill :providers => :chef
end
end
def display(target, *args, &block)
super
permanent = target.select(&:permanent?)
ui.info Formatador.display_line("servers with [red]'permanent=true'[reset] ignored: [blue]#{permanent.map(&:name).inspect}[reset]. (To kill, change 'permanent' to false, run knife cluster sync, and re-try)") unless permanent.empty?
bogus = target.select(&:bogus?)
ui.info Formatador.display_line("[red]Bogus servers detected[reset]: [blue]#{bogus.map(&:name).inspect}[reset]") unless bogus.empty?
end
def confirm_execution(target)
nodes = target.map(&:node).compact
machines = target.map(&:machine).compact
delete_message = [
(((!config[:chef]) || nodes.empty?) ? nil : "#{nodes.length} chef nodes"),
(((!config[:cloud]) || machines.empty?) ? nil : "#{machines.length} fog servers") ].compact.join(" and ")
confirm_or_exit("Are you absolutely certain that you want to delete #{delete_message}? (Type 'Yes' to confirm) ", 'Yes')
end
def prepares?
false
end
end
end
end