image_builder 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/image_builder +79 -0
- data/lib/image_builder/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0421ca79ce0ab1bc492fb62634cd3299266ccf2
|
4
|
+
data.tar.gz: 024b9010de1ba6bca39d627f5a5599dc03111c47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de380363d056d213b946d2435e78d0acdd747c7086aaa072f0024e76b4e47b303029a416f9c14b04a0ac243f4abd5a985163ac5cc7b1fb38d990a461d9aab929
|
7
|
+
data.tar.gz: b190d74ea7d04a35895951d57bbf1c7d6f57346b75e92bfa382a6aee373dde92ae4e93dc22dffc2166f9d4cae52d34932e2a76bf658f68ad0692c953563c4157
|
data/bin/image_builder
CHANGED
@@ -141,6 +141,14 @@ def convert_tags(tag_opt)
|
|
141
141
|
hash
|
142
142
|
end
|
143
143
|
|
144
|
+
def find_ami_snapshot(ami_obj)
|
145
|
+
root_dev = ami_obj.root_device_name
|
146
|
+
|
147
|
+
ami_obj.block_device_mappings.each do |k, v|
|
148
|
+
return v[:snapshot_id] if root_dev.start_with? k
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
144
152
|
# NOTE: Array options are in format '--opt arg1,arg2' (comma-seperated, no space!)
|
145
153
|
Commander.configure do
|
146
154
|
program :name, prog_name
|
@@ -233,4 +241,75 @@ Commander.configure do
|
|
233
241
|
run_packer(builders, provisioners, [vagrant].compact, options.p_packer_path, options.debug)
|
234
242
|
end
|
235
243
|
end
|
244
|
+
|
245
|
+
command :tag_snapshot do |c|
|
246
|
+
c.syntax = "#{prog_name} tag_snapshot -a ami1[,ami2,...] [-r aws_region1,aws_region2,...]"
|
247
|
+
c.description = 'A command to set the name of an EBS-backed AMI snapshot to match its AMI.'
|
248
|
+
|
249
|
+
c.option '-a, --amis AMIS', Array, 'An array of AMI ID or names to operate on (REQUIRED)'
|
250
|
+
c.option '-r, --regions REGIONS', Array, 'An array of AWS regions to do the tagging on, defaults to us-east-1'
|
251
|
+
|
252
|
+
c.action do |_args, options|
|
253
|
+
options.default r_regions: ['us-east-1']
|
254
|
+
|
255
|
+
fail ArgumentError, 'Missing required -a option' if options.a_amis.nil? || options.a_amis.empty?
|
256
|
+
|
257
|
+
options.r_regions.each do |r|
|
258
|
+
cu = Cloudutil::AWS::EC2.new(region: r)
|
259
|
+
ec2 = ::AWS::EC2.new(config: cu.config(true))
|
260
|
+
|
261
|
+
options.a_amis.each do |a|
|
262
|
+
ami_obj = cu.lookup_ami(a).first # Get AWS SDK AMI objects instead of just the id
|
263
|
+
|
264
|
+
if ami_obj.nil?
|
265
|
+
puts "WARNING: AMI #{a} not found in region #{r}, skipping"
|
266
|
+
else
|
267
|
+
if ami_obj.root_device_type.eql? :ebs
|
268
|
+
# AWS SDK only allows setting a snapshot description at create time, so we can't
|
269
|
+
# add a custom description here :(
|
270
|
+
snap_id = find_ami_snapshot(ami_obj)
|
271
|
+
ami_name = ami_obj.name
|
272
|
+
ec2.snapshots[snap_id].add_tag('Name', value: ami_name)
|
273
|
+
puts "Set name for #{snap_id} (#{a}, #{r}) to #{ami_name}"
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
command :list_ami do |c|
|
282
|
+
c.syntax = "#{prog_name} list_ami -a ami1[,ami2,...] [-r aws_region1,aws_region2,...]"
|
283
|
+
c.description = 'A command to generate a JSON mapping of AMI names to AMI ids across AWS regions.'
|
284
|
+
|
285
|
+
c.option '-a, --amis AMIS', Array, 'An array of AMI ID or names to operate on (REQUIRED)'
|
286
|
+
c.option '-r, --regions REGIONS', Array, 'An array of AWS regions to do the tagging on, defaults to us-east-1'
|
287
|
+
|
288
|
+
c.action do |_args, options|
|
289
|
+
options.default r_regions: ['us-east-1']
|
290
|
+
|
291
|
+
fail ArgumentError, 'Missing required -a option' if options.a_amis.nil? || options.a_amis.empty?
|
292
|
+
|
293
|
+
ami_data = {}
|
294
|
+
|
295
|
+
options.r_regions.each do |r|
|
296
|
+
cu = Cloudutil::AWS::EC2.new(region: r)
|
297
|
+
|
298
|
+
options.a_amis.each do |a|
|
299
|
+
ami_obj = cu.lookup_ami(a).first # Get AWS SDK AMI objects instead of just the id
|
300
|
+
|
301
|
+
if ami_obj.nil?
|
302
|
+
puts "WARNING: AMI #{a} not found in region #{r}, skipping"
|
303
|
+
else
|
304
|
+
ami_name = ami_obj.name
|
305
|
+
|
306
|
+
ami_data[ami_name] = {} unless ami_data.key? ami_name
|
307
|
+
ami_data[ami_name][r] = ami_obj.id
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
puts ami_data.to_json
|
313
|
+
end
|
314
|
+
end
|
236
315
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: image_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Morris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|