swa 0.4.2 → 0.4.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b8542e93e6b8679b57d7d15aa193605e3ac4a42
4
- data.tar.gz: 999743b0934388671489d25c6c3af62621427a20
3
+ metadata.gz: 6aaa1176986a7480f4aeba71a8864ce133083c20
4
+ data.tar.gz: 03b8bd838b24a235a1c1bb499b06ce0e761b6fad
5
5
  SHA512:
6
- metadata.gz: 5ef747f274c1bfa947d6aa534ef380df524cd860f1dfafe1625c3589b0d0b0d247977945a059dedcd3c2bc07db6de1e1fba88b5886c49d643b7c258b9e5e61f5
7
- data.tar.gz: 967358b2a172465734d695a5ffa8d5207980d59385bcf390870caa24641eae7943c212e489c357a10c054e74910e3325e4e88658ba79c28c538f1825edbbedd4
6
+ metadata.gz: f4d039e776472e25cdf8028ea81e420957ecc97416ee0e2ac571d4f5a3261c2bce52196cec049874e9a04a6d3d5afd4d58f9a6ddf554899d4d4a4e1aad2efe89
7
+ data.tar.gz: da52ab84256340a1b71b287831f3b5cb9153e7ff301c942a3c43ebd556a41cc0260b2e305a67a71f8546f4943160d2ed0804ccb88dbf3fc8be7d140caaf56c50
@@ -23,10 +23,24 @@ module Swa
23
23
 
24
24
  include ItemBehaviour
25
25
 
26
+ subcommand ["delete"], "Delete image and snapshots" do
27
+ def execute
28
+ image.delete
29
+ end
30
+ end
31
+
32
+ subcommand ["deregister"], "Deregister image" do
33
+ def execute
34
+ image.deregister
35
+ end
36
+ end
37
+
26
38
  private
27
39
 
28
40
  def image
29
- Swa::EC2::Image.new(ec2.image(image_id))
41
+ ec2_image = ec2.image(image_id)
42
+ signal_error "No such image '#{image_id}'" unless ec2_image.exists?
43
+ Swa::EC2::Image.new(ec2_image)
30
44
  end
31
45
 
32
46
  alias_method :item, :image
@@ -191,6 +205,12 @@ module Swa
191
205
 
192
206
  include ItemBehaviour
193
207
 
208
+ subcommand "delete", "Delete the key-pair" do
209
+ def execute
210
+ key_pair.delete
211
+ end
212
+ end
213
+
194
214
  private
195
215
 
196
216
  def key_pair
@@ -256,6 +276,12 @@ module Swa
256
276
 
257
277
  include ItemBehaviour
258
278
 
279
+ subcommand ["delete"], "Delete the snapshot" do
280
+ def execute
281
+ snapshot.delete
282
+ end
283
+ end
284
+
259
285
  private
260
286
 
261
287
  def snapshot
@@ -12,6 +12,26 @@ module Swa
12
12
  subcommand "iam", "IAM stuff", IamCommand
13
13
  subcommand "kms", "KMS stuff", KmsCommand
14
14
 
15
+ protected
16
+
17
+ RESOURCE_PREFIXES_BY_SERVICE = {
18
+ "ec2" => %w(ami i sg subnet vpc)
19
+ }
20
+
21
+ def subcommand_for_prefix(prefix)
22
+ RESOURCE_PREFIXES_BY_SERVICE.each do |subcommand, prefixes|
23
+ return subcommand if prefixes.member?(prefix)
24
+ end
25
+ end
26
+
27
+ def parse(arguments)
28
+ if arguments.first =~ /^(\w+)-/
29
+ subcommand = subcommand_for_prefix($1)
30
+ arguments = [subcommand] + arguments if subcommand
31
+ end
32
+ super(arguments)
33
+ end
34
+
15
35
  end
16
36
 
17
37
  end
data/lib/swa/ec2/image.rb CHANGED
@@ -21,6 +21,17 @@ module Swa
21
21
  end
22
22
 
23
23
  delegate :creation_date
24
+ delegate :deregister
25
+
26
+ def delete
27
+ ebs_snapshot_ids = ami.block_device_mappings.map do |mapping|
28
+ mapping.ebs.snapshot_id if mapping.ebs
29
+ end.compact
30
+ deregister
31
+ ebs_snapshot_ids.each do |snapshot_id|
32
+ ami.client.delete_snapshot(:snapshot_id => snapshot_id)
33
+ end
34
+ end
24
35
 
25
36
  private
26
37
 
@@ -16,6 +16,8 @@ module Swa
16
16
  aws_resource.name
17
17
  end
18
18
 
19
+ delegate :delete
20
+
19
21
  end
20
22
 
21
23
  end
data/lib/swa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Swa
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Williams
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-20 00:00:00.000000000 Z
11
+ date: 2016-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler