awful 0.0.38 → 0.0.39

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: 6bddbf8cc43381e35767b345e27342b0eef5d7d6
4
- data.tar.gz: 89d85092fba21d2ba2ed58391fb75b5701750c01
3
+ metadata.gz: ff4da95e3c0f20638173ed7fb22ee8e55708ff6c
4
+ data.tar.gz: a8f8d60efa566e0575c56be0c07ba6f8ad7451de
5
5
  SHA512:
6
- metadata.gz: 7250389da22f30bf96cbfe66c1bd0531e6c3bf4aeece59b1bf98d00dd565d72a9afef6c00532956555d35680606fd34ee272b5bf77a48f12b044a250828e52d1
7
- data.tar.gz: b86ff5574c2ffa74bd8e976c38fbb94306f6a9a7219eb246faf4c4939fb64e7797a7c68a83e0f47759cda2bae204298dc91a15381eb90f73e6b9d8fb9a62ae51
6
+ metadata.gz: 2908b7accf1edae0464a5fa48859559911db58ec7dcac5fbc901d06fa3367a619ce3309e0da7f90a92d04bdb8652d70ad0659b4f31bcfa292a31156462bbb9f3
7
+ data.tar.gz: 5870345390e1c1bf2a9df53c20ac899e28336a0833ff09fbde0de70d683a6b53fd9d62b2b52dc7578a8a5417b5e296e57d4aa2abf2ad90c0e202178604699eaa
@@ -265,35 +265,41 @@ module Awful
265
265
  def old_instances(*names)
266
266
  asgs = autoscaling.describe_auto_scaling_groups(auto_scaling_group_names: names).map(&:auto_scaling_groups).flatten
267
267
 
268
- asgs.each_with_object({}) do |asg, hash|
268
+ ## get hash of old instances by ASG name
269
+ olds = asgs.each_with_object({}) do |asg, hash|
269
270
  outdated = asg.instances.select do |instance|
270
271
  instance.launch_configuration_name != asg.launch_configuration_name
271
272
  end
272
273
  hash[asg.auto_scaling_group_name] = outdated unless outdated.empty?
273
- end.tap do |olds|
274
- if olds.empty?
275
- # noop
276
- elsif options[:detach]
277
- autoscaling.detach_instances(auto_scaling_group_name: name, instance_ids: olds.values.flatten.map(&:instance_id), should_decrement_desired_capacity: options[:decrement])
278
- elsif options[:deregister]
279
- asg.load_balancer_names.map do |elb_name|
280
- elb.deregister_instances_from_load_balancer(load_balancer_name: elb_name, instances: olds.values.flatten.map { |i| { instance_id: i.instance_id } })
281
- end.tap { puts "Deregistered: #{olds.map(&:instance_id).join(',')}" }
282
- elsif options[:terminate]
283
- olds.values.flatten.map do |instance|
284
- autoscaling.terminate_instance_in_auto_scaling_group(instance_id: instance.instance_id, should_decrement_desired_capacity: options[:decrement] && true)
285
- instance.instance_id
286
- end.tap { |ids| say("Terminated: #{ids.join(',')}", :yellow) }
287
- elsif options[:groups]
288
- puts olds.keys
289
- elsif options[:long]
290
- print_table olds.map { |asg, ins| ins.map { |i| [i.instance_id, asg, i.launch_configuration_name] }.flatten }
291
- else
292
- puts olds.values.flatten.map(&:instance_id)
274
+ end
275
+
276
+ if olds.empty?
277
+ # noop
278
+ elsif options[:detach]
279
+ autoscaling.detach_instances(auto_scaling_group_name: name, instance_ids: olds.values.flatten.map(&:instance_id), should_decrement_desired_capacity: options[:decrement])
280
+ elsif options[:deregister]
281
+ asgs.select do |asg|
282
+ olds.has_key?(asg.auto_scaling_group_name)
283
+ end.each do |asg|
284
+ instance_ids = olds[asg.auto_scaling_group_name].flatten.map(&:instance_id)
285
+ asg.load_balancer_names.each do |elb_name|
286
+ say "Deregistering #{instance_ids.join(',')} from ELB #{elb_name}", :yellow
287
+ elb.deregister_instances_from_load_balancer(load_balancer_name: elb_name, instances: instance_ids.map { |id| {instance_id: id} })
288
+ end
293
289
  end
290
+ elsif options[:terminate]
291
+ olds.values.flatten.map do |instance|
292
+ autoscaling.terminate_instance_in_auto_scaling_group(instance_id: instance.instance_id, should_decrement_desired_capacity: options[:decrement] && true)
293
+ instance.instance_id
294
+ end.tap { |ids| say("Terminated: #{ids.join(',')}", :yellow) }
295
+ elsif options[:groups]
296
+ puts olds.keys
297
+ elsif options[:long]
298
+ print_table olds.map { |asg, ins| ins.map { |i| [i.instance_id, asg, i.launch_configuration_name] }.flatten }
299
+ else
300
+ puts olds.values.flatten.map(&:instance_id)
294
301
  end
295
302
  end
296
-
297
303
  end
298
304
 
299
305
  end
data/lib/awful/s3.rb CHANGED
@@ -2,11 +2,31 @@ module Awful
2
2
 
3
3
  class S3 < Cli
4
4
 
5
- desc 'list_buckets [PATTERN]', 'list buckets'
5
+ no_commands do
6
+
7
+ ## resource interface to S3 commands
8
+ def s3_resource
9
+ Aws::S3::Resource.new(client: s3)
10
+ end
11
+
12
+ end
13
+
14
+ desc 'ls PATTERN', 'list buckets or objects'
15
+ method_option :long, aliases: '-l', default: false, desc: 'Long listing'
16
+ def ls(name = '.')
17
+ if name.include?('/')
18
+ bucket, prefix = name.split('/', 2)
19
+ invoke 'objects', [bucket, prefix], options
20
+ else
21
+ invoke 'buckets', [name], options
22
+ end
23
+ end
24
+
25
+ desc 'buckets [PATTERN]', 'list buckets'
6
26
  method_option :long, aliases: '-l', default: false, desc: 'Long listing'
7
- def list_buckets(name = /./)
27
+ def buckets(name = /./)
8
28
  s3.list_buckets.buckets.select do |bucket|
9
- bucket.name.match(name)
29
+ bucket.name.match(/#{name}/)
10
30
  end.tap do |list|
11
31
  if options[:long]
12
32
  print_table list.map { |b| [ b.name, b.creation_date ] }
@@ -16,12 +36,9 @@ module Awful
16
36
  end
17
37
  end
18
38
 
19
- desc 'list_objects BUCKET [PATTERN]', 'list objects in bucket'
20
- def list_objects(bucket, prefix = nil)
21
- # s3.list_objects(bucket: bucket, prefix: prefix, delimiter: '').contents.map(&:key).tap do |list|
22
- # puts list
23
- # end
24
- Aws::S3::Resource.new(client: s3).bucket(bucket).objects(delimiter: '', prefix: prefix).map do |object|
39
+ desc 'objects BUCKET [PATTERN]', 'list objects in bucket'
40
+ def objects(bucket, prefix = nil)
41
+ s3_resource.bucket(bucket).objects(prefix: prefix).map do |object|
25
42
  object.key
26
43
  end.tap { |list| puts list }
27
44
  end
data/lib/awful/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Awful
2
- VERSION = "0.0.38"
2
+ VERSION = "0.0.39"
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.38
4
+ version: 0.0.39
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-09-15 00:00:00.000000000 Z
11
+ date: 2015-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler