awful 0.0.54 → 0.0.55

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: 224ca11d5105f088200d1934aa706cb2efea2b7e
4
- data.tar.gz: aa9b1247d4fcaeed7d6a19c38a9f3fae935c02a8
3
+ metadata.gz: 56376495dec02b800fed9491623c01bbbdf421c1
4
+ data.tar.gz: 75d49a923b5d25064346e65f063938384192c75b
5
5
  SHA512:
6
- metadata.gz: dda428258e10bdaf181bc41c42243ee6661ab4e00dd1094ae7250c41652158be6efd3513a7ca6485a512ac353b26a1e4d31e060ec23053c2236d0502cf7abc7a
7
- data.tar.gz: eaf7fb32203c5dc76686d2bb2df19644875a2d9b21d317d76939666ceb60be6c436553b63761f633489d312e420af9f8ede9a5a025a1667aede900ec36b42bd2
6
+ metadata.gz: a13c33a1eac8b19dcab30d6498ce53f5a98ca1cfd6c1896ed658923c11f0297ee09b6d23070053b71072fe4dc61757c4006b65e061e54723f12ceb00ca77ae8e
7
+ data.tar.gz: 2d3c8916d7028a62a076a8d57255fa7ba672bff1789b1a1c1bb3688d8266ae692afaf1774131ebe8147fd8cd6337391f9796e75d23f91b2d4edbe31ddef3b793
@@ -14,37 +14,43 @@ module Awful
14
14
  Successful: :green,
15
15
  Failed: :red,
16
16
  Cancelled: :red,
17
+ ## instance state
18
+ running: :green,
19
+ stopped: :yellow,
20
+ terminated: :red,
17
21
  }
18
22
 
19
23
  no_commands do
20
24
  def color(string)
21
25
  set_color(string, COLORS.fetch(string.to_sym, :yellow))
22
26
  end
27
+
28
+ def all_matching_asgs(name)
29
+ autoscaling.describe_auto_scaling_groups.map(&:auto_scaling_groups).flatten.select do |asg|
30
+ asg.auto_scaling_group_name.match(name) or tag_name(asg, '').match(name)
31
+ end
32
+ end
23
33
  end
24
34
 
25
35
  desc 'ls [PATTERN]', 'list autoscaling groups with name matching PATTERN'
26
36
  method_option :long, aliases: '-l', default: false, desc: 'Long listing'
27
37
  def ls(name = /./)
28
- fields = if options[:long]
29
- ->(a) { [
30
- tag_name(a, '-')[0,40],
31
- a.auto_scaling_group_name[0,40],
32
- a.launch_configuration_name[0,40],
33
- "#{a.instances.length}/#{a.desired_capacity}",
34
- "#{a.min_size}-#{a.max_size}",
35
- a.availability_zones.map{ |az| az[-1,1] }.sort.join(','),
36
- a.created_time
37
- ] }
38
- else
39
- ->(a) { [ a.auto_scaling_group_name ] }
40
- end
41
-
42
- autoscaling.describe_auto_scaling_groups.map(&:auto_scaling_groups).flatten.select do |asg|
43
- asg.auto_scaling_group_name.match(name) or tag_name(asg, '').match(name)
44
- end.map do |asg|
45
- fields.call(asg)
46
- end.tap do |list|
47
- print_table list
38
+ all_matching_asgs(name).tap do |asgs|
39
+ if options[:long]
40
+ print_table asgs.map { |a|
41
+ [
42
+ tag_name(a, '-')[0,40],
43
+ a.auto_scaling_group_name[0,40],
44
+ a.launch_configuration_name[0,40],
45
+ "#{a.instances.length}/#{a.desired_capacity}",
46
+ "#{a.min_size}-#{a.max_size}",
47
+ a.availability_zones.map{ |az| az[-1,1] }.sort.join(','),
48
+ a.created_time
49
+ ]
50
+ }
51
+ else
52
+ puts asgs.map(&:auto_scaling_group_name)
53
+ end
48
54
  end
49
55
  end
50
56
 
@@ -59,16 +65,17 @@ module Awful
59
65
  method_option :long, aliases: '-l', default: false, desc: 'Long listing'
60
66
  method_option :launch_configuration, aliases: '-L', default: false, desc: 'Get instance launch_configs'
61
67
  def instances(name)
