ec2launcher 1.3.12 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
+ ## 1.4.0
2
+
3
+ * When terminating an instance, delete all EBS snapshots for volumes attached to that instance.
4
+
1
5
  ## 1.3.12
2
6
 
3
- * Use run_with_backoff when searching for AMI.
7
+ * Use run_with_backoff when searching for AMI and existing hosts.
4
8
  * Fixed bug introduced by BlockDeviceBuilder refactoring.
5
9
 
6
10
  ## 1.3.11
data/bin/ec2launcher CHANGED
@@ -28,7 +28,7 @@ if opt_parser.command == "init"
28
28
  puts "Successfully created #{opt_parser.location}"
29
29
  elsif opt_parser.command =~ /^term/
30
30
  terminator = EC2Launcher::Terminator.new(opt_parser.options.directory, opt_parser.options.environ)
31
- terminator.terminate(opt_parser.hostname, opt_parser.options.access_key, opt_parser.options.secret_key)
31
+ terminator.terminate(opt_parser.hostname, opt_parser.options.access_key, opt_parser.options.secret_key, opt_parser.snapshot_removal)
32
32
  elsif opt_parser.command == "launch"
33
33
  launcher = EC2Launcher::Launcher.new
34
34
  launcher.launch(opt_parser.options)
@@ -73,6 +73,13 @@ module EC2Launcher
73
73
  @options.skip_setup = true
74
74
  end
75
75
 
76
+ opts.separator ""
77
+ opts.separator "Termination options:"
78
+
79
+ opts.on("--[no-]snapshot-removal", "Remove EBS snapshots. Defaults to TRUE.") do |removal|
80
+ @options.snapshot_removal = removal
81
+ end
82
+
76
83
  opts.separator ""
77
84
  opts.separator "Overrides:"
78
85
 
@@ -162,6 +169,8 @@ module EC2Launcher
162
169
  @options.instance_type = nil
163
170
  @options.volume_size = nil
164
171
 
172
+ @options.snapshot_removal = true
173
+
165
174
  @options.verbosity = :normal
166
175
 
167
176
  @options.directory = "./"
@@ -43,7 +43,8 @@ module EC2Launcher
43
43
  # @param[String] server_name Name of the server instance
44
44
  # @param[String] access_key Amazon IAM access key
45
45
  # @param[String] secret Amazon IAM secret key
46
- def terminate(server_name, access_key, secret)
46
+ # @param[Boolean] snapshot_removal Remove EBS snapshots for EBS volumes attached to the instance.
47
+ def terminate(server_name, access_key, secret, snapshot_removal = true)
47
48
  ##############################
48
49
  # Initialize AWS and create EC2 connection
49
50
  ##############################
@@ -71,6 +72,11 @@ module EC2Launcher
71
72
  end # memoize
72
73
 
73
74
  if instance
75
+ # Remove EBS snapshots
76
+ AWS.memoize do
77
+ remove_snapshots(ec2, instance) if snapshot_removal
78
+ end
79
+
74
80
  private_ip_address = instance.private_ip_address
75
81
 
76
82
  run_with_backoff(30, 1, "terminating instance: #{server_name} [#{instance.instance_id}]") do
@@ -91,5 +97,21 @@ module EC2Launcher
91
97
  @log.error("Unable to find instance: #{server_name}")
92
98
  end
93
99
  end
100
+
101
+ def remove_snapshots(ec2, instance)
102
+ # Find EBS volumes for instance
103
+ volumes = instance.block_device_mappings.values
104
+
105
+ # Iterate over over volumes to find snapshots
106
+ @log.info(" Searching for snapshots...")
107
+ snapshots = []
108
+ volumes.each do |vol|
109
+ volume_snaps = ec2.snapshots.filter("volume-id", vol.id)
110
+ snapshots += volume_snaps
111
+ end
112
+
113
+ @log.info(" Deleting #{snapshots.size} snapshots...")
114
+ snapshots.each {|snap| snap.delete }
115
+ end
94
116
  end
95
117
  end
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2012 Sean Laurent
3
3
  #
4
4
  module EC2Launcher
5
- VERSION = "1.3.12"
5
+ VERSION = "1.4.0"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ec2launcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.12
4
+ version: 1.4.0
5
5
  prerelease:
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: 2012-11-09 00:00:00.000000000 Z
12
+ date: 2012-11-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
@@ -147,4 +147,3 @@ summary: Tool to launch EC2 instances.
147
147
  test_files:
148
148
  - test/ec2launcher/dsl/config_parser_test.rb
149
149
  - test/test_helper.rb
150
- has_rdoc: