bosh_cli_plugin_aws 1.5.0.pre.1226 → 1.5.0.pre.1244
Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,8 @@ require 'aws-sdk'
|
|
2
2
|
require 'securerandom'
|
3
3
|
require_relative '../../../bosh_cli_plugin_aws'
|
4
4
|
require 'bosh_cli_plugin_aws/destroyer'
|
5
|
+
require 'bosh_cli_plugin_aws/rds_destroyer'
|
6
|
+
require 'bosh_cli_plugin_aws/vpc_destroyer'
|
5
7
|
|
6
8
|
module Bosh::Cli::Command
|
7
9
|
class AWS < Base
|
@@ -155,20 +157,23 @@ module Bosh::Cli::Command
|
|
155
157
|
usage 'aws destroy'
|
156
158
|
desc 'destroy everything in an AWS account'
|
157
159
|
def destroy(config_file = nil)
|
158
|
-
destroyer = Bosh::Aws::Destroyer.new(self)
|
159
160
|
config = load_config(config_file)
|
160
161
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
162
|
+
rds_destroyer = Bosh::Aws::RdsDestroyer.new(self, config)
|
163
|
+
vpc_destroyer = Bosh::Aws::VpcDestroyer.new(self, config)
|
164
|
+
destroyer = Bosh::Aws::Destroyer.new(self, config, rds_destroyer, vpc_destroyer)
|
165
|
+
|
166
|
+
destroyer.ensure_not_production!
|
167
|
+
destroyer.delete_all_elbs
|
168
|
+
destroyer.delete_all_ec2
|
169
|
+
destroyer.delete_all_ebs
|
170
|
+
destroyer.delete_all_rds
|
171
|
+
destroyer.delete_all_s3
|
172
|
+
destroyer.delete_all_vpcs
|
173
|
+
destroyer.delete_all_key_pairs
|
174
|
+
destroyer.delete_all_elastic_ips
|
175
|
+
destroyer.delete_all_security_groups
|
176
|
+
destroyer.delete_all_route53_records
|
172
177
|
end
|
173
178
|
|
174
179
|
private
|
@@ -178,273 +183,15 @@ module Bosh::Cli::Command
|
|
178
183
|
Bosh::Aws::S3.new(config['aws'])
|
179
184
|
end
|
180
185
|
|
181
|
-
def delete_vpc(details_file)
|
182
|
-
details = load_yaml_file details_file
|
183
|
-
|
184
|
-
ec2 = Bosh::Aws::EC2.new(details['aws'])
|
185
|
-
vpc = Bosh::Aws::VPC.find(ec2, details['vpc']['id'])
|
186
|
-
route53 = Bosh::Aws::Route53.new(details['aws'])
|
187
|
-
|
188
|
-
err("#{vpc.instances_count} instance(s) running in #{vpc.vpc_id} - delete them first") if vpc.instances_count > 0
|
189
|
-
|
190
|
-
dhcp_options = vpc.dhcp_options
|
191
|
-
|
192
|
-
Bosh::Common.retryable(sleep: aws_retry_wait_time,
|
193
|
-
tries: 120, on: [::AWS::Errors::Base]) do |tries, e|
|
194
|
-
say("unable to delete resource: #{e}") if tries > 0
|
195
|
-
vpc.delete_security_groups
|
196
|
-
vpc.delete_subnets
|
197
|
-
ec2.delete_internet_gateways(ec2.internet_gateway_ids)
|
198
|
-
vpc.delete_vpc
|
199
|
-
dhcp_options.delete
|
200
|
-
|
201
|
-
if details['key_pairs']
|
202
|
-
details['key_pairs'].each do |name|
|
203
|
-
ec2.remove_key_pair name
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
if details['elastic_ips']
|
208
|
-
details['elastic_ips'].values.each do |job|
|
209
|
-
ec2.release_elastic_ips(job['ips'])
|
210
|
-
if job['dns_record']
|
211
|
-
route53.delete_record(job['dns_record'], details['vpc']['domain'])
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
|
-
true # retryable block must yield true if we only want to retry on Exceptions
|
216
|
-
end
|
217
|
-
|
218
|
-
say 'deleted VPC and all dependencies'.make_green
|
219
|
-
end
|
220
|
-
|
221
|
-
def delete_all_vpcs(config_file)
|
222
|
-
config = load_config(config_file)
|
223
|
-
|
224
|
-
ec2 = Bosh::Aws::EC2.new(config['aws'])
|
225
|
-
vpc_ids = ec2.vpcs.map { |vpc| vpc.id }
|
226
|
-
dhcp_options = []
|
227
|
-
|
228
|
-
unless vpc_ids.empty?
|
229
|
-
say("THIS IS A VERY DESTRUCTIVE OPERATION AND IT CANNOT BE UNDONE!\n".make_red)
|
230
|
-
say("VPCs:\n\t#{vpc_ids.join("\n\t")}")
|
231
|
-
|
232
|
-
if confirmed?('Are you sure you want to delete all VPCs?')
|
233
|
-
vpc_ids.each do |vpc_id|
|
234
|
-
vpc = Bosh::Aws::VPC.find(ec2, vpc_id)
|
235
|
-
err("#{vpc.instances_count} instance(s) running in #{vpc.vpc_id} - delete them first") if vpc.instances_count > 0
|
236
|
-
|
237
|
-
dhcp_options << vpc.dhcp_options
|
238
|
-
|
239
|
-
vpc.delete_network_interfaces
|
240
|
-
vpc.delete_security_groups
|
241
|
-
ec2.delete_internet_gateways(ec2.internet_gateway_ids)
|
242
|
-
vpc.delete_subnets
|
243
|
-
vpc.delete_route_tables
|
244
|
-
vpc.delete_vpc
|
245
|
-
end
|
246
|
-
dhcp_options.uniq(&:id).map(&:delete)
|
247
|
-
end
|
248
|
-
else
|
249
|
-
say('No VPCs found')
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
def delete_all_key_pairs(config_file)
|
254
|
-
config = load_config(config_file)
|
255
|
-
ec2 = Bosh::Aws::EC2.new(config['aws'])
|
256
|
-
|
257
|
-
if confirmed?('Are you sure you want to delete all SSH Keypairs?')
|
258
|
-
say 'Deleting all key pairs...'
|
259
|
-
ec2.remove_all_key_pairs
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
def delete_all_elastic_ips(config_file)
|
264
|
-
config = load_config(config_file)
|
265
|
-
ec2 = Bosh::Aws::EC2.new(config['aws'])
|
266
|
-
|
267
|
-
if confirmed?('Are you sure you want to delete all Elastic IPs?')
|
268
|
-
say 'Releasing all elastic IPs...'
|
269
|
-
ec2.release_all_elastic_ips
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
def delete_all_s3(config_file)
|
274
|
-
config = load_config(config_file)
|
275
|
-
|
276
|
-
s3 = Bosh::Aws::S3.new(config['aws'])
|
277
|
-
bucket_names = s3.bucket_names
|
278
|
-
|
279
|
-
unless bucket_names.empty?
|
280
|
-
say("THIS IS A VERY DESTRUCTIVE OPERATION AND IT CANNOT BE UNDONE!\n".make_red)
|
281
|
-
say("Buckets:\n\t#{bucket_names.join("\n\t")}")
|
282
|
-
|
283
|
-
s3.empty if confirmed?('Are you sure you want to empty and delete all buckets?')
|
284
|
-
else
|
285
|
-
say('No S3 buckets found')
|
286
|
-
end
|
287
|
-
end
|
288
|
-
|
289
|
-
def delete_all_ec2(config_file)
|
290
|
-
config = load_config(config_file)
|
291
|
-
credentials = config['aws']
|
292
|
-
ec2 = Bosh::Aws::EC2.new(credentials)
|
293
|
-
|
294
|
-
formatted_names = ec2.instance_names.map { |id, name| "#{name} (id: #{id})" }
|
295
|
-
unless formatted_names.empty?
|
296
|
-
say("THIS IS A VERY DESTRUCTIVE OPERATION AND IT CANNOT BE UNDONE!\n".make_red)
|
297
|
-
say("Instances:\n\t#{formatted_names.join("\n\t")}")
|
298
|
-
|
299
|
-
if confirmed?('Are you sure you want to terminate all terminatable EC2 instances and their associated non-persistent EBS volumes?')
|
300
|
-
say 'Terminating instances and waiting for them to die...'
|
301
|
-
if !ec2.terminate_instances
|
302
|
-
say 'Warning: instances did not terminate yet after 100 retries'.make_red
|
303
|
-
end
|
304
|
-
end
|
305
|
-
else
|
306
|
-
say('No EC2 instances found')
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
|
-
def delete_server_certificates(config_file)
|
311
|
-
config = load_config(config_file)
|
312
|
-
credentials = config['aws']
|
313
|
-
elb = Bosh::Aws::ELB.new(credentials)
|
314
|
-
certificates = elb.server_certificate_names
|
315
|
-
|
316
|
-
if certificates.any? && confirmed?("Are you sure you want to delete all server certificates? (#{certificates.join(', ')})")
|
317
|
-
elb.delete_server_certificates
|
318
|
-
say 'Server certificates deleted.'
|
319
|
-
end
|
320
|
-
end
|
321
|
-
|
322
|
-
def delete_all_rds_dbs(config_file)
|
323
|
-
config = load_config(config_file)
|
324
|
-
credentials = config['aws']
|
325
|
-
rds = Bosh::Aws::RDS.new(credentials)
|
326
|
-
|
327
|
-
formatted_names = rds.database_names.map { |instance, db| "#{instance}\t(database_name: #{db})" }
|
328
|
-
|
329
|
-
say("THIS IS A VERY DESTRUCTIVE OPERATION AND IT CANNOT BE UNDONE!\n".make_red)
|
330
|
-
say("Database Instances:\n\t#{formatted_names.join("\n\t")}")
|
331
|
-
|
332
|
-
if confirmed?('Are you sure you want to delete all databases?')
|
333
|
-
rds.delete_databases unless formatted_names.empty?
|
334
|
-
err('not all rds instances could be deleted') unless all_rds_instances_deleted?(rds)
|
335
|
-
|
336
|
-
delete_all_rds_subnet_groups(config_file)
|
337
|
-
delete_all_rds_security_groups(config_file)
|
338
|
-
rds.delete_db_parameter_group('utf8')
|
339
|
-
end
|
340
|
-
end
|
341
|
-
|
342
|
-
def delete_all_rds_subnet_groups(config_file)
|
343
|
-
config = load_config(config_file)
|
344
|
-
credentials = config['aws']
|
345
|
-
rds = Bosh::Aws::RDS.new(credentials)
|
346
|
-
rds.delete_subnet_groups
|
347
|
-
end
|
348
|
-
|
349
|
-
def delete_all_rds_security_groups(config_file)
|
350
|
-
config = load_config(config_file)
|
351
|
-
credentials = config['aws']
|
352
|
-
rds = Bosh::Aws::RDS.new(credentials)
|
353
|
-
rds.delete_security_groups
|
354
|
-
end
|
355
|
-
|
356
|
-
def delete_all_ebs(config_file)
|
357
|
-
config = load_config(config_file)
|
358
|
-
credentials = config['aws']
|
359
|
-
ec2 = Bosh::Aws::EC2.new(credentials)
|
360
|
-
check_volume_count(config)
|
361
|
-
|
362
|
-
if ec2.volume_count > 0
|
363
|
-
say("THIS IS A VERY DESTRUCTIVE OPERATION AND IT CANNOT BE UNDONE!\n".make_red)
|
364
|
-
say("It will delete #{ec2.volume_count} EBS volume(s)")
|
365
|
-
|
366
|
-
ec2.delete_volumes if confirmed?('Are you sure you want to delete all unattached EBS volumes?')
|
367
|
-
else
|
368
|
-
say('No EBS volumes found')
|
369
|
-
end
|
370
|
-
end
|
371
|
-
|
372
|
-
def delete_all_security_groups(config_file)
|
373
|
-
config = load_config(config_file)
|
374
|
-
ec2 = Bosh::Aws::EC2.new(config['aws'])
|
375
|
-
|
376
|
-
if confirmed?('Are you sure you want to delete all security groups?')
|
377
|
-
Bosh::Common.retryable(sleep: aws_retry_wait_time,
|
378
|
-
tries: 120, on: [::AWS::EC2::Errors::InvalidGroup::InUse]) do |tries, e|
|
379
|
-
say("unable to delete security groups: #{e}") if tries > 0
|
380
|
-
ec2.delete_all_security_groups
|
381
|
-
true # retryable block must yield true if we only want to retry on Exceptions
|
382
|
-
end
|
383
|
-
end
|
384
|
-
end
|
385
|
-
|
386
|
-
def delete_all_route53_records(config_file)
|
387
|
-
config = load_config(config_file)
|
388
|
-
route53 = Bosh::Aws::Route53.new(config['aws'])
|
389
|
-
|
390
|
-
say("THIS IS A VERY DESTRUCTIVE OPERATION AND IT CANNOT BE UNDONE!\n".make_red)
|
391
|
-
|
392
|
-
omit_types = options[:omit_types] || %w[NS SOA]
|
393
|
-
if omit_types.empty?
|
394
|
-
msg = 'Are you sure you want to delete all records from Route 53?'
|
395
|
-
else
|
396
|
-
msg = "Are you sure you want to delete all but #{omit_types.join('/')} records from Route 53?"
|
397
|
-
end
|
398
|
-
|
399
|
-
route53.delete_all_records(omit_types: omit_types) if confirmed?(msg)
|
400
|
-
end
|
401
|
-
|
402
|
-
def all_rds_instances_deleted?(rds)
|
403
|
-
return true if rds.databases.count == 0
|
404
|
-
(1..120).any? do |attempt|
|
405
|
-
say 'waiting for RDS deletion...'
|
406
|
-
sleep 10
|
407
|
-
rds.databases.each do |db_instance|
|
408
|
-
begin
|
409
|
-
say " #{db_instance.db_name} #{db_instance.db_instance_status}"
|
410
|
-
rescue ::AWS::RDS::Errors::DBInstanceNotFound
|
411
|
-
# it is possible for a db to be deleted between the time the
|
412
|
-
# each returns an instance and when we print out its info
|
413
|
-
end
|
414
|
-
end
|
415
|
-
rds.databases.count == 0
|
416
|
-
end
|
417
|
-
end
|
418
|
-
|
419
|
-
def deployment_manifest_state
|
420
|
-
@output_state['deployment_manifest'] ||= {}
|
421
|
-
end
|
422
|
-
|
423
|
-
def deployment_properties
|
424
|
-
deployment_manifest_state['properties'] ||= {}
|
425
|
-
end
|
426
|
-
|
427
|
-
def flush_output_state(file_path)
|
428
|
-
File.open(file_path, 'w') { |f| f.write output_state.to_yaml }
|
429
|
-
end
|
430
|
-
|
431
|
-
def check_volume_count(config)
|
432
|
-
ec2 = Bosh::Aws::EC2.new(config['aws'])
|
433
|
-
err("#{ec2.volume_count} volume(s) present. This isn't a dev account (more than 20) please make sure you want to do this, aborting.") if ec2.volume_count > 20
|
434
|
-
end
|
435
|
-
|
436
186
|
def default_config_file
|
437
187
|
File.expand_path(File.join(
|
438
|
-
|
439
|
-
|
188
|
+
File.dirname(__FILE__), '..', '..', '..', '..', 'templates', 'aws_configuration_template.yml.erb'
|
189
|
+
))
|
440
190
|
end
|
441
191
|
|
442
192
|
def load_config(config_file=nil)
|
443
193
|
config_file ||= default_config_file
|
444
|
-
|
445
194
|
Bosh::Aws::AwsConfig.new(config_file).configuration
|
446
195
|
end
|
447
|
-
|
448
|
-
def aws_retry_wait_time; 10; end
|
449
196
|
end
|
450
197
|
end
|
@@ -1,21 +1,122 @@
|
|
1
1
|
module Bosh::Aws
|
2
2
|
class Destroyer
|
3
|
-
def initialize(ui)
|
3
|
+
def initialize(ui, config, rds_destroyer, vpc_destroyer)
|
4
4
|
@ui = ui
|
5
|
+
@credentials = config['aws']
|
6
|
+
@rds_destroyer = rds_destroyer
|
7
|
+
@vpc_destroyer = vpc_destroyer
|
5
8
|
end
|
6
9
|
|
7
|
-
def ensure_not_production!
|
8
|
-
ec2 = Bosh::Aws::EC2.new(config['aws'])
|
10
|
+
def ensure_not_production!
|
9
11
|
raise "#{ec2.instances_count} instance(s) running. This isn't a dev account (more than 20) please make sure you want to do this, aborting." if ec2.instances_count > 20
|
12
|
+
raise "#{ec2.volume_count} volume(s) present. This isn't a dev account (more than 20) please make sure you want to do this, aborting." if ec2.volume_count > 20
|
10
13
|
end
|
11
14
|
|
12
|
-
def delete_all_elbs
|
13
|
-
|
14
|
-
elb = Bosh::Aws::ELB.new(credentials)
|
15
|
+
def delete_all_elbs
|
16
|
+
elb = Bosh::Aws::ELB.new(@credentials)
|
15
17
|
elb_names = elb.names
|
16
18
|
if elb_names.any? && @ui.confirmed?("Are you sure you want to delete all ELBs (#{elb_names.join(', ')})?")
|
17
19
|
elb.delete_elbs
|
18
20
|
end
|
19
21
|
end
|
22
|
+
|
23
|
+
def delete_all_ec2
|
24
|
+
formatted_names = ec2.instance_names.map { |id, name| "#{name} (id: #{id})" }
|
25
|
+
|
26
|
+
unless formatted_names.empty?
|
27
|
+
@ui.say("THIS IS A VERY DESTRUCTIVE OPERATION AND IT CANNOT BE UNDONE!\n".make_red)
|
28
|
+
@ui.say("Instances:\n\t#{formatted_names.join("\n\t")}")
|
29
|
+
|
30
|
+
if @ui.confirmed?('Are you sure you want to terminate all terminatable EC2 instances and their associated non-persistent EBS volumes?')
|
31
|
+
@ui.say('Terminating instances and waiting for them to die...')
|
32
|
+
if !ec2.terminate_instances
|
33
|
+
@ui.say('Warning: instances did not terminate yet after 100 retries'.make_red)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
else
|
37
|
+
@ui.say('No EC2 instances found')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete_all_ebs
|
42
|
+
if ec2.volume_count > 0
|
43
|
+
@ui.say("THIS IS A VERY DESTRUCTIVE OPERATION AND IT CANNOT BE UNDONE!\n".make_red)
|
44
|
+
@ui.say("It will delete #{ec2.volume_count} EBS volume(s)")
|
45
|
+
|
46
|
+
if @ui.confirmed?('Are you sure you want to delete all unattached EBS volumes?')
|
47
|
+
ec2.delete_volumes
|
48
|
+
end
|
49
|
+
else
|
50
|
+
@ui.say('No EBS volumes found')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def delete_all_rds
|
55
|
+
@rds_destroyer.delete_all
|
56
|
+
end
|
57
|
+
|
58
|
+
def delete_all_s3
|
59
|
+
s3 = Bosh::Aws::S3.new(@credentials)
|
60
|
+
bucket_names = s3.bucket_names
|
61
|
+
|
62
|
+
unless bucket_names.empty?
|
63
|
+
@ui.say("THIS IS A VERY DESTRUCTIVE OPERATION AND IT CANNOT BE UNDONE!\n".make_red)
|
64
|
+
@ui.say("Buckets:\n\t#{bucket_names.join("\n\t")}")
|
65
|
+
s3.empty if @ui.confirmed?('Are you sure you want to empty and delete all buckets?')
|
66
|
+
else
|
67
|
+
@ui.say('No S3 buckets found')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def delete_all_vpcs
|
72
|
+
@vpc_destroyer.delete_all
|
73
|
+
end
|
74
|
+
|
75
|
+
def delete_all_key_pairs
|
76
|
+
if @ui.confirmed?('Are you sure you want to delete all SSH Keypairs?')
|
77
|
+
@ui.say('Deleting all key pairs...')
|
78
|
+
ec2.remove_all_key_pairs
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def delete_all_elastic_ips
|
83
|
+
if @ui.confirmed?('Are you sure you want to delete all Elastic IPs?')
|
84
|
+
@ui.say('Releasing all elastic IPs...')
|
85
|
+
ec2.release_all_elastic_ips
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def delete_all_security_groups(wait_time=10)
|
90
|
+
if @ui.confirmed?('Are you sure you want to delete all security groups?')
|
91
|
+
retryable = Bosh::Retryable.new(sleep: wait_time, tries: 120, on: [::AWS::EC2::Errors::InvalidGroup::InUse])
|
92
|
+
retryable.retryer do |tries, e|
|
93
|
+
@ui.say("unable to delete security groups: #{e}") if tries > 0
|
94
|
+
ec2.delete_all_security_groups
|
95
|
+
true # retryable block must yield true if we only want to retry on Exceptions
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def delete_all_route53_records
|
101
|
+
@ui.say("THIS IS A VERY DESTRUCTIVE OPERATION AND IT CANNOT BE UNDONE!\n".make_red)
|
102
|
+
|
103
|
+
omit_types = @ui.options[:omit_types] || %w(NS SOA)
|
104
|
+
if omit_types.empty?
|
105
|
+
msg = 'Are you sure you want to delete all records from Route 53?'
|
106
|
+
else
|
107
|
+
msg = "Are you sure you want to delete all but #{omit_types.join('/')} records from Route 53?"
|
108
|
+
end
|
109
|
+
|
110
|
+
if @ui.confirmed?(msg)
|
111
|
+
route53 = Bosh::Aws::Route53.new(@credentials)
|
112
|
+
route53.delete_all_records(omit_types: omit_types)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
private
|
117
|
+
|
118
|
+
def ec2
|
119
|
+
@ec2 ||= Bosh::Aws::EC2.new(@credentials)
|
120
|
+
end
|
20
121
|
end
|
21
122
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Bosh::Aws
|
2
|
+
class RdsDestroyer
|
3
|
+
def initialize(ui, config)
|
4
|
+
@ui = ui
|
5
|
+
@credentials = config['aws']
|
6
|
+
end
|
7
|
+
|
8
|
+
def delete_all
|
9
|
+
formatted_names = rds.database_names.map { |instance, db| "#{instance}\t(database_name: #{db})" }
|
10
|
+
|
11
|
+
@ui.say("THIS IS A VERY DESTRUCTIVE OPERATION AND IT CANNOT BE UNDONE!\n".make_red)
|
12
|
+
@ui.say("Database Instances:\n\t#{formatted_names.join("\n\t")}")
|
13
|
+
|
14
|
+
if @ui.confirmed?('Are you sure you want to delete all databases?')
|
15
|
+
rds.delete_databases unless formatted_names.empty?
|
16
|
+
|
17
|
+
unless all_rds_instances_deleted?
|
18
|
+
raise 'not all rds instances could be deleted'
|
19
|
+
end
|
20
|
+
|
21
|
+
rds.delete_subnet_groups
|
22
|
+
rds.delete_security_groups
|
23
|
+
rds.delete_db_parameter_group('utf8')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def all_rds_instances_deleted?
|
30
|
+
120.times do
|
31
|
+
return true if rds.databases.count == 0
|
32
|
+
|
33
|
+
@ui.say('waiting for RDS deletion...')
|
34
|
+
sleep(10)
|
35
|
+
|
36
|
+
rds.databases.each do |db_instance|
|
37
|
+
begin
|
38
|
+
@ui.say(" #{db_instance.db_name} #{db_instance.db_instance_status}")
|
39
|
+
rescue ::AWS::RDS::Errors::DBInstanceNotFound
|
40
|
+
# It is possible for a db to be deleted between the time the
|
41
|
+
# each returns an instance and when we print out its info
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
false
|
47
|
+
end
|
48
|
+
|
49
|
+
def rds
|
50
|
+
@rds ||= Bosh::Aws::RDS.new(@credentials)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Bosh::Aws
|
2
|
+
class VpcDestroyer
|
3
|
+
def initialize(ui, config)
|
4
|
+
@ui = ui
|
5
|
+
@credentials = config['aws']
|
6
|
+
end
|
7
|
+
|
8
|
+
def delete_all
|
9
|
+
vpc_ids = ec2.vpcs.map(&:id)
|
10
|
+
if vpc_ids.empty?
|
11
|
+
@ui.say('No VPCs found')
|
12
|
+
return
|
13
|
+
end
|
14
|
+
|
15
|
+
@ui.say("THIS IS A VERY DESTRUCTIVE OPERATION AND IT CANNOT BE UNDONE!\n".make_red)
|
16
|
+
@ui.say("VPCs:\n\t#{vpc_ids.join("\n\t")}")
|
17
|
+
return unless @ui.confirmed?('Are you sure you want to delete all VPCs?')
|
18
|
+
|
19
|
+
dhcp_options = []
|
20
|
+
|
21
|
+
vpc_ids.each do |vpc_id|
|
22
|
+
vpc = Bosh::Aws::VPC.find(ec2, vpc_id)
|
23
|
+
if vpc.instances_count > 0
|
24
|
+
raise "#{vpc.instances_count} instance(s) running in #{vpc.vpc_id} - delete them first"
|
25
|
+
end
|
26
|
+
|
27
|
+
dhcp_options << vpc.dhcp_options
|
28
|
+
|
29
|
+
vpc.delete_network_interfaces
|
30
|
+
vpc.delete_security_groups
|
31
|
+
ec2.delete_internet_gateways(ec2.internet_gateway_ids)
|
32
|
+
vpc.delete_subnets
|
33
|
+
vpc.delete_route_tables
|
34
|
+
vpc.delete_vpc
|
35
|
+
end
|
36
|
+
|
37
|
+
dhcp_options.uniq(&:id).map(&:delete)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def ec2
|
43
|
+
@ec2 ||= Bosh::Aws::EC2.new(@credentials)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bosh_cli_plugin_aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.0.pre.
|
4
|
+
version: 1.5.0.pre.1244
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-11-
|
12
|
+
date: 2013-11-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bosh_cli
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.5.0.pre.
|
21
|
+
version: 1.5.0.pre.1244
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.5.0.pre.
|
29
|
+
version: 1.5.0.pre.1244
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: bosh_aws_cpi
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 1.5.0.pre.
|
37
|
+
version: 1.5.0.pre.1244
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 1.5.0.pre.
|
45
|
+
version: 1.5.0.pre.1244
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: bosh_cli_plugin_micro
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -50,7 +50,7 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 1.5.0.pre.
|
53
|
+
version: 1.5.0.pre.1244
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,7 +58,7 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.5.0.pre.
|
61
|
+
version: 1.5.0.pre.1244
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: bosh-stemcell
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
requirements:
|
67
67
|
- - ~>
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 1.5.0.pre.
|
69
|
+
version: 1.5.0.pre.1244
|
70
70
|
type: :runtime
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -74,7 +74,7 @@ dependencies:
|
|
74
74
|
requirements:
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version: 1.5.0.pre.
|
77
|
+
version: 1.5.0.pre.1244
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
79
|
name: rspec-fire
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
@@ -93,7 +93,7 @@ dependencies:
|
|
93
93
|
version: '0'
|
94
94
|
description: ! 'BOSH plugin to easily create and delete an AWS VPC
|
95
95
|
|
96
|
-
|
96
|
+
1e7603'
|
97
97
|
email: support@cloudfoundry.com
|
98
98
|
executables: []
|
99
99
|
extensions: []
|
@@ -116,10 +116,12 @@ files:
|
|
116
116
|
- lib/bosh_cli_plugin_aws/migration_helper.rb
|
117
117
|
- lib/bosh_cli_plugin_aws/migrator.rb
|
118
118
|
- lib/bosh_cli_plugin_aws/rds.rb
|
119
|
+
- lib/bosh_cli_plugin_aws/rds_destroyer.rb
|
119
120
|
- lib/bosh_cli_plugin_aws/route53.rb
|
120
121
|
- lib/bosh_cli_plugin_aws/s3.rb
|
121
122
|
- lib/bosh_cli_plugin_aws/version.rb
|
122
123
|
- lib/bosh_cli_plugin_aws/vpc.rb
|
124
|
+
- lib/bosh_cli_plugin_aws/vpc_destroyer.rb
|
123
125
|
- migrations/20130412000811_create_key_pairs.rb
|
124
126
|
- migrations/20130412004642_create_vpc.rb
|
125
127
|
- migrations/20130412181302_create_route53_records.rb
|