awful 0.0.156 → 0.0.157
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/eip +7 -0
- data/lib/awful/ecr.rb +29 -25
- data/lib/awful/eip.rb +67 -0
- data/lib/awful/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99c05896c178d666894061616bd3be84723558a0
|
4
|
+
data.tar.gz: b93e53d0adbb16b05775c6d51fd2d9e6dbbc6687
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17a626a26ac67317a14dd5ba156bd9f67a2ffac41a2323cce9d9428b92bd0bad2f3d42f8cc6824e9ee537c41edd34305ca86a8df1c23b7a4d3fefe87ef379277
|
7
|
+
data.tar.gz: efa5ee2168f77efd3da46f30cf212412f6674696beafd12c1ad9484f65c10fdfeae547b0d517fb86bf8ff059435bd266f8ce9adca6709c8129f9647f9a8ed231
|
data/bin/eip
ADDED
data/lib/awful/ecr.rb
CHANGED
@@ -21,9 +21,14 @@ module Awful
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
def describe_images(repository, tag_status = nil)
|
25
|
+
paginate(:image_details) do |next_token|
|
26
|
+
ecr.describe_images(
|
27
|
+
repository_name: repository,
|
28
|
+
filter: { tag_status: tag_status },
|
29
|
+
next_token: next_token,
|
30
|
+
)
|
31
|
+
end
|
27
32
|
end
|
28
33
|
end
|
29
34
|
|
@@ -87,24 +92,22 @@ module Awful
|
|
87
92
|
end
|
88
93
|
|
89
94
|
desc 'images REPO', 'list images for repo'
|
90
|
-
method_option :long,
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
break unless next_token
|
99
|
-
end
|
100
|
-
|
101
|
-
images.output do |list|
|
95
|
+
method_option :long, aliases: '-l', type: :boolean, default: false, desc: 'Long listing'
|
96
|
+
method_option :tagged, aliases: '-t', type: :boolean, default: false, desc: 'show only tagged images'
|
97
|
+
method_option :untagged, aliases: '-u', type: :boolean, default: false, desc: 'show only untagged images'
|
98
|
+
def images(repository)
|
99
|
+
tag_status = 'TAGGED' if options[:tagged]
|
100
|
+
tag_status = 'UNTAGGED' if options[:untagged]
|
101
|
+
|
102
|
+
describe_images(repository, tag_status).output do |list|
|
102
103
|
if options[:long]
|
103
104
|
print_table list.map { |i|
|
104
|
-
|
105
|
+
tags = i.image_tags || []
|
106
|
+
size = "%.2f MiB" % (i.image_size_in_bytes/(1024*1024))
|
107
|
+
[tags.join(','), i.image_pushed_at, size, i.image_digest]
|
105
108
|
}
|
106
109
|
else
|
107
|
-
puts list.map(&:
|
110
|
+
puts list.map(&:image_tags).flatten
|
108
111
|
end
|
109
112
|
end
|
110
113
|
end
|
@@ -146,7 +149,7 @@ module Awful
|
|
146
149
|
(imgs.empty? ? false : true).output(&method(:puts))
|
147
150
|
end
|
148
151
|
|
149
|
-
desc 'reap REPO', 'reap old images for repo'
|
152
|
+
desc 'reap REPO DAYS', 'reap old images for repo'
|
150
153
|
method_option :batch, aliases: '-b', type: :numeric, default: 10, desc: 'batch size to get and delete'
|
151
154
|
method_option :dry_run, aliases: '-d', type: :boolean, default: false, desc: 'dry run, do not delete, implies verbose'
|
152
155
|
method_option :verbose, aliases: '-v', type: :boolean, default: false, desc: 'print images to be deleted'
|
@@ -157,15 +160,13 @@ module Awful
|
|
157
160
|
|
158
161
|
deleted = failures = 0
|
159
162
|
loop do
|
160
|
-
|
161
|
-
response = ecr.list_images(repository_name: repository, next_token: next_token, max_results: options[:batch])
|
163
|
+
response = ecr.describe_images(repository_name: repository, next_token: next_token, max_results: options[:batch])
|
162
164
|
|
163
|
-
|
164
|
-
|
165
|
-
date = Time.parse(parse_created(image)).utc
|
165
|
+
old_images = response.image_details.select do |image|
|
166
|
+
date = image.image_pushed_at.utc
|
166
167
|
age = ((now - date)/(24*60*60)).to_i
|
167
168
|
if age > days.to_i
|
168
|
-
puts "#{date} #{age} #{image.
|
169
|
+
puts "#{date} #{age} #{image.image_digest} #{image.image_tags}" if verbose
|
169
170
|
true
|
170
171
|
else
|
171
172
|
false
|
@@ -174,7 +175,10 @@ module Awful
|
|
174
175
|
|
175
176
|
## delete old images
|
176
177
|
unless options[:dry_run] || old_images.empty?
|
177
|
-
r = ecr.batch_delete_image(
|
178
|
+
r = ecr.batch_delete_image(
|
179
|
+
repository_name: repository,
|
180
|
+
image_ids: old_images.map { |i| {image_digest: i.image_digest} }
|
181
|
+
)
|
178
182
|
deleted += r.image_ids.count
|
179
183
|
failures += r.failures.count
|
180
184
|
end
|
data/lib/awful/eip.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
module Awful
|
2
|
+
module Short
|
3
|
+
def eip(*args)
|
4
|
+
Awful::Eip.new.invoke(*args)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class Eip < Cli
|
9
|
+
no_commands do
|
10
|
+
|
11
|
+
## get an EIP by id or public ip
|
12
|
+
def find_eip(thing)
|
13
|
+
ec2.describe_addresses.addresses.find do |eip|
|
14
|
+
(thing == eip.public_ip) || (thing == eip.allocation_id) || (thing == eip.association_id)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'ls', 'list elastic IPs'
|
20
|
+
method_option :long, aliases: '-l', type: :boolean, default: false, desc: 'long listing'
|
21
|
+
def ls
|
22
|
+
ec2.describe_addresses.addresses.output do |eips|
|
23
|
+
if options[:long]
|
24
|
+
print_table eips.map { |i|
|
25
|
+
[i.public_ip, i.allocation_id, i.instance_id, i.private_ip_address, i.domain, i.association_id, i.network_interface_id, i.network_interface_owner_id]
|
26
|
+
}.sort
|
27
|
+
else
|
28
|
+
puts eips.map(&:public_ip).sort
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'allocate', 'acquire an elastic IP'
|
34
|
+
method_option :domain, aliases: '-d', type: :string, default: 'vpc', desc: 'domain: vpc or standard (ec2 classic)'
|
35
|
+
def allocate
|
36
|
+
ec2.allocate_address(domain: options[:domain]).output do |eip|
|
37
|
+
puts eip.public_ip
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'release ID', 'release elastic IP back to pool'
|
42
|
+
def release(id)
|
43
|
+
find_eip(id).tap do |eip|
|
44
|
+
unless eip.nil?
|
45
|
+
if eip.domain == 'vpc'
|
46
|
+
ec2.release_address(allocation_id: eip.allocation_id)
|
47
|
+
else
|
48
|
+
ec2.release_address(public_ip: eip.public_ip)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
desc 'associate ID INSTANCE', 'associate EIP with an instance'
|
55
|
+
def associate(id, instance)
|
56
|
+
ec2.associate_address(
|
57
|
+
allocation_id: find_eip(id).allocation_id,
|
58
|
+
instance_id: instance
|
59
|
+
).association_id.output(&method(:puts))
|
60
|
+
end
|
61
|
+
|
62
|
+
desc 'disassociate ID', 'disassociate EIP from current instance association'
|
63
|
+
def disassociate(id)
|
64
|
+
ec2.disassociate_address(association_id: find_eip(id).association_id)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/awful/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: awful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.157
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ric Lister
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -99,6 +99,7 @@ executables:
|
|
99
99
|
- ec2
|
100
100
|
- ecr
|
101
101
|
- ecs
|
102
|
+
- eip
|
102
103
|
- elasticache
|
103
104
|
- elb
|
104
105
|
- iam
|
@@ -141,6 +142,7 @@ files:
|
|
141
142
|
- bin/ec2
|
142
143
|
- bin/ecr
|
143
144
|
- bin/ecs
|
145
|
+
- bin/eip
|
144
146
|
- bin/elasticache
|
145
147
|
- bin/elb
|
146
148
|
- bin/iam
|
@@ -181,6 +183,7 @@ files:
|
|
181
183
|
- lib/awful/ec2.rb
|
182
184
|
- lib/awful/ecr.rb
|
183
185
|
- lib/awful/ecs.rb
|
186
|
+
- lib/awful/eip.rb
|
184
187
|
- lib/awful/elasticache.rb
|
185
188
|
- lib/awful/elb.rb
|
186
189
|
- lib/awful/iam.rb
|