Module: BigBang::KillCmd

Included in:
Universe
Defined in:
lib/bigbang/kill.rb

Instance Method Summary collapse

Instance Method Details

#kill(name) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/bigbang/kill.rb', line 58

def kill(name)
	kill_elb
	running = running_instances
	instances = universe_running_instances(running, universe_tags(name))
	addresses = get_addresses
	instances.each do |i|
		kill_dns_entry(i)
		kill_eip(i, addresses)
		kill_instance(i)
	end
end

#kill_dns_entry(instance) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bigbang/kill.rb', line 11

def kill_dns_entry(instance)
	records = provider.configured_zone.records

	records = records.find_all do |r|
		r.value == instance.ipAddress
	end
	if records.empty?
		puts "no DNS records found for ip #{instance.ipAddress}"
		return
	end

	domains = records.collect { |r| r.domain }
	confirm("Would you like to remove the following dns records?\n" +
		domains.join("\n") + "\n") do
		records.each do |r|
			puts "removing DNS #{r.domain}"
			r.destroy
		end
	end
end

#kill_eip(i, addresses) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bigbang/kill.rb', line 32

def kill_eip(i, addresses)
	addr = addresses.find { |a| a.publicIp == i.ipAddress }
		
	unless addr.nil?
		confirm("Would you like to release EIP address #{addr.publicIp} of instance #{i.instanceId}") do
			puts "disassociating address #{addr.publicIp}"
			provider.ec2.disassociate_address(:public_ip => addr.publicIp)
			
			puts "releasing address #{addr.publicIp}"
			provider.ec2.release_address(:public_ip => addr.publicIp)
		end
	end
end

#kill_elbObject



48
49
50
51
52
53
54
55
56
# File 'lib/bigbang/kill.rb', line 48

def kill_elb
	configured_elbs.each do |lb|
		confirm("Delete ELB #{lb.name}") do
			notify("deleting ELB #{lb.name}") do
				provider.elb.delete_load_balancer(:load_balancer_name => lb.name)
			end
		end
	end
end

#kill_instance(instance) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/bigbang/kill.rb', line 3

def kill_instance(instance)
	confirm("kill instance #{instance.instanceId}") do
		notify("sending termination signal to #{instance.instanceId}") do
			provider.ec2.terminate_instances(:instance_id => [instance.instanceId])
		end
	end
end