rodeo_clown 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +34 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +27 -0
- data/LICENSE.txt +201 -0
- data/README.md +46 -0
- data/Rakefile +2 -0
- data/bin/elb_rotate.rb +42 -0
- data/lib/rodeo_clown/ec2.rb +38 -0
- data/lib/rodeo_clown/elb.rb +76 -0
- data/lib/rodeo_clown/ext/instance_collection.rb +65 -0
- data/lib/rodeo_clown/version.rb +3 -0
- data/lib/rodeo_clown.rb +28 -0
- data/rodeo_clown.gemspec +25 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 55ed6fc33066e5ee66123312b2597ac4fc04b226
|
4
|
+
data.tar.gz: ee3f47d79e71d7674403f12861b7c4af8ea4d24b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 789a4d8928dc33a97a44b906fee0391d08444c7d61a733c4d5f7731e19a7970a8562deb033320ad12b26c1826de833cd01601021f772737c540744aad7a42973
|
7
|
+
data.tar.gz: bac588d85fda57f0bc8e5649c085c5ba4cf6a3712e45b067b30c447ae28879b8ab1d00cf03c286abb50575dafb33f0badb7a4d29fc5c7c09b7f5b471552b360c
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rodeo_clown (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
aws-sdk (1.38.0)
|
10
|
+
json (~> 1.4)
|
11
|
+
nokogiri (>= 1.4.4)
|
12
|
+
uuidtools (~> 2.1)
|
13
|
+
json (1.8.1)
|
14
|
+
mini_portile (0.5.3)
|
15
|
+
nokogiri (1.6.1)
|
16
|
+
mini_portile (~> 0.5.0)
|
17
|
+
rake (10.2.2)
|
18
|
+
uuidtools (2.1.4)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
aws-sdk
|
25
|
+
bundler (~> 1.6)
|
26
|
+
rake
|
27
|
+
rodeo_clown!
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
```
|
2
|
+
_
|
3
|
+
_( )_
|
4
|
+
(_ O _)
|
5
|
+
(_)
|
6
|
+
_________/_
|
7
|
+
\ / /
|
8
|
+
sK )=====@=( Tp!
|
9
|
+
____/_________\____
|
10
|
+
| /^\ /^\ |
|
11
|
+
_| \0/_\0/ |_
|
12
|
+
(_ _ (_) _ _)
|
13
|
+
\( \___/ )/
|
14
|
+
RAiSE\\\___/// 2o14!
|
15
|
+
,-._\\___//_,-.
|
16
|
+
|* *`-._,-' * |
|
17
|
+
| * * (_)* * *|
|
18
|
+
|* _,-' `-.* |
|
19
|
+
`-' `-'
|
20
|
+
```
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
rodeo_clown
|
25
|
+
===========
|
26
|
+
|
27
|
+
Gem to assist cycling AWS EC2 instance and images.
|
28
|
+
|
29
|
+
Grab an instance of your ELB
|
30
|
+
```ruby
|
31
|
+
elb = RodeoClown::ELB.by_name("my-elb")
|
32
|
+
```
|
33
|
+
Rotate instances by tag values
|
34
|
+
```ruby
|
35
|
+
elb.rotate("myapp_v1" => "myapp_v2")
|
36
|
+
```
|
37
|
+
|
38
|
+
Rotate new instances into load balancer
|
39
|
+
```ruby
|
40
|
+
elb.instances.rotate
|
41
|
+
```
|
42
|
+
|
43
|
+
Rotate new instances into load balancer, with a new image
|
44
|
+
```ruby
|
45
|
+
elb.instances.rotate(image_id: "ami-1234567a")
|
46
|
+
```
|
data/Rakefile
ADDED
data/bin/elb_rotate.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "./lib/rodeo_clown"
|
4
|
+
|
5
|
+
def get_elb
|
6
|
+
puts "============\nRotate ELB\n=============\nChoose ELB:"
|
7
|
+
elbs = RodeoClown::ELB.load_balancers
|
8
|
+
n = 0
|
9
|
+
elbs.each do |elb|
|
10
|
+
n += 1
|
11
|
+
puts "#{n}> #{elb.name}"
|
12
|
+
end
|
13
|
+
puts "Other> Exit!"
|
14
|
+
|
15
|
+
num = gets.chomp.to_i
|
16
|
+
cnt = 1
|
17
|
+
elb = nil
|
18
|
+
|
19
|
+
elbs.each do |e|
|
20
|
+
if cnt == num
|
21
|
+
elb = e
|
22
|
+
break
|
23
|
+
end
|
24
|
+
cnt += 1
|
25
|
+
end
|
26
|
+
|
27
|
+
if elb.nil?
|
28
|
+
puts "Leaving so soon?"
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
|
32
|
+
RodeoClown::ELB.new elb
|
33
|
+
end
|
34
|
+
|
35
|
+
rc_elb = get_elb
|
36
|
+
puts rc_elb.instances.map &:id
|
37
|
+
|
38
|
+
|
39
|
+
#puts "rotating 'giftcards1' -> 'giftcards2'"
|
40
|
+
#elb.rotate("giftcards1" => "giftcards2")
|
41
|
+
|
42
|
+
#puts "done!"
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
module RodeoClown
|
3
|
+
class EC2 < Struct.new(:ec2)
|
4
|
+
def self.instances
|
5
|
+
ec2.instances
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.ec2
|
9
|
+
@ec2 ||= AWS::EC2.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.by_name(name)
|
13
|
+
new instances[name]
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
# options: keys: [ foo... , scope: :all], [:values scope: any]
|
18
|
+
#
|
19
|
+
def self.filter_instances(options = {})
|
20
|
+
filtered = filter_by_tag_options(instances, options[:keys], :tagged)
|
21
|
+
|
22
|
+
filter_by_tag_options(filtered, options[:values], :tagged_values)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.filter_by_tag_options(instances, options, filter = :tagged_values)
|
26
|
+
return instances if options.nil? || options.empty?
|
27
|
+
|
28
|
+
all = options.delete(:scope) == :all
|
29
|
+
vals = options.delete(:values)
|
30
|
+
|
31
|
+
if all
|
32
|
+
vals.inject(instances) { |i, value| i.send(filter, value) }
|
33
|
+
else
|
34
|
+
instances.send filter, *vals
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
module RodeoClown
|
3
|
+
class ELB < Struct.new(:aws_elb)
|
4
|
+
TIMEOUT = 10
|
5
|
+
|
6
|
+
extend Forwardable
|
7
|
+
def_delegators :aws_elb, :availability_zones, :instances
|
8
|
+
|
9
|
+
def self.by_name(name)
|
10
|
+
new load_balancers[name]
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.load_balancers
|
14
|
+
AWS::ELB.new.load_balancers
|
15
|
+
end
|
16
|
+
|
17
|
+
#
|
18
|
+
# Rotate servers given
|
19
|
+
#
|
20
|
+
def rotate(hsh)
|
21
|
+
current_ec2, new_ec2 = hsh.first
|
22
|
+
|
23
|
+
cur_instances = EC2.filter_instances(values: { values: current_ec2.to_s})
|
24
|
+
new_instances = EC2.filter_instances(values: { values: new_ec2.to_s})
|
25
|
+
|
26
|
+
new_instances.each do |i|
|
27
|
+
begin
|
28
|
+
puts "...registering: #{i.id}"
|
29
|
+
instances.register(i.id)
|
30
|
+
rescue AWS::ELB::Errors::InvalidInstance
|
31
|
+
puts "Instance #{i.id} could not be registered to load balancer"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
wait_for_state(instances, "InService")
|
36
|
+
|
37
|
+
cur_instances.each do |i|
|
38
|
+
begin
|
39
|
+
puts "...deregistering: #{i.id}"
|
40
|
+
instances.deregister(i.id)
|
41
|
+
rescue AWS::ELB::Errors::InvalidInstance
|
42
|
+
puts "Instance #{i.id} currently not registered to load balancer"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Wait for all the instances to become InService
|
49
|
+
#
|
50
|
+
def wait_for_state(instances, exp_state)
|
51
|
+
|
52
|
+
time = 0
|
53
|
+
all_good = false
|
54
|
+
|
55
|
+
loop do
|
56
|
+
all_good = instances.all? do |i|
|
57
|
+
state = i.elb_health[:state]
|
58
|
+
puts "#{i.id}: #{state}"
|
59
|
+
|
60
|
+
exp_state == state
|
61
|
+
end
|
62
|
+
|
63
|
+
break if all_good || time > TIMEOUT
|
64
|
+
|
65
|
+
sleep 1
|
66
|
+
time += 1
|
67
|
+
end
|
68
|
+
|
69
|
+
# If timeout before all inservice, deregister and raise error
|
70
|
+
unless all_good
|
71
|
+
raise "Instances are out of service"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class AWS::ELB::InstanceCollection
|
2
|
+
def rotate(options = {})
|
3
|
+
|
4
|
+
new_instances = start_new_instances(options)
|
5
|
+
old_instances = stop_current_instances
|
6
|
+
|
7
|
+
deregister old_instances
|
8
|
+
register new_instances
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def wait_for_status(status, collection = self, interval = 5)
|
14
|
+
until collection.all? { |ec2| ec2.status == status }
|
15
|
+
puts "Waiting for ALL instances to be #{status}..."
|
16
|
+
collection.each { |ec2| print_status(ec2) }
|
17
|
+
sleep interval
|
18
|
+
end
|
19
|
+
|
20
|
+
collection
|
21
|
+
end
|
22
|
+
|
23
|
+
def print_status(ec2)
|
24
|
+
puts "#{ec2.id}\t#{ec2.status}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def start_new_instances(options = {})
|
28
|
+
new_instances = map do |instance|
|
29
|
+
create_instance(instance_attributes(instance).merge(options))
|
30
|
+
end
|
31
|
+
|
32
|
+
wait_for_status(:running, new_instances)
|
33
|
+
|
34
|
+
new_instances
|
35
|
+
end
|
36
|
+
|
37
|
+
def stop_current_instances(interval = 5)
|
38
|
+
old_instances = map { |instance| stop_instance(instance) }
|
39
|
+
|
40
|
+
wait_for_status(:stopped)
|
41
|
+
old_instances
|
42
|
+
end
|
43
|
+
|
44
|
+
def instance_attributes(instance)
|
45
|
+
{
|
46
|
+
security_groups: instance.security_groups.map(&:name),
|
47
|
+
image_id: instance.image_id,
|
48
|
+
instance_type: instance.instance_type,
|
49
|
+
availability_zone: instance.availability_zone,
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def create_instance(options)
|
54
|
+
ec2.instances.create(options)
|
55
|
+
end
|
56
|
+
|
57
|
+
def stop_instance(instance)
|
58
|
+
instance.stop
|
59
|
+
instance
|
60
|
+
end
|
61
|
+
|
62
|
+
def ec2
|
63
|
+
@ec2 ||= AWS::EC2.new
|
64
|
+
end
|
65
|
+
end
|
data/lib/rodeo_clown.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative "rodeo_clown/version"
|
2
|
+
require "aws-sdk"
|
3
|
+
|
4
|
+
module RodeoClown
|
5
|
+
|
6
|
+
#
|
7
|
+
# Set aws credentials as environment variables
|
8
|
+
# Set aws credentials in the ~/.rodeo_clown.yml
|
9
|
+
#
|
10
|
+
# Just set your aws credentials
|
11
|
+
def self.credentials
|
12
|
+
@credentials ||=
|
13
|
+
if ENV.key?("AWS_ACCESS_KEY") && ENV.key?("AWS_SECRET_ACCESS_KEY")
|
14
|
+
{ access_key_id: ENV["AWS_ACCESS_KEY"],
|
15
|
+
secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"], }
|
16
|
+
elsif File.exists?(file = File.expand_path("~") + "/.rodeo_clown.yml")
|
17
|
+
YAML.load_file(file)
|
18
|
+
else
|
19
|
+
raise "Please supply aws_access_key and Aws_secret_access_key"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
AWS.config RodeoClown.credentials # Street cred
|
25
|
+
|
26
|
+
require_relative "rodeo_clown/ec2"
|
27
|
+
require_relative "rodeo_clown/elb"
|
28
|
+
require_relative "rodeo_clown/ext/instance_collection.rb"
|
data/rodeo_clown.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rodeo_clown/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rodeo_clown"
|
8
|
+
spec.version = RodeoClown::VERSION
|
9
|
+
spec.authors = ["Ted Price", "Stephen Korecky"]
|
10
|
+
spec.email = ["ted.price@gmail.com"]
|
11
|
+
spec.summary = %q{Tools for AWS}
|
12
|
+
spec.description = %q{Tools for AWS}
|
13
|
+
spec.homepage = "https://github.com/pricees/rodeo_clown/blob/master/README.md"
|
14
|
+
spec.license = "Cowboy Code"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "aws-sdk", "~> 1.38"
|
22
|
+
spec.add_development_dependency "aws-sdk", "~> 1.38"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rodeo_clown
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ted Price
|
8
|
+
- Stephen Korecky
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-04-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: aws-sdk
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.38'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.38'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: aws-sdk
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.38'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.38'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: bundler
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.6'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.6'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
description: Tools for AWS
|
71
|
+
email:
|
72
|
+
- ted.price@gmail.com
|
73
|
+
executables:
|
74
|
+
- elb_rotate.rb
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- .gitignore
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/elb_rotate.rb
|
85
|
+
- lib/rodeo_clown.rb
|
86
|
+
- lib/rodeo_clown/ec2.rb
|
87
|
+
- lib/rodeo_clown/elb.rb
|
88
|
+
- lib/rodeo_clown/ext/instance_collection.rb
|
89
|
+
- lib/rodeo_clown/version.rb
|
90
|
+
- rodeo_clown.gemspec
|
91
|
+
homepage: https://github.com/pricees/rodeo_clown/blob/master/README.md
|
92
|
+
licenses:
|
93
|
+
- Cowboy Code
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.0.3
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Tools for AWS
|
115
|
+
test_files: []
|