awful 0.0.70 → 0.0.71
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 +4 -4
- data/lib/awful/ec2.rb +50 -14
- data/lib/awful/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03463a7d6e810bc35c1e6046e1c7146f169c6c3b
|
4
|
+
data.tar.gz: b2fb9f9635cee738269536462100adf340afb3ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 080d501cbb006811a5d344975f1f8ffb25ba571eab9924c3f576ff1b7da6eddd69eb4db7264f07ef1d1d58e712301aa83325591bb8846218dc5a850396a2a0aa
|
7
|
+
data.tar.gz: 340922621b2549bd82b732c5737871685401492096f647e671149e00eef66ec977f618699d9196af8a7f479fee098f11b6c5af56f862d781d292e82423d43274
|
data/lib/awful/ec2.rb
CHANGED
@@ -16,20 +16,56 @@ module Awful
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
desc 'ls [
|
20
|
-
method_option :long,
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
19
|
+
desc 'ls [NAME]', 'get instances with given name regex'
|
20
|
+
method_option :long, aliases: '-l', type: :boolean, default: false, desc: 'Long listing'
|
21
|
+
method_option :ids, aliases: '-i', type: :array, default: [], desc: 'List of instance ids to retrieve'
|
22
|
+
method_option :tags, aliases: '-t', type: :array, default: [], desc: 'List of tags to filter, as key:value'
|
23
|
+
method_option :stack, aliases: '-s', type: :string, default: nil, desc: 'Filter by given stack'
|
24
|
+
method_option :resource, aliases: '-r', type: :string, default: nil, desc: 'Filter by given stack resource logical id'
|
25
|
+
method_option :autoscaling, aliases: '-a', type: :string, default: nil, desc: 'Filter by given autoscaling group'
|
26
|
+
def ls(name = nil)
|
27
|
+
params = {instance_ids: [], filters: []}
|
28
|
+
|
29
|
+
## filter by ids
|
30
|
+
options[:ids].each do |id|
|
31
|
+
params[:instance_ids] << id
|
32
|
+
end
|
33
|
+
|
34
|
+
## filter by arbitrary tags
|
35
|
+
options[:tags].each do |tag|
|
36
|
+
key, value = tag.split(/[:=]/)
|
37
|
+
params[:filters] << {name: "tag:#{key}", values: [value]}
|
38
|
+
end
|
39
|
+
|
40
|
+
## filter shortcuts for stack, resource, autoscaling group
|
41
|
+
params[:filters] << {name: 'tag:aws:cloudformation:stack-name', values: [options[:stack]]} if options[:stack]
|
42
|
+
params[:filters] << {name: 'tag:aws:cloudformation:logical-id', values: [options[:resource]]} if options[:resource]
|
43
|
+
params[:filters] << {name: 'tag:aws:autoscaling:groupName', values: [options[:autoscaling]]} if options[:autoscaling]
|
44
|
+
|
45
|
+
## get list of instances
|
46
|
+
instances = ec2.describe_instances(params.reject{ |k,v| v.empty? }).reservations.map(&:instances).flatten
|
47
|
+
|
48
|
+
## filter by Name tag as a regex
|
49
|
+
instances.select! { |i| tag_name(i, '').match(name) } if name
|
50
|
+
|
51
|
+
## output
|
52
|
+
instances.tap do |list|
|
53
|
+
if options[:long]
|
54
|
+
print_table list.map { |i|
|
55
|
+
[
|
56
|
+
tag_name(i),
|
57
|
+
i.instance_id,
|
58
|
+
i.instance_type,
|
59
|
+
i.placement.availability_zone,
|
60
|
+
color(i.state.name),
|
61
|
+
i.security_groups.map(&:group_name).join(',').slice(0..30),
|
62
|
+
i.private_ip_address,
|
63
|
+
i.public_ip_address
|
64
|
+
]
|
65
|
+
}
|
66
|
+
else
|
67
|
+
puts list.map(&:instance_id)
|
68
|
+
end
|
33
69
|
end
|
34
70
|
end
|
35
71
|
|
data/lib/awful/version.rb
CHANGED