aws-tools 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/aws_manager.rb +55 -35
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe9c961919c43463f06cc1889bfd5917100ae167
|
4
|
+
data.tar.gz: 1c5cb8dd18202554e8ed82c103e70d1ceb2d38eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7cbf2c410b658c8baf08c4b536471dce71672fdbfaf8da4691086583b9c83fbdada17b7e381b62e956b5dc665bf41eb4d37a5f46386271d25e139b141ec659a
|
7
|
+
data.tar.gz: 48a385a11f632b8cfa5b74079d2afc26083f3ac1b2b8aea65e8ed8f3a936092b19f11d879a235d81e094bc30046e09513dfdc1e48693ccce232717ea4c09a0e9
|
data/bin/aws_manager.rb
CHANGED
@@ -43,7 +43,7 @@ def locate_instance_choice(instances, instance_id, options={})
|
|
43
43
|
puts "There are no instances matching criteria"
|
44
44
|
return nil
|
45
45
|
elsif instances.length == 1
|
46
|
-
instances
|
46
|
+
instances
|
47
47
|
else
|
48
48
|
if !instance_id.nil?
|
49
49
|
instance = nil
|
@@ -62,22 +62,24 @@ def locate_instance_choice(instances, instance_id, options={})
|
|
62
62
|
instance = instances[instance_id.to_i]
|
63
63
|
end
|
64
64
|
end
|
65
|
-
return instance
|
65
|
+
return [instance]
|
66
66
|
else
|
67
67
|
if selection_filter == :first
|
68
|
-
return instances[0]
|
68
|
+
return [instances[0]]
|
69
69
|
elsif selection_filter == :oldest
|
70
70
|
oldest = instances[0]
|
71
71
|
instances.each do |i|
|
72
72
|
oldest = i if i._instance[:launch_time] < oldest._instance[:launch_time]
|
73
73
|
end
|
74
|
-
return oldest
|
74
|
+
return [oldest]
|
75
75
|
elsif selection_filter == :newest
|
76
76
|
newest = instances[0]
|
77
77
|
instances.each do |i|
|
78
78
|
newest = i if i._instance[:launch_time] > newest._instance[:launch_time]
|
79
79
|
end
|
80
|
-
return newest
|
80
|
+
return [newest]
|
81
|
+
elsif selection_filter == :all
|
82
|
+
return instances
|
81
83
|
else
|
82
84
|
puts "Error, there are multiple instances that match these tags. Please choose one:"
|
83
85
|
puts "index: private_ip / public_ip / instance_id / launch_time"
|
@@ -85,7 +87,7 @@ def locate_instance_choice(instances, instance_id, options={})
|
|
85
87
|
puts "#{i}: #{instances[i]._instance[:private_ip_address]} / #{instances[i]._instance[:public_ip_address]} / #{instances[i]._instance[:instance_id]} / #{instances[i]._instance[:launch_time]}"
|
86
88
|
end
|
87
89
|
ans = STDIN.gets.chomp().to_i
|
88
|
-
return instances[ans]
|
90
|
+
return [instances[ans]]
|
89
91
|
end
|
90
92
|
end
|
91
93
|
nil
|
@@ -95,14 +97,14 @@ end
|
|
95
97
|
def syntax
|
96
98
|
puts "Syntax:"
|
97
99
|
puts " EC2 Instance commands:"
|
98
|
-
puts " aws_manager.rb --region region run_instance <instance template file> "
|
100
|
+
puts " aws_manager.rb --region region [--max n] run_instance <instance template file> "
|
99
101
|
puts " aws_manager.rb --region region [--mount volume:device] run_instance <instance template file> "
|
100
|
-
puts " aws_manager.rb --region region [--environment environment] [--purpose purpose] [--choose first|oldest|newest] connect [id]"
|
101
|
-
puts " aws_manager.rb --region region [--environment environment] [--purpose purpose] [--choose first|oldest|newest] start [id]"
|
102
|
-
puts " aws_manager.rb --region region [--environment environment] [--purpose purpose] [--choose first|oldest|newest] [--keep-one] stop [id]"
|
103
|
-
puts " aws_manager.rb --region region [--environment environment] [--purpose purpose] [--choose first|oldest|newest] get_instance_status [id]"
|
104
|
-
puts " aws_manager.rb --region region [--environment environment] [--purpose purpose] [--choose first|oldest|newest] get_instance_ip [id]"
|
105
|
-
puts " aws_manager.rb --region region [--environment environment] [--purpose purpose] [--choose first|oldest|newest] [--keep-one] terminate_instance [id]"
|
102
|
+
puts " aws_manager.rb --region region [--environment environment] [--purpose purpose] [--choose first|oldest|newest|all] connect [id]"
|
103
|
+
puts " aws_manager.rb --region region [--environment environment] [--purpose purpose] [--choose first|oldest|newest|all] start [id]"
|
104
|
+
puts " aws_manager.rb --region region [--environment environment] [--purpose purpose] [--choose first|oldest|newest|all] [--keep-one] stop [id]"
|
105
|
+
puts " aws_manager.rb --region region [--environment environment] [--purpose purpose] [--choose first|oldest|newest|all] get_instance_status [id]"
|
106
|
+
puts " aws_manager.rb --region region [--environment environment] [--purpose purpose] [--choose first|oldest|newest|all] get_instance_ip [id]"
|
107
|
+
puts " aws_manager.rb --region region [--environment environment] [--purpose purpose] [--choose first|oldest|newest|all ] [--keep-one] terminate_instance [id]"
|
106
108
|
puts " CW commands:"
|
107
109
|
puts " aws_manager.rb --region region put_cw_metric csv_metric"
|
108
110
|
puts " S3 commands:"
|
@@ -130,7 +132,7 @@ def syntax
|
|
130
132
|
end
|
131
133
|
def main
|
132
134
|
syntax if ARGV.length <= 0
|
133
|
-
params = ARGV.getopts("hr:e:p:fkc:m:", "choose:", "mount:", "keep-one", "help", "region:", "environment:", "purpose:")
|
135
|
+
params = ARGV.getopts("hr:e:p:fkc:m:", "choose:", "max:", "mount:", "keep-one", "help", "region:", "environment:", "purpose:")
|
134
136
|
syntax if params['h'] or params['help']
|
135
137
|
purpose = params['p'] || params['purpose']
|
136
138
|
environment = params['e'] || params['environment']
|
@@ -138,8 +140,9 @@ def main
|
|
138
140
|
keep_one = params['k'] || params['keep-one']
|
139
141
|
selection_criteria = params['c'] || params['choose']
|
140
142
|
mount = params['m'] || params['mount']
|
143
|
+
max = params['x'] || params['max']
|
141
144
|
selection_criteria = selection_criteria.downcase.to_sym if selection_criteria
|
142
|
-
syntax if selection_criteria and !([:first,:oldest, :newest].include?(selection_criteria))
|
145
|
+
syntax if selection_criteria and !([:first,:oldest, :newest, :all].include?(selection_criteria))
|
143
146
|
syntax if ARGV.length <= 0
|
144
147
|
command = ARGV.shift
|
145
148
|
save_cl = ARGV.dup
|
@@ -156,14 +159,20 @@ def main
|
|
156
159
|
puts "Error, there are less than 2 instances, and keep_one flag set. Exiting."
|
157
160
|
exit
|
158
161
|
end
|
159
|
-
|
160
|
-
instance
|
162
|
+
instances = locate_instance_choice(filter_instances(region.find_instances({environment: environment, purpose: purpose }), ['running']),name, {:selection_filter => selection_criteria})
|
163
|
+
instances.each do |instance|
|
164
|
+
instance.stop(wait=true)
|
165
|
+
end if instances and instances.length > 0
|
161
166
|
elsif command == 'start'
|
162
|
-
|
163
|
-
instance
|
167
|
+
instances = locate_instance_choice(filter_instances(region.find_instances({environment: environment, purpose: purpose }), ['stopped']),name, {:selection_filter => selection_criteria})
|
168
|
+
instances.each do |instance|
|
169
|
+
instance.start(wait=true)
|
170
|
+
end if instances and instances.length > 0
|
164
171
|
elsif command == 'connect'
|
165
|
-
|
166
|
-
instance
|
172
|
+
instances = locate_instance_choice(filter_instances(region.find_instances({environment: environment, purpose: purpose }), ['running']),name, {:selection_filter => selection_criteria})
|
173
|
+
instances.each do |instance|
|
174
|
+
instance.connect
|
175
|
+
end if instances and instances.length > 0
|
167
176
|
elsif command == 'create_db'
|
168
177
|
options = YAML::load File.read(name) if File.exists? name
|
169
178
|
instance = region.create_db_instance(options)
|
@@ -180,11 +189,15 @@ def main
|
|
180
189
|
instances = region.find_db_instances({:environment => environment, :purpose => purpose, :instance_id => name})
|
181
190
|
puts instances[0].status
|
182
191
|
elsif command == 'get_instance_status'
|
183
|
-
|
184
|
-
|
192
|
+
instances = locate_instance_choice(filter_instances(region.find_instances({environment: environment, purpose: purpose }), []), name, {:selection_filter => selection_criteria})
|
193
|
+
instances.each do |instance|
|
194
|
+
puts instance.state
|
195
|
+
end if instances and instances.length > 0
|
185
196
|
elsif command == 'get_instance_ip'
|
186
|
-
|
187
|
-
|
197
|
+
instances = locate_instance_choice(filter_instances(region.find_instances({environment: environment, purpose: purpose }), []), name, {:selection_filter => selection_criteria})
|
198
|
+
instances.each do |instance|
|
199
|
+
puts instance.public_ip
|
200
|
+
end if instances and instances.length > 0
|
188
201
|
elsif command == 'purge_db_snapshots'
|
189
202
|
instances = region.find_db_instances({:environment => environment, :purpose => purpose, :instance_id => name})
|
190
203
|
instances[0].purge_db_snapshots
|
@@ -205,22 +218,29 @@ def main
|
|
205
218
|
exit
|
206
219
|
end
|
207
220
|
image_options = YAML.load(ERB.new(File.read(instance_template)).result)
|
208
|
-
|
209
|
-
if
|
210
|
-
|
211
|
-
|
221
|
+
ninstances = filter_instances(region.find_instances({environment: image_options[:tags][:environment], purpose: image_options[:tags][:purpose] }), ['running', 'starting', 'pending']).length
|
222
|
+
if max and max.to_i > ninstances
|
223
|
+
instance = region.create_instance(image_options)
|
224
|
+
if mount
|
225
|
+
(vol,dev) = mount.split(":")
|
226
|
+
instance.mount(vol, dev)
|
227
|
+
end
|
228
|
+
else
|
229
|
+
puts "Maximum number of instances already established: #{ninstances}"
|
212
230
|
end
|
213
231
|
elsif command == 'terminate_instance'
|
214
232
|
if keep_one and filter_instances(region.find_instances({environment: environment, purpose: purpose }), ['running']).length < 2
|
215
233
|
puts "There are less than 2 instances, and keep_one flag set. Exiting."
|
216
234
|
exit
|
217
235
|
end
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
236
|
+
instances = locate_instance_choice(filter_instances(region.find_instances({environment: environment, purpose: purpose }), []), name, {:selection_filter => selection_criteria})
|
237
|
+
instances.each do |instance|
|
238
|
+
if instance.nil?
|
239
|
+
puts "No instances matching criteria found #{{environment: environment, purpose: purpose, selection_filter: selection_criteria}.inspect}"
|
240
|
+
else
|
241
|
+
instance.terminate
|
242
|
+
end
|
243
|
+
end if instances and instances.length > 0
|
224
244
|
elsif command == 'sns'
|
225
245
|
instance = region.create_sns_instance
|
226
246
|
instance.publish save_cl[0], save_cl[1]
|