62
- autoscaling.describe_auto_scaling_instances.map(&:auto_scaling_instances).flatten.select do |instance|
63
- instance.auto_scaling_group_name.match(name)
64
- end.tap do |instances|
68
+ all_matching_asgs(name).map(&:instances).flatten.tap do |instances|
65
69
  if options[:long]
66
70
  print_table instances.map { |i|
67
- [i.instance_id, i.auto_scaling_group_name, i.availability_zone, color(i.lifecycle_state),
68
- color(i.health_status), i.launch_configuration_name]
71
+ [
72
+ i.instance_id,
73
+ i.availability_zone,
74
+ color(i.lifecycle_state),
75
+ color(i.health_status),
76
+ i.launch_configuration_name,
77
+ ]
69
78
  }
70
- elsif options[:launch_configuration]
71
- print_table instances.map { |i| [i.instance_id, i.launch_configuration_name] }
72
79
  else
73
80
  puts instances.map(&:instance_id)
74
81
  end
@@ -78,20 +85,20 @@ module Awful
78
85
  desc 'ips NAME', 'list IPs for instances in groups matching NAME'
79
86
  method_option :long, aliases: '-l', default: false, desc: 'Long listing'
80
87
  def ips(name)
81
- fields = options[:long] ?
82
- ->(i) { [ i.public_ip_address, i.private_ip_address, i.instance_id, i.image_id, i.instance_type, i.placement.availability_zone, i.state.name, i.launch_time ] } :
83
- ->(i) { [ i.public_ip_address ] }
84
-
85
- instance_ids = autoscaling.describe_auto_scaling_instances.map(&:auto_scaling_instances).flatten.select do |instance|
86
- instance.auto_scaling_group_name.match(name)
87
- end.map(&:instance_id)
88
-
89
- ec2 = Aws::EC2::Client.new
90
- ec2.describe_instances(instance_ids: instance_ids).map(&:reservations).flatten.map(&:instances).flatten.sort_by(&:launch_time).map do |instance|
91
- fields.call(instance)
92
- end.tap do |list|
93
- print_table list
88
+ ## get instance IDs for matching ASGs
89
+ ids = all_matching_asgs(name).map(&:instances).flatten.map(&:instance_id)
90
+
91
+ ## get instance details for these IDs
92
+ ec2.describe_instances(instance_ids: ids).map(&:reservations).flatten.map(&:instances).flatten.sort_by(&:launch_time).tap do |instances|
93
+ if options[:long]
94
+ print_table instances.map { |i|
95
+ [ i.public_ip_address, i.private_ip_address, i.instance_id, i.image_id, i.instance_type, i.placement.availability_zone, color(i.state.name), i.launch_time ]
96
+ }
97
+ else
98
+ puts instances.map(&:public_ip_address)
99
+ end
94
100
  end
101
+
95
102
  end
96
103
 
97
104
  desc 'ssh NAME [ARGS]', 'ssh to an instance for this autoscaling group'
@@ -99,7 +106,7 @@ module Awful
99
106
  method_option :number, aliases: '-n', default: 1, desc: 'number of instances to ssh'
100
107
  method_option :login_name, aliases: '-l', default: nil, desc: 'login name to pass to ssh'
101
108
  def ssh(name, *args)
102
- ips = ips(name).flatten
109
+ ips = ips(name).map(&:public_ip_address)
103
110
  num = options[:all] ? ips.count : options[:number].to_i
104
111
  login_name = options[:login_name] ? "-l #{options[:login_name]}" : ''
105
112
  ips.last(num).each do |ip|
@@ -109,8 +116,10 @@ module Awful
109
116
 
110
117
  desc 'dump NAME', 'dump existing autoscaling group as yaml'
111
118
  def dump(name)
112
- autoscaling.describe_auto_scaling_groups(auto_scaling_group_names: Array(name)).map(&:auto_scaling_groups).flatten.first.to_hash.tap do |asg|
113
- puts YAML.dump(stringify_keys(asg)) unless options[:quiet]
119
+ all_matching_asgs(name).map(&:to_hash).tap do |asgs|
120
+ asgs.each do |asg|
121
+ puts YAML.dump(stringify_keys(asg)) unless options[:quiet]
122
+ end
114
123
  end
115
124
  end
116
125
 
data/lib/awful/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Awful
2
- VERSION = "0.0.54"
2
+ VERSION = "0.0.55"
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.54
4
+ version: 0.0.55
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ric Lister