awful 0.0.14 → 0.0.15

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: 5c3c3f308afeedec0d4062123c7866216c70e7ab
4
- data.tar.gz: 7e47dafe01e7ca56f2422316c0e45c0fb04de498
3
+ metadata.gz: f08603e28f31d8ffcca5784bd8a3322f34b9518c
4
+ data.tar.gz: 8fadd7303be34019c6c362391086877fe27fbea3
5
5
  SHA512:
6
- metadata.gz: 9b56c90f105bca387670e4186395cd90abf3ccfa3b18fab280372d299253253b74651fbdd711309390bca00f1201af83860ac1f6c140de948db2ac3f503ed9ed
7
- data.tar.gz: 07fb00bdc2e4e5a702d3b74cccfd6321afb5c622ff0fd27dfd23251b3e2906ee45ef1bd354558f74a6468013de1dfc4a8282d1c80e443175e2a2389fd5021f1e
6
+ metadata.gz: ab2b585419b4153e55d4d953e49c43c8e7dabaae357ebea1e16d72e1e0e6b020f53132963925ed286f0ee326b381ffa1325fb00d4e089f40eace9e08ed6b1fbf
7
+ data.tar.gz: 452c315e6b9a805cec044fdcf538af00389ccbb0364836001222ddb82aecd2d11c897d70812c9ca1f7ac91c28351fedf2183605a9997b4eae42b94332edbaf84
data/bin/ami ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby
2
+ #-*- mode: ruby; -*-
3
+
4
+ require 'awful'
5
+ require 'awful/ami'
6
+
7
+ Awful::Ami.start(ARGV)
@@ -0,0 +1,77 @@
1
+ module Awful
2
+
3
+ class Ami < Cli
4
+ class_option :owners, aliases: '-o', default: 'self', desc: 'List images with this owner'
5
+
6
+ no_commands do
7
+ def images(options)
8
+ ec2.describe_images(owners: options[:owners].split(',')).map(&:images).flatten
9
+ end
10
+ end
11
+
12
+ desc 'ls [PATTERN]', 'list AMIs'
13
+ method_option :long, aliases: '-l', default: false, desc: 'Long listing'
14
+ def ls(name = /./)
15
+ fields = options[:long] ?
16
+ ->(i) { [ i.name, i.image_id, i.root_device_type, i.state, i.creation_date, i.tags.map{ |t| "#{t.key}=#{t.value}" }.sort.join(',') ] } :
17
+ ->(i) { [ i.image_id ] }
18
+
19
+ images(options).select do |image|
20
+ image.name.match(name)
21
+ end.map do |image|
22
+ fields.call(image)
23
+ end.tap do |list|
24
+ print_table list.sort
25
+ end
26
+ end
27
+
28
+ desc 'delete NAME', 'delete AMI'
29
+ def delete(id)
30
+ images(options).find do |image|
31
+ image.image_id.match(id)
32
+ end.tap do |ami|
33
+ if yes? "Really deregister image #{ami.name} (#{ami.image_id})?", :yellow
34
+ ec2.deregister_image(image_id: ami.image_id)
35
+ end
36
+ end
37
+ end
38
+
39
+ desc 'tags ID [KEY=VALUE]', 'tag an image, or print tags'
40
+ def tags(id, tag = nil)
41
+ ami = images(options).find do |image|
42
+ image.image_id.match(id)
43
+ end
44
+ if tag
45
+ key, value = tag.split('=')
46
+ ec2.create_tags(resources: [ami.image_id], tags: [{key: key, value: value}])
47
+ else
48
+ puts ami.tags.map { |t| "#{t[:key]}=#{t[:value]}" }
49
+ end
50
+ end
51
+
52
+ # desc 'copy ID REGION', 'copy image from given REGION to current region'
53
+ # def copy(id, region)
54
+ # current_region = ENV['AWS_REGION']
55
+ # ENV['AWS_REGION'] = region
56
+ # images(options).find do |image|
57
+ # image.image_id.match(id)
58
+ # end.tap do |ami|
59
+ # ENV['AWS_REGION'] = current_region
60
+ # ec2.copy_image(source_image_id: ami.image_id, source_region: region, name: ami.name, description: ami.description)
61
+ # end
62
+ # end
63
+
64
+ desc 'last NAME', 'get last AMI matching NAME'
65
+ def last(name, n = 1)
66
+ images(options).select do |image|
67
+ image.name.match(name)
68
+ end.sort_by { |i| i.creation_date }.last(n.to_i).map do |image|
69
+ image.image_id
70
+ end.tap do |list|
71
+ puts list
72
+ end
73
+ end
74
+
75
+ end
76
+
77
+ end
@@ -1,3 +1,3 @@
1
1
  module Awful
2
- VERSION = "0.0.14"
2
+ VERSION = "0.0.15"
3
3
  end
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.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ric Lister
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-14 00:00:00.000000000 Z
11
+ date: 2015-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,6 +84,7 @@ description: AWS cmdline and yaml loader.
84
84
  email:
85
85
  - rlister+gh@gmail.com
86
86
  executables:
87
+ - ami
87
88
  - asg
88
89
  - ec2
89
90
  - elb
@@ -102,6 +103,7 @@ files:
102
103
  - README.md
103
104
  - Rakefile
104
105
  - awful.gemspec
106
+ - bin/ami
105
107
  - bin/asg
106
108
  - bin/ec2
107
109
  - bin/elb
@@ -112,6 +114,7 @@ files:
112
114
  - bin/subnet
113
115
  - bin/vpc
114
116
  - lib/awful.rb
117
+ - lib/awful/ami.rb
115
118
  - lib/awful/auto_scaling.rb
116
119
  - lib/awful/ec2.rb
117
120
  - lib/awful/elb.rb