kitchen-scalr 0.1.0.dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.cane +0 -0
- data/.gitignore +17 -0
- data/.tailor +4 -0
- data/.travis.yml +11 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +3 -0
- data/LICENSE +202 -0
- data/README.md +82 -0
- data/Rakefile +21 -0
- data/kitchen-scalr.gemspec +30 -0
- data/lib/kitchen/driver/ScalrAPI.rb +121 -0
- data/lib/kitchen/driver/dbapi.rb +114 -0
- data/lib/kitchen/driver/scalr.rb +381 -0
- data/lib/kitchen/driver/scalr_cred.rb +66 -0
- data/lib/kitchen/driver/scalr_ps_script_template.rb +31 -0
- data/lib/kitchen/driver/scalr_ssh_script_template.rb +10 -0
- data/lib/kitchen/driver/scalr_version.rb +26 -0
- metadata +173 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 395a24f60d3d485680b14642a36cc87fd2d1d296
|
4
|
+
data.tar.gz: e35f597abfbb74632927c7dbb20a5b9af66a5cff
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 30e30d1f60065b5644dd9ba2b3dcf6add87cb996beaeec386185fd7c460f9339aec4c30fb73dfc5f599771007000e995e78aff9acd0d5896de83798186de2a02
|
7
|
+
data.tar.gz: f619d3f569c5902bf917b9a5bd9dd3b2b1393c7e0514b5423195dbc06360018d1c9eb4e26ca01e5808fc813d9998abde14439fd11cd6875a1d182203b4a7e50e
|
data/.cane
ADDED
File without changes
|
data/.gitignore
ADDED
data/.tailor
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright 2016 Scalr, Inc
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# <a name="title"></a> Kitchen::Scalr
|
2
|
+
|
3
|
+
A Test Kitchen Driver for Scalr. This driver creates an instance on Scalr by creating a Farm containing a single Farm Role and granting Test Kitchen access to the corresponding server. It can work in two modes:
|
4
|
+
* **Image Mode:** (default) The user provides an image name and the driver will automatically create a role corresponding to this image as well as instanciate this role in a farm.
|
5
|
+
* **Role Mode:** the user provides a role id and the driver will instanciate it in a farm
|
6
|
+
|
7
|
+
## <a name="installation"></a> Installation and Setup
|
8
|
+
|
9
|
+
Please read the [Driver usage][driver_usage] page for more details.
|
10
|
+
|
11
|
+
## <a name="config"></a> Configuration
|
12
|
+
### scalr_api_url
|
13
|
+
**Required** This is the URL of the Scalr server that will be reached by the driver.
|
14
|
+
### scalr_env_id
|
15
|
+
**Required** This is a string corresponding to the environment id used by the plugin.
|
16
|
+
### scalr_api_key_id and scalr_api_key_secret
|
17
|
+
**Required except on macOS and Windows** These are respectively the API KEY ID and API KEY secret used to make the API calls to Scalr. This option **SHOULD NOT** be used on Windows and macOS because kitchen scalr integrates natively with these OSes to ensure secure storage of the Scalr credentials. In this case, Scalr will prompt for credentials at the first use, and memorize them for further calls.
|
18
|
+
### scalr_project_id
|
19
|
+
**Required** This is a string corresponding to the project identifier used to create the farm in Scalr. This is used in Scalr for accountability and cost management.
|
20
|
+
### scalr_use_role
|
21
|
+
**Optional** Setting this option to an integer corresponding to a role id will trigger Role mode with the provided role identifier. If this option is not set, the driver will work in Image mode.
|
22
|
+
### scalr_server_image
|
23
|
+
**Required in Image mode** This is a string corresponding to the image name used to instanciate the server.
|
24
|
+
### scalr_server_instanceType
|
25
|
+
**Required** This is a string corresponding to the instance type of the VMs in the underlying cloud. Example: 'm3.medium'
|
26
|
+
### scalr_platform
|
27
|
+
**Required in Role mode** This is the identifier of the underlying cloud platform. Examples: "ec2", "gce", "openstack".
|
28
|
+
### scalr_location
|
29
|
+
**Required** This is a string corresponding to the cloud location used to create the instance. Example: "us-east-1"
|
30
|
+
|
31
|
+
## Configuration example
|
32
|
+
---
|
33
|
+
driver:
|
34
|
+
name: scalr
|
35
|
+
|
36
|
+
provisioner:
|
37
|
+
name: chef_zero
|
38
|
+
|
39
|
+
verifier:
|
40
|
+
name: inspec
|
41
|
+
|
42
|
+
platforms:
|
43
|
+
- name: ubuntu-14.04
|
44
|
+
driver:
|
45
|
+
scalr_api_url: 'http://my.scalr.com'
|
46
|
+
scalr_env_id: '2'
|
47
|
+
scalr_project_id: '30c59dba-fc9b-4d0f-83ec-4b5043b12f72'
|
48
|
+
scalr_server_instanceType: 'm3.medium'
|
49
|
+
scalr_use_role: 12345
|
50
|
+
scalr_platform: 'ec2'
|
51
|
+
scalr_location: 'us-east-1'
|
52
|
+
|
53
|
+
## <a name="development"></a> Development
|
54
|
+
|
55
|
+
* Source hosted at [GitHub][repo]
|
56
|
+
* Report issues/questions/feature requests on [GitHub Issues][issues]
|
57
|
+
|
58
|
+
Pull requests are very welcome! Make sure your patches are well tested.
|
59
|
+
Ideally create a topic branch for every separate change you make. For
|
60
|
+
example:
|
61
|
+
|
62
|
+
1. Fork the repo
|
63
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
64
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
65
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
66
|
+
5. Create new Pull Request
|
67
|
+
|
68
|
+
## <a name="authors"></a> Authors
|
69
|
+
|
70
|
+
Created and maintained by [Mohammed HAWARI][author] (<mohammed@hawari.fr>)
|
71
|
+
|
72
|
+
## <a name="license"></a> License
|
73
|
+
|
74
|
+
Apache 2.0 (see [LICENSE][license])
|
75
|
+
|
76
|
+
|
77
|
+
[author]: https://github.com/momohawari
|
78
|
+
[issues]: https://github.com/momohawari/kitchen-scalr/issues
|
79
|
+
[license]: https://github.com/momohawari/kitchen-scalr/blob/master/LICENSE
|
80
|
+
[repo]: https://github.com/momohawari/kitchen-scalr
|
81
|
+
[driver_usage]: http://kitchen.ci/docs/getting-started/adding-platform
|
82
|
+
[chef_omnibus_dl]: http://www.chef.io/chef/install/
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'cane/rake_task'
|
3
|
+
require 'tailor/rake_task'
|
4
|
+
|
5
|
+
desc "Run cane to check quality metrics"
|
6
|
+
Cane::RakeTask.new do |cane|
|
7
|
+
cane.canefile = './.cane'
|
8
|
+
end
|
9
|
+
|
10
|
+
Tailor::RakeTask.new
|
11
|
+
|
12
|
+
desc "Display LOC stats"
|
13
|
+
task :stats do
|
14
|
+
puts "\n## Production Code Stats"
|
15
|
+
sh "countloc -r lib"
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Run all quality tasks"
|
19
|
+
task :quality => [:cane, :tailor, :stats]
|
20
|
+
|
21
|
+
task :default => [:quality]
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'kitchen/driver/scalr_version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'kitchen-scalr'
|
8
|
+
spec.version = Kitchen::Driver::SCALR_VERSION
|
9
|
+
spec.authors = ['Mohammed HAWARI']
|
10
|
+
spec.email = ['mohammed@hawari.fr']
|
11
|
+
spec.description = %q{A Test Kitchen Driver for Scalr}
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'Apache 2.0'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = []
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'test-kitchen'
|
22
|
+
spec.add_dependency 'rest-client'
|
23
|
+
spec.add_dependency 'os'
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
|
27
|
+
spec.add_development_dependency 'cane'
|
28
|
+
spec.add_development_dependency 'tailor'
|
29
|
+
spec.add_development_dependency 'countloc'
|
30
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'time'
|
3
|
+
require 'openssl'
|
4
|
+
require 'base64'
|
5
|
+
require 'rest-client'
|
6
|
+
|
7
|
+
class ScalrAPI
|
8
|
+
|
9
|
+
def initialize(url, key_id, key_secret)
|
10
|
+
|
11
|
+
@api_url = url
|
12
|
+
@api_key_id = key_id
|
13
|
+
@api_key_secret = key_secret
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def request(method, url, body='')
|
18
|
+
|
19
|
+
#JSON encode body if set
|
20
|
+
if body != ''
|
21
|
+
body = body.to_json
|
22
|
+
end
|
23
|
+
|
24
|
+
#Split URL into components
|
25
|
+
parts = URI.parse(@api_url + url)
|
26
|
+
|
27
|
+
path = parts.path
|
28
|
+
host = parts.host
|
29
|
+
port = parts.port
|
30
|
+
|
31
|
+
query = ''
|
32
|
+
if parts.query != nil
|
33
|
+
#Convert querystring into an array
|
34
|
+
q = parts.query.split('&')
|
35
|
+
|
36
|
+
#Sort the querystring array
|
37
|
+
q.sort!
|
38
|
+
|
39
|
+
#Convert querystring array back to string
|
40
|
+
query = q.join('&')
|
41
|
+
end
|
42
|
+
|
43
|
+
#Create ISO 8601 date/time string
|
44
|
+
time = Time.now.utc.iso8601 + '+00:00'
|
45
|
+
|
46
|
+
#Collection of request data for generating signature
|
47
|
+
request = [
|
48
|
+
method,
|
49
|
+
time,
|
50
|
+
path,
|
51
|
+
query,
|
52
|
+
body
|
53
|
+
]
|
54
|
+
|
55
|
+
#Calculate signature based on request data
|
56
|
+
signature = 'V1-HMAC-SHA256 ' + Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), @api_key_secret, request.join("\n"))).strip()
|
57
|
+
|
58
|
+
#HTTP request headers
|
59
|
+
headers = {
|
60
|
+
'X-Scalr-Key-Id' => @api_key_id,
|
61
|
+
'X-Scalr-Signature' => signature,
|
62
|
+
'X-Scalr-Date' => time,
|
63
|
+
'X-Scalr-Debug' => '1'
|
64
|
+
}
|
65
|
+
|
66
|
+
if body != ""
|
67
|
+
headers['Content-Type'] = 'application/json'
|
68
|
+
end
|
69
|
+
|
70
|
+
response = ::RestClient::Request.execute(
|
71
|
+
:method => method,
|
72
|
+
:url => @api_url + url,
|
73
|
+
:headers => headers,
|
74
|
+
:payload => body
|
75
|
+
)
|
76
|
+
if response == ""
|
77
|
+
response = "{}"
|
78
|
+
end
|
79
|
+
return JSON.parse(response)
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
#List items from API
|
84
|
+
def list(url)
|
85
|
+
data = []
|
86
|
+
|
87
|
+
while url != nil do
|
88
|
+
response = self.request('GET', url)
|
89
|
+
|
90
|
+
data.concat response['data']
|
91
|
+
url = response['pagination']['next']
|
92
|
+
end
|
93
|
+
|
94
|
+
return data
|
95
|
+
end
|
96
|
+
|
97
|
+
#Fetch a single item from API
|
98
|
+
def fetch(url)
|
99
|
+
response = self.request('GET', url)
|
100
|
+
return response['data']
|
101
|
+
end
|
102
|
+
|
103
|
+
#Create item in API
|
104
|
+
def create(url, data)
|
105
|
+
response = self.request('POST', url, data)
|
106
|
+
return response['data']
|
107
|
+
end
|
108
|
+
|
109
|
+
#Delete item from API
|
110
|
+
def delete(url)
|
111
|
+
response = self.request('DELETE', url)
|
112
|
+
return true
|
113
|
+
end
|
114
|
+
|
115
|
+
#Edit items in API
|
116
|
+
def post(url, data)
|
117
|
+
response = self.request('POST', url, data)
|
118
|
+
return response['data']
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
# Minimal wrapper around Microsoft's DPAPI
|
4
|
+
#
|
5
|
+
# struct & function definitions cribbed from...
|
6
|
+
# http://msdn.microsoft.com/en-us/library/ms995355.aspx
|
7
|
+
|
8
|
+
module DPAPI
|
9
|
+
extend FFI::Library
|
10
|
+
ffi_lib 'crypt32'
|
11
|
+
|
12
|
+
class EncryptError < StandardError; end
|
13
|
+
class DecryptError < StandardError; end
|
14
|
+
|
15
|
+
=begin
|
16
|
+
typedef struct _CRYPTOAPI_BLOB {
|
17
|
+
DWORD cbData;
|
18
|
+
BYTE *pbData;
|
19
|
+
} DATA_BLOB;
|
20
|
+
=end
|
21
|
+
class DataBlob < FFI::Struct
|
22
|
+
layout :cbData, :uint32,
|
23
|
+
:pbData, :pointer
|
24
|
+
|
25
|
+
def initialize blob=nil
|
26
|
+
super()
|
27
|
+
self.data = blob unless blob.nil?
|
28
|
+
end
|
29
|
+
|
30
|
+
def data
|
31
|
+
self[:pbData].get_bytes(0, self[:cbData])
|
32
|
+
end
|
33
|
+
|
34
|
+
def data= blob
|
35
|
+
self[:pbData] = FFI::MemoryPointer.from_string blob
|
36
|
+
self[:cbData] = blob.bytesize
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
# http://www.pinvoke.net/default.aspx/Enums/CryptProtectFlags.html
|
42
|
+
# dwFlags is a bitvector with the following values...
|
43
|
+
UI_FORBIDDEN = 0x1
|
44
|
+
LOCAL_MACHINE = 0x4
|
45
|
+
CRED_SYNC = 0x8
|
46
|
+
AUDIT = 0x10
|
47
|
+
NO_RECOVERY = 0x20
|
48
|
+
VERIFY_PROTECTION = 0x40
|
49
|
+
|
50
|
+
=begin
|
51
|
+
BOOL WINAPI CryptProtectData(
|
52
|
+
_In_ DATA_BLOB *pDataIn,
|
53
|
+
_In_ LPCWSTR szDataDescr,
|
54
|
+
_In_ DATA_BLOB *pOptionalEntropy,
|
55
|
+
_In_ PVOID pvReserved,
|
56
|
+
_In_opt_ CRYPTPROTECT_PROMPTSTRUCT *pPromptStruct,
|
57
|
+
_In_ DWORD dwFlags,
|
58
|
+
_Out_ DATA_BLOB *pDataOut
|
59
|
+
);
|
60
|
+
=end
|
61
|
+
|
62
|
+
attach_function :CryptProtectData,
|
63
|
+
[:pointer, :string, :pointer, :pointer, :pointer, :uint32, :pointer],
|
64
|
+
:int32
|
65
|
+
|
66
|
+
def encrypt plaintext, entropy=nil, flags = [], desc=nil
|
67
|
+
ciphertext_blob = DataBlob.new
|
68
|
+
|
69
|
+
CryptProtectData(DataBlob.new(plaintext),
|
70
|
+
desc,
|
71
|
+
entropy.nil? ? nil : DataBlob.new(entropy),
|
72
|
+
nil,
|
73
|
+
nil,
|
74
|
+
flags.reduce(0, :|),
|
75
|
+
ciphertext_blob) or
|
76
|
+
raise EncryptErorr
|
77
|
+
|
78
|
+
ciphertext_blob.data
|
79
|
+
end
|
80
|
+
|
81
|
+
=begin
|
82
|
+
BOOL WINAPI CryptUnprotectData(
|
83
|
+
_In_ DATA_BLOB *pDataIn,
|
84
|
+
_Out_opt_ LPWSTR *ppszDataDescr,
|
85
|
+
_In_opt_ DATA_BLOB *pOptionalEntropy,
|
86
|
+
_Reserved_ PVOID pvReserved,
|
87
|
+
_In_opt_ CRYPTPROTECT_PROMPTSTRUCT *pPromptStruct,
|
88
|
+
_In_ DWORD dwFlags,
|
89
|
+
_Out_ DATA_BLOB *pDataOut
|
90
|
+
);
|
91
|
+
=end
|
92
|
+
attach_function :CryptUnprotectData,
|
93
|
+
[:pointer, :pointer, :pointer, :pointer, :pointer, :uint32, :pointer],
|
94
|
+
:int32
|
95
|
+
|
96
|
+
def decrypt ciphertext, entropy=nil, flags=[]
|
97
|
+
plaintext_blob = DataBlob.new
|
98
|
+
desc = FFI::MemoryPointer.new(:pointer, 256)
|
99
|
+
|
100
|
+
CryptUnprotectData(DataBlob.new(ciphertext),
|
101
|
+
desc,
|
102
|
+
DataBlob.new(entropy),
|
103
|
+
nil,
|
104
|
+
nil,
|
105
|
+
flags.reduce(0, :|),
|
106
|
+
plaintext_blob) or
|
107
|
+
raise DecryptError
|
108
|
+
|
109
|
+
[plaintext_blob.data,
|
110
|
+
desc.read_pointer.nil? ? nil : desc.read_pointer.read_string
|
111
|
+
]
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
@@ -0,0 +1,381 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Author:: Mohammed HAWARI (<mohammed@hawari.fr>)
|
4
|
+
#
|
5
|
+
# Copyright (C) 2016, Mohammed HAWARI
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
|
19
|
+
require 'kitchen'
|
20
|
+
require 'kitchen/driver/ScalrAPI'
|
21
|
+
require "kitchen/driver/scalr_version"
|
22
|
+
require "kitchen/driver/scalr_ssh_script_template"
|
23
|
+
require "kitchen/driver/scalr_cred"
|
24
|
+
require "kitchen/driver/scalr_ps_script_template"
|
25
|
+
require "json"
|
26
|
+
require 'os'
|
27
|
+
require 'securerandom'
|
28
|
+
|
29
|
+
module Kitchen
|
30
|
+
|
31
|
+
module Driver
|
32
|
+
|
33
|
+
# Scalr driver for Kitchen.
|
34
|
+
#
|
35
|
+
# @author Mohammed HAWARI <mohammed@hawari.fr>
|
36
|
+
class Scalr < Kitchen::Driver::Base
|
37
|
+
include CredentialsManager
|
38
|
+
|
39
|
+
kitchen_driver_api_version 2
|
40
|
+
|
41
|
+
plugin_version Kitchen::Driver::SCALR_VERSION
|
42
|
+
|
43
|
+
default_config :scalr_api_url, ''
|
44
|
+
|
45
|
+
default_config :scalr_api_key_id, ''
|
46
|
+
|
47
|
+
default_config :scalr_api_key_secret, ''
|
48
|
+
|
49
|
+
default_config :scalr_env_id, ''
|
50
|
+
|
51
|
+
default_config :scalr_project_id, ''
|
52
|
+
|
53
|
+
default_config :scalr_ssh_key_filename, ''
|
54
|
+
|
55
|
+
default_config :scalr_server_status_polling_period, 10
|
56
|
+
|
57
|
+
default_config :scalr_server_status_polling_timeout, 600
|
58
|
+
|
59
|
+
default_config :scalr_server_image, ''
|
60
|
+
|
61
|
+
default_config :scalr_server_instanceType, ''
|
62
|
+
|
63
|
+
default_config :scalr_use_role, -1
|
64
|
+
|
65
|
+
default_config :scalr_platform, ''
|
66
|
+
|
67
|
+
default_config :scalr_location, ''
|
68
|
+
|
69
|
+
def create(state)
|
70
|
+
if config[:scalr_api_key_id]==''
|
71
|
+
#We have to find some other way of getting the credentials
|
72
|
+
loadCredentials
|
73
|
+
end
|
74
|
+
#Create a Scalr API object
|
75
|
+
scalr_api = ScalrAPI.new(config[:scalr_api_url], config[:scalr_api_key_id], config[:scalr_api_key_secret])
|
76
|
+
#Create a farm
|
77
|
+
state[:suuid] = SecureRandom.uuid
|
78
|
+
uuid = 'KITCHEN_FARM_' + instance.name + "_" + state[:suuid]
|
79
|
+
createFarmObject = {
|
80
|
+
'name' => uuid,
|
81
|
+
'description' => 'Test Kitchen Farm',
|
82
|
+
'project' => {
|
83
|
+
'id' => config[:scalr_project_id]
|
84
|
+
}
|
85
|
+
}
|
86
|
+
puts 'Creating farm with name: %s' % [uuid]
|
87
|
+
response = scalr_api.create('/api/v1beta0/user/%s/farms/' % [config[:scalr_env_id] ], createFarmObject)
|
88
|
+
state[:farmId] = response['id']
|
89
|
+
puts 'Success: farmId is %d' % [state[:farmId]]
|
90
|
+
if config[:scalr_use_role] == -1
|
91
|
+
createCustomRole(scalr_api, state)
|
92
|
+
else
|
93
|
+
state[:roleId] = config[:scalr_use_role]
|
94
|
+
state[:imagePlatform] = config[:scalr_platform]
|
95
|
+
state[:imageLocation] = config[:scalr_location]
|
96
|
+
end
|
97
|
+
#Now create the farm role object
|
98
|
+
puts "Creating the Farm Role"
|
99
|
+
fruuid = "KITCHEN-ROLE-" + state[:suuid]
|
100
|
+
farmRoleObject = {
|
101
|
+
"alias" => fruuid,
|
102
|
+
"placement" => {
|
103
|
+
"placementConfigurationType" => placementConfigurationType(state[:imagePlatform]),
|
104
|
+
"region" => state[:imageLocation]
|
105
|
+
},
|
106
|
+
"instance" => {
|
107
|
+
"instanceConfigurationType" => instanceConfigurationType(state[:imagePlatform]),
|
108
|
+
"instanceType" => {
|
109
|
+
"id" => config[:scalr_server_instanceType]
|
110
|
+
}
|
111
|
+
},
|
112
|
+
"platform" => state[:imagePlatform],
|
113
|
+
"role" => {
|
114
|
+
"id" => state[:roleId]
|
115
|
+
},
|
116
|
+
"scaling" => {
|
117
|
+
"considerSuspendedServers" => "running",
|
118
|
+
"enabled" => true,
|
119
|
+
"maxInstances" => 1,
|
120
|
+
"minInstances" => 1,
|
121
|
+
"scalingBehavior" => "launch-terminate",
|
122
|
+
"rules" => []
|
123
|
+
}
|
124
|
+
}
|
125
|
+
response = scalr_api.create('/api/v1beta0/user/%s/farms/%d/farm-roles/' % [config[:scalr_env_id], state[:farmId]], farmRoleObject)
|
126
|
+
puts "Farm Role created"
|
127
|
+
state[:farmRoleId] = response['id']
|
128
|
+
#Start the farm now
|
129
|
+
response = scalr_api.post('/api/v1beta0/user/%s/farms/%d/actions/launch/' % [config[:scalr_env_id], state[:farmId]], {})
|
130
|
+
state[:farmLaunched] = 1
|
131
|
+
#Keep polling for server status
|
132
|
+
wait_for_status(scalr_api, state, 'running')
|
133
|
+
#Generate and upload credentials to the instance
|
134
|
+
setup_credentials(scalr_api,state)
|
135
|
+
#Finally get the IP address
|
136
|
+
response = scalr_api.list('/api/v1beta0/user/%s/farms/%d/servers/' % [config[:scalr_env_id], state[:farmId]] )
|
137
|
+
if response.size == 0 then
|
138
|
+
raise "No running server in the farm!"
|
139
|
+
end
|
140
|
+
state[:hostname] = response[0]['publicIp'][0]
|
141
|
+
#state[:port] = 22
|
142
|
+
#state[:username] = 'root'
|
143
|
+
#state[:password] =
|
144
|
+
state[:ssh_key] = state[:keyfileName]
|
145
|
+
#state[:proxy_command] =
|
146
|
+
#state[:rdp_port] =
|
147
|
+
end
|
148
|
+
|
149
|
+
def cleanup_scalr(scalr_api, state)
|
150
|
+
puts "Starting the tear-down process"
|
151
|
+
if state.key?(:farmLaunched)
|
152
|
+
puts "A running server is here, terminate the farm"
|
153
|
+
scalr_api.post('/api/v1beta0/user/%s/farms/%d/actions/terminate/' % [config[:scalr_env_id], state[:farmId]], {})
|
154
|
+
state.delete(:hostname)
|
155
|
+
state.delete(:port)
|
156
|
+
state.delete(:username)
|
157
|
+
state.delete(:ssh_key)
|
158
|
+
state.delete(:farmLaunched)
|
159
|
+
end
|
160
|
+
if state.key?(:farmRoleId)
|
161
|
+
puts "Now waiting until all the servers are terminated..."
|
162
|
+
wait_for_empty(scalr_api, '/api/v1beta0/user/%s/farms/%d/servers/' % [config[:scalr_env_id], state[:farmId]])
|
163
|
+
puts "...Done"
|
164
|
+
puts "Cleanup of the farm role..."
|
165
|
+
scalr_api.delete('/api/v1beta0/user/%s/farm-roles/%d/' % [config[:scalr_env_id], state[:farmRoleId]])
|
166
|
+
puts '...Done'
|
167
|
+
state.delete(:farmRoleId)
|
168
|
+
end
|
169
|
+
if state.key?(:roleId) && config[:scalr_use_role] == -1
|
170
|
+
puts "Cleanup of the role..."
|
171
|
+
scalr_api.delete('/api/v1beta0/user/%s/roles/%s/' % [config[:scalr_env_id], state[:roleId]])
|
172
|
+
puts '...Done'
|
173
|
+
state.delete(:roleId)
|
174
|
+
end
|
175
|
+
if state.key?(:farmId)
|
176
|
+
puts "Cleanup of the farm..."
|
177
|
+
scalr_api.delete('/api/v1beta0/user/%s/farms/%d/' % [config[:scalr_env_id], state[:farmId]])
|
178
|
+
puts '...Done'
|
179
|
+
state.delete(:farmId)
|
180
|
+
end
|
181
|
+
if state.key?(:scriptId)
|
182
|
+
puts "Cleanup of the script..."
|
183
|
+
scalr_api.delete('/api/v1beta0/user/%s/scripts/%d/' % [config[:scalr_env_id], state[:scriptId]])
|
184
|
+
puts "...Done"
|
185
|
+
state.delete(:scriptId)
|
186
|
+
end
|
187
|
+
if state.key?(:keyfileName)
|
188
|
+
puts "Cleanup of the local keys..."
|
189
|
+
res = `rm -rf #{state[:keyfileName]}`
|
190
|
+
res = `rm -rf #{state[:keyfileName]}.pub`
|
191
|
+
puts "...Done"
|
192
|
+
state.delete(:scriptId)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def wait_for_empty(scalr_api, endpoint)
|
197
|
+
elapsed_time = 0
|
198
|
+
while elapsed_time < config[:scalr_server_status_polling_timeout] do
|
199
|
+
response = scalr_api.list(endpoint)
|
200
|
+
nbOfNonTerminatedServers = 0
|
201
|
+
for s in response
|
202
|
+
if s['status'] != 'terminated'
|
203
|
+
nbOfNonTerminatedServers += 1
|
204
|
+
end
|
205
|
+
end
|
206
|
+
if (nbOfNonTerminatedServers == 0) then
|
207
|
+
return
|
208
|
+
end
|
209
|
+
puts "Still %d servers." % [nbOfNonTerminatedServers]
|
210
|
+
sleep config[:scalr_server_status_polling_period]
|
211
|
+
elapsed_time += config[:scalr_server_status_polling_period]
|
212
|
+
puts "Elapsed time: %d seconds. Still polling for number of servers in farm" % [elapsed_time]
|
213
|
+
end
|
214
|
+
raise "Timeout! And some servers are still running...Try later"
|
215
|
+
end
|
216
|
+
|
217
|
+
def destroy(state)
|
218
|
+
if config[:scalr_api_key_id]==''
|
219
|
+
#We have to find some other way of getting the credentials
|
220
|
+
loadCredentials
|
221
|
+
end
|
222
|
+
scalr_api = ScalrAPI.new(config[:scalr_api_url], config[:scalr_api_key_id], config[:scalr_api_key_secret])
|
223
|
+
cleanup_scalr(scalr_api, state)
|
224
|
+
end
|
225
|
+
|
226
|
+
def wait_for_status(scalr_api,state, status)
|
227
|
+
elapsed_time = 0
|
228
|
+
puts 'Waiting for server to be %s.' % [status]
|
229
|
+
while elapsed_time < config[:scalr_server_status_polling_timeout] do
|
230
|
+
response = scalr_api.list('/api/v1beta0/user/%s/farms/%d/servers/' % [config[:scalr_env_id], state[:farmId]] )
|
231
|
+
if (response.size > 0 && response[0]['status'] == status) then
|
232
|
+
puts 'Server is %s!' % [response[0]['status']]
|
233
|
+
return
|
234
|
+
end
|
235
|
+
if (response.size > 0) then
|
236
|
+
puts 'Server is still %s.' % [response[0]['scalrAgent']['reachabilityStatus']['status']]
|
237
|
+
end
|
238
|
+
sleep config[:scalr_server_status_polling_period]
|
239
|
+
elapsed_time += config[:scalr_server_status_polling_period]
|
240
|
+
puts "Elapsed time: %d seconds. Still polling for server status" % [elapsed_time]
|
241
|
+
end
|
242
|
+
raise "Server status timeout!"
|
243
|
+
end
|
244
|
+
|
245
|
+
def placementConfigurationType(cloudPlatform)
|
246
|
+
return {
|
247
|
+
"ec2" => "AwsClassicPlacementConfiguration",
|
248
|
+
"openstack" => "OpenStackPlacementConfiguration",
|
249
|
+
"gce" => "GcePlacementConfiguration",
|
250
|
+
"cloudstack" => "CloudStackPlacementConfiguration"
|
251
|
+
}[cloudPlatform]
|
252
|
+
end
|
253
|
+
|
254
|
+
def instanceConfigurationType(cloudPlatform)
|
255
|
+
return {
|
256
|
+
"ec2" => "AwsInstanceConfiguration"
|
257
|
+
}[cloudPlatform]
|
258
|
+
end
|
259
|
+
|
260
|
+
def createCustomRole(scalr_api,state)
|
261
|
+
#Get the imageId for the provided image
|
262
|
+
puts 'Getting the imageId for image %s' % [config[:scalr_server_image]]
|
263
|
+
response = scalr_api.list('/api/v1beta0/user/%s/images/?name=%s' % [config[:scalr_env_id], config[:scalr_server_image] ])
|
264
|
+
if response.size == 0 then
|
265
|
+
raise 'No matching image was found in this environment!'
|
266
|
+
end
|
267
|
+
state[:imageId] = response[0]['id']
|
268
|
+
state[:imageOsId] = response[0]['os']['id']
|
269
|
+
state[:imagePlatform] = response[0]['cloudPlatform']
|
270
|
+
state[:imageLocation] = response[0]['cloudLocation']
|
271
|
+
puts 'The image id is %s' % [state[:imageId]]
|
272
|
+
puts 'The image os id is %s' % [state[:imageOsId]]
|
273
|
+
puts 'The image platform is %s' % [state[:imagePlatform]]
|
274
|
+
puts 'The image Location is %s' % [state[:imageLocation]]
|
275
|
+
#Create a matching role on the fly
|
276
|
+
ruuid = 'KITCHEN-ROLE-' + state[:suuid]
|
277
|
+
roleObject = {
|
278
|
+
"builtinAutomation" => ["base"],
|
279
|
+
"category" => {
|
280
|
+
"id" => 1
|
281
|
+
},
|
282
|
+
"deprecated" => false,
|
283
|
+
"description" => "test kitchen role",
|
284
|
+
"name" => ruuid,
|
285
|
+
"os" => {
|
286
|
+
"id" => state[:imageOsId]
|
287
|
+
},
|
288
|
+
"quickStart" => false,
|
289
|
+
"useScalrAgent" => true
|
290
|
+
}
|
291
|
+
puts 'Creating a role with name %s' % [ruuid]
|
292
|
+
response = scalr_api.create('/api/v1beta0/user/%s/roles/' % [config[:scalr_env_id] ], roleObject)
|
293
|
+
state[:roleId] = response['id']
|
294
|
+
puts 'The role id is %d' % [state[:roleId]]
|
295
|
+
#Create a RoleImage matching
|
296
|
+
roleImageObject = {
|
297
|
+
"image" => {
|
298
|
+
"id" => state[:imageId],
|
299
|
+
},
|
300
|
+
"role" => {
|
301
|
+
"id" => state[:roleId]
|
302
|
+
}
|
303
|
+
}
|
304
|
+
response = scalr_api.create('/api/v1beta0/user/%s/roles/%d/images/' % [config[:scalr_env_id], state[:roleId]], roleImageObject)
|
305
|
+
puts "RoleImage association created"
|
306
|
+
end
|
307
|
+
|
308
|
+
def setup_credentials(scalr_api,state)
|
309
|
+
response = scalr_api.list('/api/v1beta0/user/%s/farms/%d/servers/' % [config[:scalr_env_id], state[:farmId]])
|
310
|
+
state[:serverId] = response[0]['id']
|
311
|
+
#Handle the Linux case
|
312
|
+
#Generate a key
|
313
|
+
if !windows_os? then
|
314
|
+
keyfileName = 'KEY_' + state[:suuid]
|
315
|
+
state[:username] = 'root'
|
316
|
+
state[:keyfileName] = keyfileName
|
317
|
+
puts "Generating a key named %s" % [keyfileName]
|
318
|
+
res = `yes | ssh-keygen -q -f #{keyfileName} -N ""`
|
319
|
+
f = File.open(keyfileName + ".pub")
|
320
|
+
scriptData = Kitchen::Driver::SCALR_SSH_SCRIPT % { :ssh_pub_key => f.read }
|
321
|
+
f.close
|
322
|
+
state[:scriptOsType] = "linux"
|
323
|
+
else
|
324
|
+
instance_password = SecureRandom.urlsafe_base64(20)
|
325
|
+
instance_username = "adminchef"
|
326
|
+
scriptData = Kitchen::Driver::SCALR_PS_SCRIPT % {:username => instance_username, :password => instance_password}
|
327
|
+
state[:scriptOsType] = "windows"
|
328
|
+
state[:username] = instance_username
|
329
|
+
state[:password] = instance_password
|
330
|
+
end
|
331
|
+
#Now create a script in Scalr
|
332
|
+
puts "Creating a script in Scalr with this key"
|
333
|
+
response = scalr_api.create('/api/v1beta0/user/%s/scripts/' % [config[:scalr_env_id]],
|
334
|
+
{
|
335
|
+
'name' => 'TestKitchenScript_%s' % [keyfileName],
|
336
|
+
'osType' => state[:scriptOsType]
|
337
|
+
})
|
338
|
+
state[:scriptId] = response['id']
|
339
|
+
puts "Script created with id %s" % [state[:scriptId]]
|
340
|
+
#Now create a script version with the actual body
|
341
|
+
puts "Creating a script version"
|
342
|
+
puts "Script content:"
|
343
|
+
puts scriptData
|
344
|
+
puts "End of script content"
|
345
|
+
response = scalr_api.create('/api/v1beta0/user/%s/scripts/%d/script-versions/' % [config[:scalr_env_id], state[:scriptId]],
|
346
|
+
{
|
347
|
+
'body' => scriptData,
|
348
|
+
'script' => {
|
349
|
+
'id' => state[:scriptId]
|
350
|
+
}
|
351
|
+
})
|
352
|
+
puts "Script version created"
|
353
|
+
#Finally try and execute the script
|
354
|
+
puts "Executing the script"
|
355
|
+
response = scalr_api.create('/api/v1beta0/user/%s/scripts/%d/actions/execute/' % [config[:scalr_env_id], state[:scriptId]],
|
356
|
+
{
|
357
|
+
'server' => {
|
358
|
+
'id' => state[:serverId]
|
359
|
+
}
|
360
|
+
})
|
361
|
+
state[:scriptExecutionId] = response['id']
|
362
|
+
puts "Execution started with id %s" % [state[:scriptExecutionId]]
|
363
|
+
#Wait for execution to be complete
|
364
|
+
elapsed_time = 0
|
365
|
+
"Waiting for execution to be finished"
|
366
|
+
while (elapsed_time < config[:scalr_server_status_polling_timeout]) do
|
367
|
+
puts "%d seconds elapsed. Polling" % [elapsed_time]
|
368
|
+
response = scalr_api.fetch('/api/v1beta0/user/%s/script-executions/%s/' % [config[:scalr_env_id], state[:scriptExecutionId]])
|
369
|
+
if (response['status'] == 'finished')
|
370
|
+
puts "Script execution has finished."
|
371
|
+
return
|
372
|
+
end
|
373
|
+
puts "Script execution is still in %s state" % [response['status']]
|
374
|
+
sleep config[:scalr_server_status_polling_period]
|
375
|
+
elapsed_time += config[:scalr_server_status_polling_period]
|
376
|
+
end
|
377
|
+
raise "Error in script execution"
|
378
|
+
end
|
379
|
+
end
|
380
|
+
end
|
381
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'os'
|
2
|
+
require 'json'
|
3
|
+
if OS.windows? then
|
4
|
+
require 'kitchen/driver/dbapi.rb'
|
5
|
+
end
|
6
|
+
require 'io/console'
|
7
|
+
module Kitchen
|
8
|
+
module Driver
|
9
|
+
module CredentialsManager
|
10
|
+
if OS.windows? then
|
11
|
+
include DPAPI
|
12
|
+
end
|
13
|
+
def loadCredentials()
|
14
|
+
if OS.windows? then
|
15
|
+
credentialsFilename = ENV['APPDATA'] + "\\kitchen_scalr.cred"
|
16
|
+
if File.file?(credentialsFilename) then
|
17
|
+
#Load existing credentials
|
18
|
+
encryptedCred = File.open(credentialsFilename, "rb") {|f| f.read}
|
19
|
+
decryptedJson = decrypt(encryptedCred)
|
20
|
+
cred = JSON.parse(decryptedJson[0])
|
21
|
+
config[:scalr_api_key_id] = cred['API_KEY_ID']
|
22
|
+
config[:scalr_api_key_secret] = cred['API_KEY_SECRET']
|
23
|
+
else
|
24
|
+
#Prompt for credentials
|
25
|
+
print 'Enter your API Key ID: '
|
26
|
+
apiKeyId = STDIN.gets.chomp
|
27
|
+
print 'Enter you API Key secret: '
|
28
|
+
apiKeySecret = STDIN.noecho(&:gets).chomp
|
29
|
+
cred = {
|
30
|
+
'API_KEY_ID' => apiKeyId,
|
31
|
+
'API_KEY_SECRET' => apiKeySecret
|
32
|
+
}
|
33
|
+
decryptedJson = cred.to_json
|
34
|
+
encryptedCred = encrypt(decryptedJson)
|
35
|
+
File.binwrite(credentialsFilename, encryptedCred)
|
36
|
+
config[:scalr_api_key_id] = cred['API_KEY_ID']
|
37
|
+
config[:scalr_api_key_secret] = cred['API_KEY_SECRET']
|
38
|
+
end
|
39
|
+
elsif OS.mac? then
|
40
|
+
credentialsServiceName = "kitchen_scalr.cred"
|
41
|
+
#First, we detect if there is any password in the keychain
|
42
|
+
res = `security find-generic-password -l #{credentialsServiceName} -g >/dev/null 2>/dev/null; echo $?`
|
43
|
+
res = res.chomp
|
44
|
+
if res == '0' then
|
45
|
+
account = `security find-generic-password -l #{credentialsServiceName} | grep acct | awk -F"=" '{print $2}' | sed 's/"//g'`.chomp
|
46
|
+
password = `security find-generic-password -l #{credentialsServiceName} -g 2>&1 | grep password | awk '{print $2}' | sed 's/"//g'`.chomp
|
47
|
+
config[:scalr_api_key_id] = account
|
48
|
+
config[:scalr_api_key_secret] = password
|
49
|
+
else
|
50
|
+
#Prompt for credentials
|
51
|
+
print 'Enter your API Key ID: '
|
52
|
+
apiKeyId = STDIN.gets.chomp
|
53
|
+
print 'Enter you API Key secret: '
|
54
|
+
apiKeySecret = STDIN.noecho(&:gets).chomp
|
55
|
+
#Save those in Keychain
|
56
|
+
res = `security add-generic-password -a #{apiKeyId} -s #{credentialsServiceName} -p #{apiKeySecret}`
|
57
|
+
config[:scalr_api_key_id] = apiKeyId
|
58
|
+
config[:scalr_api_key_secret] = apiKeySecret
|
59
|
+
end
|
60
|
+
else
|
61
|
+
puts 'This OS is currently not supported'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Kitchen
|
2
|
+
module Driver
|
3
|
+
|
4
|
+
SCALR_PS_SCRIPT =
|
5
|
+
'#!powershell
|
6
|
+
$Username = "%{username}"
|
7
|
+
$Password = "%{password}"
|
8
|
+
|
9
|
+
$group = "Administrators"
|
10
|
+
|
11
|
+
$adsi = [ADSI]"WinNT://$env:COMPUTERNAME"
|
12
|
+
$existing = $adsi.Children | where {$_.SchemaClassName -eq \'user\' -and $_.Name -eq $Username }
|
13
|
+
|
14
|
+
if ($existing -eq $null) {
|
15
|
+
|
16
|
+
Write-Host "Creating new local user $Username."
|
17
|
+
& NET USER $Username $Password /add /y /expires:never
|
18
|
+
|
19
|
+
Write-Host "Adding local user $Username to $group."
|
20
|
+
& NET LOCALGROUP $group $Username /add
|
21
|
+
|
22
|
+
}
|
23
|
+
else {
|
24
|
+
Write-Host "Setting password for existing local user $Username."
|
25
|
+
$existing.SetPassword($Password)
|
26
|
+
}
|
27
|
+
|
28
|
+
Write-Host "Ensuring password for $Username never expires."
|
29
|
+
& WMIC USERACCOUNT WHERE "Name=\'$Username\'" SET PasswordExpires=FALSE'
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Author:: Mohammed HAWARI (<mohammed@hawari.fr>)
|
4
|
+
#
|
5
|
+
# Copyright (C) 2016, Mohammed HAWARI
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
|
19
|
+
module Kitchen
|
20
|
+
|
21
|
+
module Driver
|
22
|
+
|
23
|
+
# Version string for Scalr Kitchen driver
|
24
|
+
SCALR_VERSION = "0.1.0.dev"
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kitchen-scalr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.dev
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mohammed HAWARI
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: test-kitchen
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: os
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: cane
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: tailor
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: countloc
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: A Test Kitchen Driver for Scalr
|
126
|
+
email:
|
127
|
+
- mohammed@hawari.fr
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- .cane
|
133
|
+
- .gitignore
|
134
|
+
- .tailor
|
135
|
+
- .travis.yml
|
136
|
+
- CHANGELOG.md
|
137
|
+
- Gemfile
|
138
|
+
- LICENSE
|
139
|
+
- README.md
|
140
|
+
- Rakefile
|
141
|
+
- kitchen-scalr.gemspec
|
142
|
+
- lib/kitchen/driver/ScalrAPI.rb
|
143
|
+
- lib/kitchen/driver/dbapi.rb
|
144
|
+
- lib/kitchen/driver/scalr.rb
|
145
|
+
- lib/kitchen/driver/scalr_cred.rb
|
146
|
+
- lib/kitchen/driver/scalr_ps_script_template.rb
|
147
|
+
- lib/kitchen/driver/scalr_ssh_script_template.rb
|
148
|
+
- lib/kitchen/driver/scalr_version.rb
|
149
|
+
homepage: ''
|
150
|
+
licenses:
|
151
|
+
- Apache 2.0
|
152
|
+
metadata: {}
|
153
|
+
post_install_message:
|
154
|
+
rdoc_options: []
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - '>='
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>'
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 1.3.1
|
167
|
+
requirements: []
|
168
|
+
rubyforge_project:
|
169
|
+
rubygems_version: 2.0.14.1
|
170
|
+
signing_key:
|
171
|
+
specification_version: 4
|
172
|
+
summary: A Test Kitchen Driver for Scalr
|
173
|
+
test_files: []
|