amirotate 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30854b7602885714e0d2426e8c4882e7eeb54d43
4
- data.tar.gz: 11ce7d825a87e78c0fb1d0cc7b60fc16da15dda2
3
+ metadata.gz: 31f16325898481501b4e535e513bc369c67a75f8
4
+ data.tar.gz: 272b8b2581529dd70d48ec3f6de7552c090f8aeb
5
5
  SHA512:
6
- metadata.gz: f770dd0e47f571dc3fda149bfd2ab3b0ed2b1bcbd53c82586341e80047e9654c9aa6a6ae7fdf460a5268aedab144d5b2183089d1258ea213dbd9a02395ef00de
7
- data.tar.gz: 1483f7506102e6febff6ece44c1b31ee9b2c88ac57e36c7e74c866968869a4cb3166e353736e12ee136412cd0e5f639ff258a6ef38f96f99a68d65af12781404
6
+ metadata.gz: fcc41546e0cebc3fe5bab319b89671901bfe298f5cf4de76ef70dccae7eb9ad7238935978063b90fda601edbd57947fcc8bbed6b8dd2a7bc71459e658bf281d5
7
+ data.tar.gz: 93a9be2cc8f9781db95e180a5a57bc2272d962ed5667d620265ae9ba5acc61d60656d94ff1ab36a2cdf386bf8e429db8a8f4d16adbd6cf3d5fa5583ba5f28458
@@ -1,5 +1,6 @@
1
1
  require "aws-sdk"
2
2
  require "time"
3
+ require "ostruct"
3
4
 
4
5
  module AMIRotate
5
6
  class Client
@@ -48,6 +49,7 @@ module AMIRotate
48
49
  end
49
50
 
50
51
  def preserve
52
+ backuped_amis = []
51
53
  instances.each do |instance|
52
54
  tag_key = "amirotate:#{@cli_options[:profile_name]}:retention_period"
53
55
  tag = instance.tags.find {|tag| tag.key == tag_key}
@@ -76,6 +78,7 @@ module AMIRotate
76
78
  ].join(" - ")
77
79
  )
78
80
 
81
+ backuped_amis << OpenStruct.new(name: name, id: image.id, tag: tag)
79
82
  image.wait_until {|image| image.state.match /available|pending/}
80
83
 
81
84
  image.create_tags(
@@ -97,6 +100,40 @@ module AMIRotate
97
100
  logger.info "Did nothing due to dry run."
98
101
  end
99
102
  end
103
+
104
+ timeout_at = Time.now + (60 * 5)
105
+ begin
106
+ backuped_amis.each do |ami|
107
+ image = @ec2.image(ami.id)
108
+ next unless image.state.match /available/
109
+
110
+ begin
111
+ image.block_device_mappings.map do |block_device|
112
+ logger.info "Tag to snapshot #{block_device.ebs.snapshot_id}"
113
+ @ec2.snapshot(block_device.ebs.snapshot_id.to_s).create_tags(
114
+ dry_run: @cli_options[:dry_run],
115
+ tags: [
116
+ {
117
+ key: ami.tag.key,
118
+ value: ami.tag.value,
119
+ },
120
+
121
+ {
122
+ key: "Name",
123
+ value: "#{ami.name}: #{block_device.device_name}"
124
+ },
125
+ ],
126
+ )
127
+ end
128
+ backuped_amis.delete(ami)
129
+ rescue Aws::EC2::Errors
130
+ next
131
+ end
132
+ end
133
+ break if backuped_amis.empty?
134
+ logger.info "To wait 1 minutes for the snapshot is created"
135
+ sleep(60)
136
+ end while Time.now < timeout_at
100
137
  end
101
138
 
102
139
  def invalidate
@@ -1,3 +1,3 @@
1
1
  module AMIRotate
2
- VERSION = "0.0.16"
2
+ VERSION = "0.0.17"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amirotate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - y13i
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-18 00:00:00.000000000 Z
11
+ date: 2015-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
180
  version: '0'
181
181
  requirements: []
182
182
  rubyforge_project:
183
- rubygems_version: 2.4.5
183
+ rubygems_version: 2.4.5.1
184
184
  signing_key:
185
185
  specification_version: 4
186
186
  summary: Back up EC2 instances by Snapshot/AMI.