forked from auser/poolparty
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcloud-contract
executable file
·40 lines (30 loc) · 1.07 KB
/
cloud-contract
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
#!/usr/bin/env ruby
$:.unshift(File.dirname(__FILE__) + "/../lib")
require "poolparty"
require 'git-style-binary/command'
GitStyleBinary.command do
banner <<-EOS
Usage: #{$0} #{all_options_string}
contracts the cloud by a single instance
EOS
short_desc "contracts the cloud by a single instance"
run do |command|
@loaded_clouds.each do |cld|
node_to_terminate = cld.nodes.last
# node_to_terminate.cloud = cld
puts cld.nodes.size
if cld.nodes.size - 1 < cld.minimum_instances
puts "Contracting instances by 1 in cloud #{cld.name} will lower the number of instances below specified minimum (#{cld.minimum_instances})"
next
end
msg = [
"Contracting cloud #{cld.name} (#{cld.keypair}) by 1",
"#{cld.nodes.size} running instances (#{cld.minimum_instances} - #{cld.maximum_instances})",
" node: #{node_to_terminate.public_ip}"
]
puts msg.join("\n")
node_to_terminate.terminate!
puts "#{node_to_terminate.public_ip} has been terminated"
end
end
end