easy_aws 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/easy_aws/ec2.rb +39 -0
  2. metadata +5 -4
@@ -0,0 +1,39 @@
1
+ require 'aws-sdk'
2
+
3
+ module EasyAws
4
+ extend self
5
+
6
+ def stop_all_instances_with_tag(tag_name, tag_value)
7
+ AWS::EC2.new().regions.each { |region| stop_instances_in_region_with_tag region, tag_name, tag_value }
8
+ end
9
+
10
+ def stop_instances_in_region_with_tag(region, tag_name, tag_value)
11
+ puts "Stopping instances in #{region.name}"
12
+ threads = []
13
+ region.instances.tagged(tag_name).tagged_values(tag_value).each() { |instance|
14
+ threads << Thread.new(instance) { |instance|
15
+ status = instance.status
16
+ id = instance.id
17
+
18
+ puts "Found Instance #{id} #{status}"
19
+ if status == :running || status == :pending
20
+ stop_instance id, instance
21
+ end
22
+ }
23
+ }
24
+ threads.each { |t| t.join }
25
+ end
26
+
27
+ private
28
+
29
+ def stop_instance(id, instance)
30
+ puts "Stopping #{id}"
31
+ instance.stop
32
+ while (status = instance.status) != :stopped
33
+ puts "Instance #{id} #{status}"
34
+ sleep 5
35
+ end
36
+ puts "Instance #{id} #{status}"
37
+ end
38
+
39
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_aws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-11 00:00:00.000000000 Z
12
+ date: 2013-10-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
@@ -33,6 +33,7 @@ executables: []
33
33
  extensions: []
34
34
  extra_rdoc_files: []
35
35
  files:
36
+ - lib/easy_aws/ec2.rb
36
37
  - lib/easy_aws/helpers.rb
37
38
  - lib/easy_aws/route53.rb
38
39
  - lib/easy_aws/sns.rb
@@ -52,7 +53,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
52
53
  version: '0'
53
54
  segments:
54
55
  - 0
55
- hash: 1071192877
56
+ hash: 430660499
56
57
  required_rubygems_version: !ruby/object:Gem::Requirement
57
58
  none: false
58
59
  requirements:
@@ -61,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
62
  version: '0'
62
63
  segments:
63
64
  - 0
64
- hash: 1071192877
65
+ hash: 430660499
65
66
  requirements: []
66
67
  rubyforge_project:
67
68
  rubygems_version: 1.8.24