awful 0.0.70 → 0.0.71

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/awful/ec2.rb +50 -14
  3. data/lib/awful/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 023f1990584357d114dc7e70c8d2971c1ecd00ce
4
- data.tar.gz: 6b7861723e772dbc5c36902c433fb7ba95d16d18
3
+ metadata.gz: 03463a7d6e810bc35c1e6046e1c7146f169c6c3b
4
+ data.tar.gz: b2fb9f9635cee738269536462100adf340afb3ea
5
5
  SHA512:
6
- metadata.gz: 9ebd3dd3cf71c1bdbb0c300f119953278fc27732749188fdbe0d9e37ba985eebfdb1a13436b0423b792fbe3f57eb90017e50c665f3374f46190c7dccdfb460ff
7
- data.tar.gz: ddf52bcfe5a26b5fc6830d7631a20fc8310b0093ef1b3af6acf53613de636f9d2a3ccce09fda5e384f8ae9bfa141b765019eea8c62d0b96657aa8261ddcb2828
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 [PATTERN]', 'list EC2 instances [with id or tags matching PATTERN]'
20
- method_option :long, aliases: '-l', default: false, desc: 'Long listing'
21
- def ls(name = /./)
22
- fields = options[:long] ?
23
- ->(i) { [ (tag_name(i) || '-').slice(0..40), i.instance_id, i.instance_type, i.virtualization_type, i.placement.availability_zone, color(i.state.name),
24
- i.security_groups.map(&:group_name).join(',').slice(0..30), i.private_ip_address, i.public_ip_address ] } :
25
- ->(i) { [ tag_name(i) || i.instance_id ] }
26
-
27
- ec2.describe_instances.map(&:reservations).flatten.map(&:instances).flatten.select do |instance|
28
- instance.instance_id.match(name) or instance.tags.any? { |tag| tag.value.match(name) }
29
- end.map do |instance|
30
- fields.call(instance)
31
- end.tap do |list|
32
- print_table list.sort
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
@@ -1,3 +1,3 @@
1
1
  module Awful
2
- VERSION = '0.0.70'
2
+ VERSION = '0.0.71'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.70
4
+ version: 0.0.71
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ric Lister