rivet 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +31 -0
- data/LICENSE +202 -0
- data/README.md +128 -0
- data/Rakefile +9 -0
- data/bin/rivet +43 -0
- data/lib/rivet/autoscale.rb +125 -0
- data/lib/rivet/aws_utils.rb +74 -0
- data/lib/rivet/bootstrap.rb +62 -0
- data/lib/rivet/client.rb +29 -0
- data/lib/rivet/deep_merge.rb +27 -0
- data/lib/rivet/launch_config.rb +90 -0
- data/lib/rivet/logger.rb +52 -0
- data/lib/rivet/utils.rb +68 -0
- data/lib/rivet/version.rb +4 -0
- data/lib/rivet.rb +18 -0
- data/rivet.gemspec +31 -0
- data/spec/rivet_bootstrap_spec.rb +69 -0
- data/spec/rivet_launch_config_spec.rb +37 -0
- data/spec/rivet_spec_setup.rb +62 -0
- data/spec/rivet_util_spec.rb +123 -0
- metadata +124 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
aws-sdk (1.24.0)
|
5
|
+
json (~> 1.4)
|
6
|
+
nokogiri (>= 1.4.4, < 1.6.0)
|
7
|
+
uuidtools (~> 2.1)
|
8
|
+
diff-lcs (1.2.5)
|
9
|
+
json (1.8.1)
|
10
|
+
json (1.8.1-java)
|
11
|
+
nokogiri (1.5.10)
|
12
|
+
nokogiri (1.5.10-java)
|
13
|
+
rake (10.1.0)
|
14
|
+
rspec (2.14.1)
|
15
|
+
rspec-core (~> 2.14.0)
|
16
|
+
rspec-expectations (~> 2.14.0)
|
17
|
+
rspec-mocks (~> 2.14.0)
|
18
|
+
rspec-core (2.14.7)
|
19
|
+
rspec-expectations (2.14.4)
|
20
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
21
|
+
rspec-mocks (2.14.4)
|
22
|
+
uuidtools (2.1.4)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
java
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
aws-sdk (~> 1.24.0)
|
30
|
+
rake (>= 10.1.0)
|
31
|
+
rspec (~> 2.14.1)
|
data/LICENSE
ADDED
@@ -0,0 +1,202 @@
|
|
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 {2013} {Brian Bianco}
|
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.
|
202
|
+
|
data/README.md
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/brianbianco/rivet.png)](https://travis-ci.org/brianbianco/rivet)
|
2
|
+
|
3
|
+
Rivet
|
4
|
+
=======
|
5
|
+
Rivet is a small utility which allows you to describe an autoscaling groups and it's launch configurations as yaml. You can then sync those changes to AWS.
|
6
|
+
|
7
|
+
Rivet allows you to provide a template and it's options which will be rendered as user-data for your launch configurations. It is currently opinionated and assumes you are trying to build
|
8
|
+
a bootstrap script for chef installed via gems. You can of course provide it with any template you desire, and in future releases this system will become more flexible and less opinionated.
|
9
|
+
|
10
|
+
Rivet is also opinionated about how it names launch configurations, as it generates unique deterministic names for them and automatically assigns the proper launch configuration to your
|
11
|
+
autoscaling group based upon it's generated identity.
|
12
|
+
|
13
|
+
Installation
|
14
|
+
============
|
15
|
+
|
16
|
+
gem install rivet
|
17
|
+
|
18
|
+
Setup
|
19
|
+
=====
|
20
|
+
|
21
|
+
AWS Credentials
|
22
|
+
---------------
|
23
|
+
|
24
|
+
Rivet uses the python AWS CLI tools [https://github.com/aws/aws-cli] configuration format and file for it's AWS credentials. This means it looks for a file located at AWS\_CONFIG\_FILE.
|
25
|
+
|
26
|
+
Right now Rivet only uses the following options from the file:
|
27
|
+
|
28
|
+
* profile name
|
29
|
+
* aws\_access\_key\_id
|
30
|
+
* aws\_secret\_access\_key
|
31
|
+
* region
|
32
|
+
|
33
|
+
An example config could look as follows:
|
34
|
+
|
35
|
+
```
|
36
|
+
[default]
|
37
|
+
aws_access_key_id<YOUR ACCESS KEY ID>
|
38
|
+
aws_secret_access_key=<YOUR SECRET ACCESS KEY>
|
39
|
+
region=us-east-1
|
40
|
+
|
41
|
+
[foo]
|
42
|
+
aws_access_key_id=<YOUR ACCESS KEY ID>
|
43
|
+
aws_secret_access_key=<YOUR SECRET_ACCESS KEY>
|
44
|
+
region=us-west-2
|
45
|
+
```
|
46
|
+
|
47
|
+
Alternatively you can specify your AWS\_ACCESS\_KEY\_ID and AWS\_SECRET\_ACCESS\_KEY as environment variables.
|
48
|
+
|
49
|
+
You will still need to specify the region to use in your AWS\_CONFIG\_FILE.
|
50
|
+
|
51
|
+
Rivet will use the [default] profile if you do not specify a profile to use with the -p [--profile] option.
|
52
|
+
|
53
|
+
|
54
|
+
Autoscaling group definition directories and files
|
55
|
+
--------------------------------------------------
|
56
|
+
|
57
|
+
Example files can be found in the example/ directory in the rivet git repository
|
58
|
+
|
59
|
+
You should create an "autoscale" directory wherever you plan to run rivet from. Currently it always looks in the current directory for definition files. It expects a directory structure as such.
|
60
|
+
|
61
|
+
```
|
62
|
+
./autoscale
|
63
|
+
| - defaults.yml
|
64
|
+
| - <autoscale group name>
|
65
|
+
| - conf.yml
|
66
|
+
```
|
67
|
+
|
68
|
+
defaults.yml and conf.yml both accept all the same options. A groups definition will be deep merged over the defaults.
|
69
|
+
|
70
|
+
The yaml file format:
|
71
|
+
|
72
|
+
```
|
73
|
+
min_size: SIZE <integer>
|
74
|
+
max_size: SIZE <integer>
|
75
|
+
region: AWS REGION <STRING>
|
76
|
+
availability_zones: [ZONE<string>,ZONE...]
|
77
|
+
|
78
|
+
bootstrap:
|
79
|
+
chef_organization: CHEF_ORGANIZATION <string>
|
80
|
+
template: TEMPLATE <string>
|
81
|
+
config_dir: CONFIGURATION_FILES_DIR <string>
|
82
|
+
environment: CHEF_ENVIRONMENT <string>
|
83
|
+
gems:
|
84
|
+
- [GEM_NAME<string>,GEM_VERSION<string>]
|
85
|
+
- [GEM_NAME<string>]
|
86
|
+
run_list:
|
87
|
+
- 'role[example]' <string>
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
Availability zones should use the single character of the zone. The region will be appended by rivet.
|
92
|
+
|
93
|
+
The following files should exist in the configuration directory specified under the bootstrap -> config_dir key:
|
94
|
+
|
95
|
+
A template file (specified by the bootstrap -> template file name)
|
96
|
+
A validator pem (named by the bootstrap -> environment key as <environment>-validator.pem)
|
97
|
+
|
98
|
+
|
99
|
+
Usage
|
100
|
+
=====
|
101
|
+
|
102
|
+
```
|
103
|
+
Usage: rivet [options]
|
104
|
+
-g, --group [GROUP_NAME] Autoscaling group name
|
105
|
+
-l, --log-level [LEVEL] specify the log level (default is INFO)
|
106
|
+
-p, --profile [PROFILE_NAME] Selects the AWS profile to use (default is 'default')
|
107
|
+
-s, --sync Sync the changes remotely to AWS
|
108
|
+
-h
|
109
|
+
```
|
110
|
+
|
111
|
+
Using rivet to check the differences for the example_group autoscaling group
|
112
|
+
|
113
|
+
```bash
|
114
|
+
rivet -g example_group
|
115
|
+
```
|
116
|
+
|
117
|
+
Using rivet to check the differences for the example_group using the foobar profile
|
118
|
+
|
119
|
+
```bash
|
120
|
+
rivet -g example_group -p foobar
|
121
|
+
```
|
122
|
+
|
123
|
+
Using rivet to sync the differences for the example_group using the foobar profile
|
124
|
+
|
125
|
+
```bash
|
126
|
+
rivet -g example_group -p foobar -s
|
127
|
+
```
|
128
|
+
|
data/Rakefile
ADDED
data/bin/rivet
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
4
|
+
require 'rivet'
|
5
|
+
require 'rivet/client'
|
6
|
+
|
7
|
+
DEBUG = Logger::DEBUG
|
8
|
+
WARN = Logger::WARN
|
9
|
+
FATAL = Logger::FATAL
|
10
|
+
INFO = Logger::INFO
|
11
|
+
|
12
|
+
# Default option values
|
13
|
+
options = {
|
14
|
+
:log_level => INFO,
|
15
|
+
:profile => 'default'
|
16
|
+
}
|
17
|
+
|
18
|
+
OptionParser.new do |o|
|
19
|
+
o.on('-g', '--group [GROUP_NAME]', String, 'Autoscaling group name') do |g|
|
20
|
+
options[:group] = g
|
21
|
+
end
|
22
|
+
|
23
|
+
o.on('-l', '--log-level [LEVEL]', String, "specify the log level (default is INFO)") do |l|
|
24
|
+
options[:log_level] = Kernel.const_get l.upcase
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
o.on('-p', '--profile [PROFILE_NAME]', "Selects the AWS profile to use (default is 'default')") do |p|
|
29
|
+
options[:profile] = p
|
30
|
+
end
|
31
|
+
|
32
|
+
o.on('-s', '--sync', "Sync the changes remotely to AWS") do |s|
|
33
|
+
options[:sync] = s
|
34
|
+
end
|
35
|
+
|
36
|
+
o.on('-h') { puts o; exit }
|
37
|
+
o.parse!
|
38
|
+
end
|
39
|
+
|
40
|
+
raise "--group [GROUP_NAME] argument is required!" if options[:group].nil?
|
41
|
+
|
42
|
+
Rivet::Client.new.run(options)
|
43
|
+
|
@@ -0,0 +1,125 @@
|
|
1
|
+
module Rivet
|
2
|
+
class Autoscale
|
3
|
+
|
4
|
+
REQUIRED_FIELDS = [:min_size,:max_size,:launch_configuration,:availability_zones]
|
5
|
+
|
6
|
+
attr_reader :min_size, :max_size, :name, :launch_configuration, :availability_zones
|
7
|
+
|
8
|
+
def initialize(name,definition)
|
9
|
+
@name = name
|
10
|
+
@min_size = definition['min_size']
|
11
|
+
@max_size = definition['max_size']
|
12
|
+
@launch_config = LaunchConfig.new(definition)
|
13
|
+
|
14
|
+
# Normalizing zones to match what the SDK expects, E.G. "<region><zone>"
|
15
|
+
@availability_zones = definition['availability_zones'].map! do |zone|
|
16
|
+
definition['region'] + zone
|
17
|
+
end
|
18
|
+
|
19
|
+
# The launch_configuration attr exists for convinence since that is what
|
20
|
+
# the aws SDK refers to the launch configuration name as for autoscaling
|
21
|
+
@launch_configuration = @launch_config.identity
|
22
|
+
end
|
23
|
+
|
24
|
+
def options
|
25
|
+
@options ||= get_update_options
|
26
|
+
end
|
27
|
+
|
28
|
+
def differences
|
29
|
+
@differences ||= get_differences
|
30
|
+
end
|
31
|
+
|
32
|
+
def differences?
|
33
|
+
!differences.empty?
|
34
|
+
end
|
35
|
+
|
36
|
+
def show_differences(level = 'info')
|
37
|
+
|
38
|
+
Rivet::Log.write(level, "Remote and local defintions match") unless differences?
|
39
|
+
|
40
|
+
differences.each_pair do |attr,values|
|
41
|
+
Rivet::Log.write(level,"#{attr}:")
|
42
|
+
Rivet::Log.write(level," remote: #{values['remote']}")
|
43
|
+
Rivet::Log.write(level," local: #{values['local']}")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def sync
|
48
|
+
if differences?
|
49
|
+
Rivet::Log.info("Syncing autoscale group changes to AWS for #{@name}")
|
50
|
+
autoscale = AWS::AutoScaling.new()
|
51
|
+
group = autoscale.groups[@name]
|
52
|
+
|
53
|
+
create(options) unless group.exists?
|
54
|
+
|
55
|
+
@launch_config.save
|
56
|
+
group.update(options)
|
57
|
+
else
|
58
|
+
Rivet::Log.info("No autoscale differences to sync to AWS for #{@name}.")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
protected
|
63
|
+
|
64
|
+
def get_update_options
|
65
|
+
options = Hash.new
|
66
|
+
differences.each_pair do |attribute,values|
|
67
|
+
options[attribute.to_sym] = values['local']
|
68
|
+
end
|
69
|
+
|
70
|
+
REQUIRED_FIELDS.each do |field|
|
71
|
+
unless options.has_key?(field)
|
72
|
+
options[field] = self.send(field)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
options
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_differences
|
79
|
+
remote = get_remote
|
80
|
+
differences = Hash.new
|
81
|
+
[:min_size,:max_size,:launch_configuration].each do |a|
|
82
|
+
if remote[a.to_s] != self.send(a)
|
83
|
+
differences[a.to_s] = { 'remote' => remote[a.to_s], 'local' => self.send(a) }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
if remote['availability_zones'] != availability_zones
|
88
|
+
differences['availability_zones'] = { 'remote' => remote['availability_zones'], 'local' => availability_zones }
|
89
|
+
end if remote.has_key?('availability_zones')
|
90
|
+
|
91
|
+
differences
|
92
|
+
end
|
93
|
+
|
94
|
+
def get_remote
|
95
|
+
autoscale = AWS::AutoScaling.new()
|
96
|
+
remote_group = autoscale.groups[@name]
|
97
|
+
if remote_group.exists?
|
98
|
+
|
99
|
+
remote_hash = [:min_size,:max_size].inject(Hash.new) do |accum,attr|
|
100
|
+
accum[attr.to_s] = remote_group.send(attr)
|
101
|
+
accum
|
102
|
+
end
|
103
|
+
|
104
|
+
remote_hash['launch_configuration'] = remote_group.launch_configuration_name
|
105
|
+
|
106
|
+
# Normalize their AWS::Core::Data::List to a sorted array
|
107
|
+
remote_hash['availability_zones'] = remote_group.availability_zone_names.to_a.sort
|
108
|
+
|
109
|
+
remote_hash
|
110
|
+
else
|
111
|
+
{ }
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def create(options)
|
116
|
+
autoscale = AWS::AutoScaling.new()
|
117
|
+
if autoscale.groups[@name].exists?
|
118
|
+
raise "Cannot create AutoScaling #{@name} group it already exists!"
|
119
|
+
else
|
120
|
+
autoscale.groups.create(@name,options)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Rivet
|
2
|
+
module AwsUtils
|
3
|
+
|
4
|
+
def self.verify_security_groups(groups)
|
5
|
+
Rivet::Log.info("Verifying security groups: #{groups.join(",")}")
|
6
|
+
|
7
|
+
security_groups_collection = AWS::EC2.new().security_groups
|
8
|
+
filtered_groups = Array.new
|
9
|
+
security_groups_collection.filter('group-name', *groups).each do |g|
|
10
|
+
filtered_groups << g.name
|
11
|
+
end
|
12
|
+
|
13
|
+
groups.each do |g|
|
14
|
+
unless filtered_groups.include?(g)
|
15
|
+
Rivet::Log.debug("Creating security group #{g}")
|
16
|
+
security_groups_collection.create g
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.config_parser
|
22
|
+
if ENV['AWS_CONFIG_FILE']
|
23
|
+
|
24
|
+
current_profile = nil
|
25
|
+
profile_matcher = /^\[(.*)\]/
|
26
|
+
option_matcher = /(\w.*)=(\S.*)\s*/
|
27
|
+
aws_config = Hash.new
|
28
|
+
|
29
|
+
File.open(ENV['AWS_CONFIG_FILE'],"r").each_line do |line|
|
30
|
+
|
31
|
+
if line =~ profile_matcher
|
32
|
+
current_profile = line.match(profile_matcher)[1]
|
33
|
+
aws_config[current_profile] = Hash.new unless aws_config.has_key?(current_profile)
|
34
|
+
end
|
35
|
+
|
36
|
+
if line =~ option_matcher && !current_profile.nil?
|
37
|
+
results = line.match(option_matcher)
|
38
|
+
|
39
|
+
# Normalize the option name so it can be used with the AWS SDK
|
40
|
+
if results[1] =~ /^\S*aws_/
|
41
|
+
option = results[1].gsub("aws_",'').to_sym
|
42
|
+
else
|
43
|
+
option = results[1].to_sym
|
44
|
+
end
|
45
|
+
|
46
|
+
value = results[2]
|
47
|
+
aws_config[current_profile].merge!({ option => value})
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
aws_config
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.set_aws_credentials(profile)
|
56
|
+
Rivet::Log.info("Settings AWS credentials to #{profile} profile")
|
57
|
+
settings = config_parser
|
58
|
+
aws_creds = nil
|
59
|
+
|
60
|
+
if settings && settings.has_key?(profile)
|
61
|
+
aws_creds = [:access_key_id,:secret_access_key,:region].inject({})do |accum,option|
|
62
|
+
if settings[profile].has_key?(option)
|
63
|
+
accum[option] = settings[profile][option]
|
64
|
+
end
|
65
|
+
accum
|
66
|
+
end
|
67
|
+
|
68
|
+
AWS.config(aws_creds) if aws_creds
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|