kontena-plugin-upcloud 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +16 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +191 -0
- data/README.md +16 -0
- data/kontena-plugin-upcloud.gemspec +23 -0
- data/lib/kontena/machine/upcloud/cloudinit.yml +65 -0
- data/lib/kontena/machine/upcloud/cloudinit_master.yml +120 -0
- data/lib/kontena/machine/upcloud/master_provisioner.rb +138 -0
- data/lib/kontena/machine/upcloud/node_destroyer.rb +85 -0
- data/lib/kontena/machine/upcloud/node_provisioner.rb +121 -0
- data/lib/kontena/machine/upcloud/node_restarter.rb +49 -0
- data/lib/kontena/machine/upcloud/upcloud_common.rb +74 -0
- data/lib/kontena/machine/upcloud.rb +7 -0
- data/lib/kontena/plugin/upcloud/master/create_command.rb +39 -0
- data/lib/kontena/plugin/upcloud/master_command.rb +9 -0
- data/lib/kontena/plugin/upcloud/node_command.rb +13 -0
- data/lib/kontena/plugin/upcloud/nodes/create_command.rb +40 -0
- data/lib/kontena/plugin/upcloud/nodes/restart_command.rb +20 -0
- data/lib/kontena/plugin/upcloud/nodes/terminate_command.rb +20 -0
- data/lib/kontena/plugin/upcloud.rb +7 -0
- data/lib/kontena/plugin/upcloud_command.rb +11 -0
- data/lib/kontena_cli_plugin.rb +5 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NTQzNDU0M2NmMjI0M2Q4M2FlYTExOTdmYTNhNTJkYjAxNjYxY2VmYg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MjNkZTNjY2FmNThmYWMyMTM0ZjgxZTA0MmMyNGM5MWYzNzk2ZDQzMA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MzZjY2U2OTFiM2I3MmFkZmM2MzI2MTI5N2QyOWNjNjE2ZDY4N2I0NjA0MTQ4
|
10
|
+
YTE1MmY4ZjViYmQ1OTZiNjBkZjQ0ZjkxYzViNmYyMTJiNDNiZmRlYzc1MmE1
|
11
|
+
ZGVmYzIwMTVhNThlOGI4NTU1ZjNjOGYwZTc5M2E2YTY3MGVkMzY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NzEyYzEyMjAyNzVmMzc4ZWY2YzdlNTM0YTc3YzgzM2MzNmI5M2RmMDVmNmY5
|
14
|
+
M2FlNmRhMmVmMmQzOTZmYjdlN2U0NGYxMjk3NGNmMzI0MTBjMmQwNjQzOWQy
|
15
|
+
ZWU3MWMxNTk3YzUwMDE3ZTIxN2U1MGRmNDcyYTVmYjk5M2UxZTk=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.0.0-p648
|
4
|
+
- 2.1.8
|
5
|
+
- 2.2.3
|
6
|
+
- 2.3.1
|
7
|
+
env:
|
8
|
+
- secure: "SWp7F0Gu07m6DYXYNMTL746xXsS1oGmv68XSf/6Af/gdEEPLfllJ0hsHK7D0tiXvtvUFlQ+zQr7WVSYavvdkoaPjTAICD3pL5U7yMla4v6MQl4Mohwr2LwUx9YC18Ij6HIjSsk2EUSqxTyANOqxcRi820nZZUtZeGpUsP0aO/yCyBQOQdLSGOVHi7oUMrKfCjjl9vjrKAOHvsvlM4XvB4EzRM2m2hoxkQBOFWVGRbZXWQUzMuLW1kh1WIScul2ObFWFMz8zBFkizIiEHktwlaqWst66w1464WRv/JcvUrEombyvvoJbeeByguhoa3Y614t1ESYDKH65oUVNQUhlAr1+iUqUJvdulIh2WAuyer3rHytEdXVfs8kbPLcVhqToPTUAV4mzJ1jFWttguDHUh5R4Y6UTw9jVbh+d7lfuE4y3ghwTvciCCdkYTHRHJIzDkOW6pKpOxW0cDaX3J/7Gh8lJ7asLsP16uqbrC3W0gpFBWmMnielDfXzWkrfPlZtR8N75SyHgw/fPHfcqvw1IadrZ8tsyAIHj7afdIhcBrd86UCvGW7feF0RUYlXevxs2aesAnujpJatTp23fCUBsbJywI7DmvuvWLwbTBumI1mEvyAbQh+lIy2oqeK1/3lUtmDkWey21fRt06hippKf40DiAXK4Gzn0HuYkQotc9GHeo="
|
9
|
+
cache: bundler
|
10
|
+
script: bundle install && bundle exec rspec spec/
|
11
|
+
deploy:
|
12
|
+
provider: rubygems
|
13
|
+
api_key: $GEM_TOKEN
|
14
|
+
gem: kontena-plugin-upcloud
|
15
|
+
on:
|
16
|
+
tags: true
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,191 @@
|
|
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
|
+
Copyright 2015 Kontena, Inc.
|
180
|
+
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
182
|
+
you may not use this file except in compliance with the License.
|
183
|
+
You may obtain a copy of the License at
|
184
|
+
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
186
|
+
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
190
|
+
See the License for the specific language governing permissions and
|
191
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Kontena Upcloud Plugin
|
2
|
+
|
3
|
+
This plugin provides support for Upcloud provisioning to Kontena CLI.
|
4
|
+
|
5
|
+
|
6
|
+
## Contributing
|
7
|
+
|
8
|
+
1. Fork it ( https://github.com/kontena/kontena-plugin-upcloud )
|
9
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
10
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
11
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
12
|
+
5. Create a new Pull Request
|
13
|
+
|
14
|
+
## License
|
15
|
+
|
16
|
+
Kontena is licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE.txt) for full license text.
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'kontena/plugin/upcloud'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "kontena-plugin-upcloud"
|
8
|
+
spec.version = Kontena::Plugin::Upcloud::VERSION
|
9
|
+
spec.authors = ["Kontena, Inc."]
|
10
|
+
spec.email = ["info@kontena.io"]
|
11
|
+
|
12
|
+
spec.summary = "Kontena Upcloud plugin"
|
13
|
+
spec.description = "Kontena Upcloud plugin"
|
14
|
+
spec.homepage = "https://github.com/kontena/kontena-plugin-upcloud"
|
15
|
+
spec.license = "Apache-2.0"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_runtime_dependency 'kontena-cli', '>= 0.15.0.rc1'
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#cloud-config
|
2
|
+
write_files:
|
3
|
+
- path: /etc/kontena-agent.env
|
4
|
+
permissions: 0600
|
5
|
+
owner: root
|
6
|
+
content: |
|
7
|
+
KONTENA_URI="<%= master_uri %>"
|
8
|
+
KONTENA_TOKEN="<%= grid_token %>"
|
9
|
+
KONTENA_PEER_INTERFACE=eth1
|
10
|
+
KONTENA_VERSION=<%= version %>
|
11
|
+
- path: /etc/systemd/system/docker.service.d/50-kontena.conf
|
12
|
+
content: |
|
13
|
+
[Service]
|
14
|
+
Environment='DOCKER_OPTS=--insecure-registry="10.81.0.0/19" --bip="172.17.43.1/16"'
|
15
|
+
Environment='DOCKER_CGROUPS=--exec-opt native.cgroupdriver=cgroupfs'
|
16
|
+
- path: /etc/sysctl.d/99-inotify.conf
|
17
|
+
owner: root
|
18
|
+
permissions: 0644
|
19
|
+
content: |
|
20
|
+
fs.inotify.max_user_instances = 8192
|
21
|
+
- path: /etc/resolv.conf
|
22
|
+
permissions: 0644
|
23
|
+
owner: root
|
24
|
+
content: |
|
25
|
+
nameserver 172.17.43.1
|
26
|
+
nameserver 8.8.8.8
|
27
|
+
nameserver 8.8.4.4
|
28
|
+
coreos:
|
29
|
+
units:
|
30
|
+
- name: 10-weave.network
|
31
|
+
runtime: false
|
32
|
+
content: |
|
33
|
+
[Match]
|
34
|
+
Type=bridge
|
35
|
+
Name=weave*
|
36
|
+
|
37
|
+
[Network]
|
38
|
+
- name: kontena-agent.service
|
39
|
+
command: start
|
40
|
+
enable: true
|
41
|
+
content: |
|
42
|
+
[Unit]
|
43
|
+
Description=kontena-agent
|
44
|
+
After=network-online.target
|
45
|
+
After=docker.service
|
46
|
+
Description=Kontena Agent
|
47
|
+
Documentation=http://www.kontena.io/
|
48
|
+
Requires=network-online.target
|
49
|
+
Requires=docker.service
|
50
|
+
|
51
|
+
[Service]
|
52
|
+
Restart=always
|
53
|
+
RestartSec=5
|
54
|
+
EnvironmentFile=/etc/kontena-agent.env
|
55
|
+
ExecStartPre=-/usr/bin/docker stop kontena-agent
|
56
|
+
ExecStartPre=-/usr/bin/docker rm kontena-agent
|
57
|
+
ExecStartPre=/usr/bin/docker pull kontena/agent:${KONTENA_VERSION}
|
58
|
+
ExecStart=/usr/bin/docker run --name kontena-agent \
|
59
|
+
-e KONTENA_URI=${KONTENA_URI} \
|
60
|
+
-e KONTENA_TOKEN=${KONTENA_TOKEN} \
|
61
|
+
-e KONTENA_PEER_INTERFACE=${KONTENA_PEER_INTERFACE} \
|
62
|
+
-v=/var/run/docker.sock:/var/run/docker.sock \
|
63
|
+
-v=/etc/kontena-agent.env:/etc/kontena.env \
|
64
|
+
--net=host \
|
65
|
+
kontena/agent:${KONTENA_VERSION}
|
@@ -0,0 +1,120 @@
|
|
1
|
+
#cloud-config
|
2
|
+
write_files:
|
3
|
+
- path: /etc/kontena-server.env
|
4
|
+
permissions: 0600
|
5
|
+
owner: root
|
6
|
+
content: |
|
7
|
+
KONTENA_VERSION=<%= version %>
|
8
|
+
KONTENA_VAULT_KEY=<%= vault_secret %>
|
9
|
+
KONTENA_VAULT_IV=<%= vault_iv %>
|
10
|
+
<% if ssl_cert %>SSL_CERT="/etc/kontena-server.pem"
|
11
|
+
|
12
|
+
- path: /etc/kontena-server.pem
|
13
|
+
permissions: 0600
|
14
|
+
owner: root
|
15
|
+
content: | <% ssl_cert.split(/\n/).each do |row| %>
|
16
|
+
<%= row %><% end %><% end %>
|
17
|
+
- path: /opt/bin/kontena-haproxy.sh
|
18
|
+
permissions: 0755
|
19
|
+
owner: root
|
20
|
+
content: |
|
21
|
+
#!/bin/sh
|
22
|
+
if [ -n "$SSL_CERT" ]; then
|
23
|
+
SSL_CERT=$(awk 1 ORS='\\n' $SSL_CERT)
|
24
|
+
else
|
25
|
+
SSL_CERT="**None**"
|
26
|
+
fi
|
27
|
+
/usr/bin/docker run --name=kontena-server-haproxy \
|
28
|
+
--link kontena-server-api:kontena-server-api \
|
29
|
+
-e SSL_CERT="$SSL_CERT" \
|
30
|
+
-p 80:80 -p 443:443 kontena/haproxy:latest
|
31
|
+
coreos:
|
32
|
+
units:
|
33
|
+
<% unless mongodb_uri -%>
|
34
|
+
- name: kontena-server-mongo.service
|
35
|
+
command: start
|
36
|
+
enable: true
|
37
|
+
content: |
|
38
|
+
[Unit]
|
39
|
+
Description=kontena-server-mongo
|
40
|
+
After=network-online.target
|
41
|
+
After=docker.service
|
42
|
+
Description=Kontena Server MongoDB
|
43
|
+
Documentation=http://www.mongodb.org/
|
44
|
+
Requires=network-online.target
|
45
|
+
Requires=docker.service
|
46
|
+
|
47
|
+
[Service]
|
48
|
+
Restart=always
|
49
|
+
RestartSec=5
|
50
|
+
ExecStartPre=/usr/bin/docker pull mongo:3.0
|
51
|
+
ExecStartPre=-/usr/bin/docker create --name=kontena-server-mongo-data mongo:3.0
|
52
|
+
ExecStartPre=-/usr/bin/docker stop kontena-server-mongo
|
53
|
+
ExecStartPre=-/usr/bin/docker rm kontena-server-mongo
|
54
|
+
ExecStart=/usr/bin/docker run --name=kontena-server-mongo \
|
55
|
+
--volumes-from=kontena-server-mongo-data \
|
56
|
+
mongo:3.0 mongod --smallfiles
|
57
|
+
<% end -%>
|
58
|
+
- name: kontena-server-api.service
|
59
|
+
command: start
|
60
|
+
enable: true
|
61
|
+
content: |
|
62
|
+
[Unit]
|
63
|
+
Description=kontena-server-api
|
64
|
+
After=network-online.target
|
65
|
+
After=docker.service
|
66
|
+
After=kontena-server-mongo.service
|
67
|
+
Description=Kontena Master
|
68
|
+
Documentation=http://www.kontena.io/
|
69
|
+
Before=kontena-server-haproxy.service
|
70
|
+
Wants=kontena-server-haproxy.service
|
71
|
+
Requires=network-online.target
|
72
|
+
Requires=docker.service
|
73
|
+
<% unless mongodb_uri -%>
|
74
|
+
Requires=kontena-server-mongo.service
|
75
|
+
<% end %>
|
76
|
+
|
77
|
+
[Service]
|
78
|
+
Restart=always
|
79
|
+
RestartSec=5
|
80
|
+
EnvironmentFile=/etc/kontena-server.env
|
81
|
+
EnvironmentFile=-/etc/kontena-server.custom.env
|
82
|
+
ExecStartPre=-/usr/bin/docker stop kontena-server-api
|
83
|
+
ExecStartPre=-/usr/bin/docker rm kontena-server-api
|
84
|
+
ExecStartPre=-/usr/bin/docker pull kontena/server:${KONTENA_VERSION}
|
85
|
+
ExecStart=/usr/bin/docker run --name kontena-server-api \
|
86
|
+
<% if mongodb_uri -%>
|
87
|
+
-e MONGODB_URI=<%= mongodb_uri %> \
|
88
|
+
<% else -%>
|
89
|
+
--link kontena-server-mongo:mongodb \
|
90
|
+
-e MONGODB_URI=mongodb://mongodb:27017/kontena_server \
|
91
|
+
<% end -%>
|
92
|
+
<% if auth_server %>
|
93
|
+
-e AUTH_API_URL=<%= auth_server %> \
|
94
|
+
<% end -%>
|
95
|
+
-e VAULT_KEY=${KONTENA_VAULT_KEY} -e VAULT_IV=${KONTENA_VAULT_IV} \
|
96
|
+
kontena/server:${KONTENA_VERSION}
|
97
|
+
|
98
|
+
- name: kontena-server-haproxy.service
|
99
|
+
command: start
|
100
|
+
enable: true
|
101
|
+
content: |
|
102
|
+
[Unit]
|
103
|
+
Description=kontena-server-haproxy
|
104
|
+
After=network-online.target
|
105
|
+
After=docker.service
|
106
|
+
Description=Kontena Server HAProxy
|
107
|
+
Documentation=http://www.kontena.io/
|
108
|
+
Requires=network-online.target
|
109
|
+
Requires=docker.service
|
110
|
+
Requires=kontena-server-api.service
|
111
|
+
|
112
|
+
[Service]
|
113
|
+
Restart=always
|
114
|
+
RestartSec=5
|
115
|
+
EnvironmentFile=/etc/kontena-server.env
|
116
|
+
EnvironmentFile=-/etc/kontena-server.custom.env
|
117
|
+
ExecStartPre=-/usr/bin/docker stop kontena-server-haproxy
|
118
|
+
ExecStartPre=-/usr/bin/docker rm kontena-server-haproxy
|
119
|
+
ExecStartPre=-/usr/bin/docker pull kontena/haproxy:latest
|
120
|
+
ExecStart=/opt/bin/kontena-haproxy.sh
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'erb'
|
3
|
+
require 'open3'
|
4
|
+
require 'shell-spinner'
|
5
|
+
|
6
|
+
module Kontena
|
7
|
+
module Machine
|
8
|
+
module Upcloud
|
9
|
+
class MasterProvisioner
|
10
|
+
include RandomName
|
11
|
+
include Machine::CertHelper
|
12
|
+
include UpcloudCommon
|
13
|
+
|
14
|
+
attr_reader :http_client, :username, :password
|
15
|
+
|
16
|
+
# @param [String] token Upcloud token
|
17
|
+
def initialize(upcloud_username, upcloud_password)
|
18
|
+
@username = upcloud_username
|
19
|
+
@password = upcloud_password
|
20
|
+
end
|
21
|
+
|
22
|
+
def run!(opts)
|
23
|
+
if File.readable?(File.expand_path(opts[:ssh_key]))
|
24
|
+
ssh_key = File.read(File.expand_path(opts[:ssh_key])).strip
|
25
|
+
end
|
26
|
+
|
27
|
+
abort('Invalid ssh key') unless ssh_key && ssh_key.start_with?('ssh-')
|
28
|
+
|
29
|
+
if opts[:ssl_cert]
|
30
|
+
abort('Invalid ssl cert') unless File.exists?(File.expand_path(opts[:ssl_cert]))
|
31
|
+
ssl_cert = File.read(File.expand_path(opts[:ssl_cert]))
|
32
|
+
else
|
33
|
+
ShellSpinner "Generating self-signed SSL certificate" do
|
34
|
+
ssl_cert = generate_self_signed_cert
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
abort_unless_api_access
|
39
|
+
|
40
|
+
abort('CoreOS template not found on Upcloud') unless coreos_template = find_template('CoreOS Stable')
|
41
|
+
abort('Server plan not found on Upcloud') unless plan = find_plan(opts[:plan])
|
42
|
+
abort('Zone not found on Upcloud') unless zone_exist?(opts[:zone])
|
43
|
+
|
44
|
+
hostname = generate_name
|
45
|
+
|
46
|
+
userdata_vars = {
|
47
|
+
ssl_cert: ssl_cert,
|
48
|
+
auth_server: opts[:auth_server],
|
49
|
+
version: opts[:version],
|
50
|
+
vault_secret: opts[:vault_secret],
|
51
|
+
vault_iv: opts[:vault_iv],
|
52
|
+
mongodb_uri: opts[:mongodb_uri]
|
53
|
+
}
|
54
|
+
|
55
|
+
device_data = {
|
56
|
+
server: {
|
57
|
+
zone: opts[:zone],
|
58
|
+
title: "Kontena Master #{hostname}",
|
59
|
+
hostname: hostname,
|
60
|
+
plan: plan[:name],
|
61
|
+
vnc: 'off',
|
62
|
+
timezone: 'UTC',
|
63
|
+
user_data: user_data(userdata_vars),
|
64
|
+
firewall: 'off',
|
65
|
+
storage_devices: {
|
66
|
+
storage_device: [
|
67
|
+
{
|
68
|
+
action: 'clone',
|
69
|
+
storage: coreos_template[:uuid],
|
70
|
+
title: "From template #{coreos_template[:title]}",
|
71
|
+
size: plan[:storage_size],
|
72
|
+
tier: 'maxiops'
|
73
|
+
}
|
74
|
+
]
|
75
|
+
},
|
76
|
+
login_user: {
|
77
|
+
create_password: 'no',
|
78
|
+
username: 'root',
|
79
|
+
ssh_keys: {
|
80
|
+
ssh_key: [ssh_key]
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}.to_json
|
85
|
+
|
86
|
+
ShellSpinner "Creating Upcloud master #{hostname.colorize(:cyan)} " do
|
87
|
+
response = post('server', body: device_data)
|
88
|
+
if response.has_key?(:error)
|
89
|
+
abort("\nUpcloud server creation failed (#{response[:error].fetch(:error_message, '')})")
|
90
|
+
end
|
91
|
+
device_data = response[:server]
|
92
|
+
|
93
|
+
until device_data && device_data.fetch(:state, nil).to_s == 'maintenance'
|
94
|
+
device_data = get("server/#{device[:uuid]}").fetch(:server, {}) rescue nil
|
95
|
+
sleep 5
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
device_public_ip = device_data[:ip_addresses][:ip_address].find do |ip|
|
100
|
+
ip[:access].eql?('public') && ip[:family].eql?('IPv4')
|
101
|
+
end
|
102
|
+
|
103
|
+
abort('Server public ip not found, destroy manually.') unless device_public_ip
|
104
|
+
|
105
|
+
master_url = "https://#{device_public_ip[:address]}"
|
106
|
+
Excon.defaults[:ssl_verify_peer] = false
|
107
|
+
@http_client = Excon.new("#{master_url}", :connect_timeout => 10)
|
108
|
+
|
109
|
+
ShellSpinner "Waiting for #{hostname.colorize(:cyan)} to start" do
|
110
|
+
sleep 5 until master_running?
|
111
|
+
end
|
112
|
+
|
113
|
+
puts "Kontena Master is now running at #{master_url}"
|
114
|
+
puts "Use #{"kontena login --name=#{hostname.sub('kontena-master-', '')} #{master_url}".colorize(:light_black)} to complete Kontena Master setup"
|
115
|
+
end
|
116
|
+
|
117
|
+
def user_data(vars)
|
118
|
+
cloudinit_template = File.join(__dir__ , '/cloudinit_master.yml')
|
119
|
+
erb(File.read(cloudinit_template), vars)
|
120
|
+
end
|
121
|
+
|
122
|
+
def generate_name
|
123
|
+
"kontena-master-#{super}-#{rand(1..9)}"
|
124
|
+
end
|
125
|
+
|
126
|
+
def master_running?
|
127
|
+
http_client.get(path: '/').status == 200
|
128
|
+
rescue
|
129
|
+
false
|
130
|
+
end
|
131
|
+
|
132
|
+
def erb(template, vars)
|
133
|
+
ERB.new(template, nil, '%<>-').result(OpenStruct.new(vars).instance_eval { binding })
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'shell-spinner'
|
2
|
+
|
3
|
+
module Kontena
|
4
|
+
module Machine
|
5
|
+
module Upcloud
|
6
|
+
class NodeDestroyer
|
7
|
+
include RandomName
|
8
|
+
include UpcloudCommon
|
9
|
+
|
10
|
+
attr_reader :api_client, :username, :password
|
11
|
+
|
12
|
+
# @param [Kontena::Client] api_client Kontena api client
|
13
|
+
# @param [String] token Upcloud token
|
14
|
+
def initialize(api_client, upcloud_username, upcloud_password)
|
15
|
+
@api_client = api_client
|
16
|
+
@username = upcloud_username
|
17
|
+
@password = upcloud_password
|
18
|
+
end
|
19
|
+
|
20
|
+
def run!(grid, name)
|
21
|
+
|
22
|
+
abort_unless_api_access
|
23
|
+
|
24
|
+
servers = get('server')
|
25
|
+
unless servers && servers.has_key?(:servers)
|
26
|
+
abort('Upcloud API error')
|
27
|
+
end
|
28
|
+
|
29
|
+
server = servers[:servers][:server].find{|s| s[:hostname] == name}
|
30
|
+
|
31
|
+
abort "Cannot find node #{name.colorize(:cyan)} in Upcloud" unless server
|
32
|
+
|
33
|
+
server_data = get("server/#{server[:uuid]}")
|
34
|
+
|
35
|
+
storage_devices = server_data.fetch(:server, {}).fetch(:storage_devices, {}).fetch(:storage_device, [])
|
36
|
+
storage_uuids = storage_devices.map{|s| s[:storage]}
|
37
|
+
|
38
|
+
abort('No storage devices found for Upcloud node') if storage_uuids.empty?
|
39
|
+
|
40
|
+
if server
|
41
|
+
unless server[:state].eql?('stopped')
|
42
|
+
ShellSpinner "Shutting down Upcloud node #{name.colorize(:cyan)} " do
|
43
|
+
device_data = post(
|
44
|
+
"server/#{server[:uuid]}/stop", body: {
|
45
|
+
stop_server: {
|
46
|
+
stop_type: 'soft',
|
47
|
+
timeout: 120
|
48
|
+
}
|
49
|
+
}.to_json
|
50
|
+
)
|
51
|
+
|
52
|
+
until device_data && device_data.fetch(:state, nil).to_s.eql?('stopped')
|
53
|
+
device_data = get("server/#{server[:uuid]}").fetch(:server, {}) rescue nil
|
54
|
+
sleep 5
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
ShellSpinner "Terminating Upcloud node #{name.colorize(:cyan)} " do
|
60
|
+
response = delete("server/#{server[:uuid]}")
|
61
|
+
abort "Cannot delete node #{name.colorize(:cyan)} in Upcloud" unless response[:success]
|
62
|
+
end
|
63
|
+
|
64
|
+
storage_uuids.each do |uuid|
|
65
|
+
ShellSpinner "Deleting Upcloud storage device '#{uuid.colorize(:cyan)}' " do
|
66
|
+
response = delete("storage/#{uuid}")
|
67
|
+
unless response[:success]
|
68
|
+
puts "#{"WARNING".colorize(:red)}: Couldn't delete Upcloud storage '#{uuid.colorize(:cyan)}', check manually."
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
else
|
73
|
+
abort "Cannot find node #{name.colorize(:cyan)} in Upcloud"
|
74
|
+
end
|
75
|
+
node = api_client.get("grids/#{grid['id']}/nodes")['nodes'].find{|n| n['name'] == name}
|
76
|
+
if node
|
77
|
+
ShellSpinner "Removing node #{name.colorize(:cyan)} from grid #{grid['name'].colorize(:cyan)} " do
|
78
|
+
api_client.delete("grids/#{grid['id']}/nodes/#{name}")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'erb'
|
3
|
+
require 'open3'
|
4
|
+
require 'shell-spinner'
|
5
|
+
|
6
|
+
module Kontena
|
7
|
+
module Machine
|
8
|
+
module Upcloud
|
9
|
+
class NodeProvisioner
|
10
|
+
include RandomName
|
11
|
+
include UpcloudCommon
|
12
|
+
|
13
|
+
attr_reader :api_client, :username, :password
|
14
|
+
|
15
|
+
# @param [Kontena::Client] api_client Kontena api client
|
16
|
+
# @param [String] upcloud_username Upcloud username
|
17
|
+
# @param [String] upcloud_password Upcloud password
|
18
|
+
def initialize(api_client, upcloud_username, upcloud_password)
|
19
|
+
@api_client = api_client
|
20
|
+
@username = upcloud_username
|
21
|
+
@password = upcloud_password
|
22
|
+
end
|
23
|
+
|
24
|
+
def run!(opts)
|
25
|
+
if File.readable?(File.expand_path(opts[:ssh_key]))
|
26
|
+
ssh_key = File.read(File.expand_path(opts[:ssh_key])).strip
|
27
|
+
end
|
28
|
+
|
29
|
+
abort('Invalid ssh key') unless ssh_key && ssh_key.start_with?('ssh-')
|
30
|
+
|
31
|
+
userdata_vars = {
|
32
|
+
version: opts[:version],
|
33
|
+
master_uri: opts[:master_uri],
|
34
|
+
grid_token: opts[:grid_token],
|
35
|
+
}
|
36
|
+
|
37
|
+
abort_unless_api_access
|
38
|
+
|
39
|
+
abort('CoreOS template not found on Upcloud') unless coreos_template = find_template('CoreOS Stable')
|
40
|
+
abort('Server plan not found on Upcloud') unless plan = find_plan(opts[:plan])
|
41
|
+
abort('Zone not found on Upcloud') unless zone_exist?(opts[:zone])
|
42
|
+
|
43
|
+
hostname = generate_name
|
44
|
+
|
45
|
+
device_data = {
|
46
|
+
server: {
|
47
|
+
zone: opts[:zone],
|
48
|
+
title: "Kontena Grid #{opts[:grid]} Node #{hostname}",
|
49
|
+
hostname: hostname,
|
50
|
+
plan: plan[:name],
|
51
|
+
vnc: 'off',
|
52
|
+
timezone: 'UTC',
|
53
|
+
user_data: user_data(userdata_vars),
|
54
|
+
firewall: 'off',
|
55
|
+
storage_devices: {
|
56
|
+
storage_device: [
|
57
|
+
{
|
58
|
+
action: 'clone',
|
59
|
+
storage: coreos_template[:uuid],
|
60
|
+
title: "From template #{coreos_template[:title]}",
|
61
|
+
size: plan[:storage_size],
|
62
|
+
tier: 'maxiops'
|
63
|
+
}
|
64
|
+
]
|
65
|
+
},
|
66
|
+
login_user: {
|
67
|
+
create_password: 'no',
|
68
|
+
username: 'root',
|
69
|
+
ssh_keys: {
|
70
|
+
ssh_key: [ssh_key]
|
71
|
+
}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}.to_json
|
75
|
+
|
76
|
+
ShellSpinner "Creating Upcloud node #{hostname.colorize(:cyan)} " do
|
77
|
+
response = post('server', body: device_data)
|
78
|
+
|
79
|
+
if response.has_key?(:error)
|
80
|
+
abort("\nUpcloud server creation failed (#{response[:error].fetch(:error_message, '')})")
|
81
|
+
end
|
82
|
+
device_data = response[:server]
|
83
|
+
|
84
|
+
until device_data && device_data.fetch(:state, nil).to_s == 'maintenance'
|
85
|
+
device_data = get("server/#{device[:uuid]}").fetch(:server, {}) rescue nil
|
86
|
+
sleep 5
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
node = nil
|
91
|
+
ShellSpinner "Waiting for node #{hostname.colorize(:cyan)} join to grid #{opts[:grid].colorize(:cyan)} " do
|
92
|
+
sleep 2 until node = node_exists_in_grid?(opts[:grid], hostname)
|
93
|
+
end
|
94
|
+
set_labels(node, ["region=#{opts[:zone]}", "provider=upcloud"])
|
95
|
+
end
|
96
|
+
|
97
|
+
def user_data(vars)
|
98
|
+
cloudinit_template = File.join(__dir__ , '/cloudinit.yml')
|
99
|
+
erb(File.read(cloudinit_template), vars)
|
100
|
+
end
|
101
|
+
|
102
|
+
def generate_name
|
103
|
+
"#{super}-#{rand(1..99)}"
|
104
|
+
end
|
105
|
+
|
106
|
+
def node_exists_in_grid?(grid, hostname)
|
107
|
+
api_client.get("grids/#{grid}/nodes")['nodes'].find{|n| n['name'] == hostname}
|
108
|
+
end
|
109
|
+
|
110
|
+
def erb(template, vars)
|
111
|
+
ERB.new(template).result(OpenStruct.new(vars).instance_eval { binding })
|
112
|
+
end
|
113
|
+
|
114
|
+
def set_labels(node, labels)
|
115
|
+
data = {labels: labels}
|
116
|
+
api_client.put("nodes/#{node['id']}", data, {}, {'Kontena-Grid-Token' => node['grid']['token']})
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'shell-spinner'
|
2
|
+
|
3
|
+
module Kontena
|
4
|
+
module Machine
|
5
|
+
module Upcloud
|
6
|
+
class NodeRestarter
|
7
|
+
include RandomName
|
8
|
+
include UpcloudCommon
|
9
|
+
|
10
|
+
attr_reader :username, :password
|
11
|
+
|
12
|
+
# @param [String] upcloud_username Upcloud username
|
13
|
+
# @param [String] upcloud_password Upcloud password
|
14
|
+
def initialize(upcloud_username, upcloud_password)
|
15
|
+
@username = upcloud_username
|
16
|
+
@password = upcloud_password
|
17
|
+
end
|
18
|
+
|
19
|
+
def run!(name)
|
20
|
+
abort_unless_api_access
|
21
|
+
|
22
|
+
servers = get('server')
|
23
|
+
unless servers && servers.has_key?(:servers)
|
24
|
+
abort('Upcloud API error')
|
25
|
+
end
|
26
|
+
|
27
|
+
server = servers[:servers][:server].find{|s| s[:hostname] == name}
|
28
|
+
|
29
|
+
if server
|
30
|
+
ShellSpinner "Restarting Upcloud node #{name.colorize(:cyan)} " do
|
31
|
+
result = post(
|
32
|
+
"server/#{server[:uuid]}/restart", body: {
|
33
|
+
restart_server: {
|
34
|
+
stop_type: 'soft',
|
35
|
+
timeout: 600,
|
36
|
+
timeout_action: 'destroy' # hard shutdown in case sof timeouts
|
37
|
+
}
|
38
|
+
}.to_json
|
39
|
+
)
|
40
|
+
end
|
41
|
+
else
|
42
|
+
abort "Cannot find node #{name.colorize(:cyan)} in Upcloud"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'excon'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Kontena
|
5
|
+
module Machine
|
6
|
+
module Upcloud
|
7
|
+
module UpcloudCommon
|
8
|
+
|
9
|
+
attr_reader :username
|
10
|
+
attr_reader :password
|
11
|
+
|
12
|
+
def client
|
13
|
+
@client ||= Excon.new(
|
14
|
+
'https://api.upcloud.com',
|
15
|
+
omit_default_port: true,
|
16
|
+
user: username,
|
17
|
+
password: password,
|
18
|
+
headers: { "Accept-Encoding" => 'application/json' }
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def find_template(name)
|
23
|
+
get('storage/template')[:storages][:storage].find{|s| s[:title].downcase.start_with?(name.downcase)}
|
24
|
+
end
|
25
|
+
|
26
|
+
def find_plan(name)
|
27
|
+
get('plan')[:plans][:plan].find{|s| s[:name].downcase.eql?(name.downcase)}
|
28
|
+
end
|
29
|
+
|
30
|
+
def zone_exist?(name)
|
31
|
+
get('zone')[:zones][:zone].map{|p| p[:id]}.include?(name)
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_server(id)
|
35
|
+
get("server/#{id}").fetch(:server, nil)
|
36
|
+
end
|
37
|
+
|
38
|
+
def api_access?
|
39
|
+
response = get('account')
|
40
|
+
response.kind_of?(Hash) && response.has_key?(:account)
|
41
|
+
rescue
|
42
|
+
false
|
43
|
+
end
|
44
|
+
|
45
|
+
def abort_unless_api_access
|
46
|
+
unless api_access?
|
47
|
+
abort('Upcloud API authentication failed. Check that API access is enabled for the user.')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
[:get, :post, :delete].each do |http_method|
|
52
|
+
define_method http_method do |path, opts={}|
|
53
|
+
response = client.send(
|
54
|
+
http_method,
|
55
|
+
opts.merge(
|
56
|
+
path: File.join('/1.2', path),
|
57
|
+
headers: {
|
58
|
+
'Content-Type': 'application/json'
|
59
|
+
}
|
60
|
+
)
|
61
|
+
)
|
62
|
+
if response.body && response.body.start_with?('{')
|
63
|
+
JSON.parse(response.body, symbolize_names: true)
|
64
|
+
elsif response.status.to_s.start_with?('2')
|
65
|
+
{success: true}
|
66
|
+
else
|
67
|
+
{error: response.status}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
require 'kontena/machine/random_name'
|
2
|
+
require 'kontena/machine/cert_helper'
|
3
|
+
require_relative 'upcloud/upcloud_common'
|
4
|
+
require_relative 'upcloud/node_provisioner'
|
5
|
+
require_relative 'upcloud/node_destroyer'
|
6
|
+
require_relative 'upcloud/node_restarter'
|
7
|
+
require_relative 'upcloud/master_provisioner'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
module Kontena::Plugin::Upcloud::Master
|
4
|
+
class CreateCommand < Clamp::Command
|
5
|
+
include Kontena::Cli::Common
|
6
|
+
|
7
|
+
option "--username", "USER", "Upcloud username", required: true
|
8
|
+
option "--password", "PASS", "Upcloud password", required: true
|
9
|
+
option "--ssh-key", "SSH_KEY", "Path to ssh public key", required: true
|
10
|
+
option "--ssl-cert", "SSL CERT", "SSL certificate file (optional)"
|
11
|
+
option "--plan", "PLAN", "Server plan", default: '1xCPU-1GB'
|
12
|
+
option "--zone", "ZONE", "Zone", default: 'fi-hel1'
|
13
|
+
option "--vault-secret", "VAULT_SECRET", "Secret key for Vault (optional)"
|
14
|
+
option "--vault-iv", "VAULT_IV", "Initialization vector for Vault (optional)"
|
15
|
+
option "--mongodb-uri", "URI", "External MongoDB uri (optional)"
|
16
|
+
option "--version", "VERSION", "Define installed Kontena version", default: 'latest'
|
17
|
+
option "--auth-provider-url", "AUTH_PROVIDER_URL", "Define authentication provider url"
|
18
|
+
|
19
|
+
|
20
|
+
def execute
|
21
|
+
|
22
|
+
require 'kontena/machine/upcloud'
|
23
|
+
|
24
|
+
provisioner = Kontena::Machine::Upcloud::MasterProvisioner.new(username, password)
|
25
|
+
provisioner.run!(
|
26
|
+
ssh_key: ssh_key,
|
27
|
+
ssl_cert: ssl_cert,
|
28
|
+
plan: plan,
|
29
|
+
zone: zone,
|
30
|
+
version: version,
|
31
|
+
auth_server: auth_provider_url,
|
32
|
+
vault_secret: vault_secret || SecureRandom.hex(24),
|
33
|
+
vault_iv: vault_iv || SecureRandom.hex(24),
|
34
|
+
mongodb_uri: mongodb_uri
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative 'nodes/create_command'
|
2
|
+
require_relative 'nodes/restart_command'
|
3
|
+
require_relative 'nodes/terminate_command'
|
4
|
+
|
5
|
+
class Kontena::Plugin::Upcloud::NodeCommand < Kontena::Command
|
6
|
+
|
7
|
+
subcommand "create", "Create a new node to Upcloud", Kontena::Plugin::Upcloud::Nodes::CreateCommand
|
8
|
+
subcommand "restart", "Restart Upcloud node", Kontena::Plugin::Upcloud::Nodes::RestartCommand
|
9
|
+
subcommand "terminate", "Terminate Upcloud node", Kontena::Plugin::Upcloud::Nodes::TerminateCommand
|
10
|
+
|
11
|
+
def execute
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Kontena::Plugin::Upcloud::Nodes
|
2
|
+
class CreateCommand < Clamp::Command
|
3
|
+
include Kontena::Cli::Common
|
4
|
+
include Kontena::Cli::GridOptions
|
5
|
+
|
6
|
+
parameter "[NAME]", "Node name"
|
7
|
+
option "--username", "USER", "Upcloud username", required: true
|
8
|
+
option "--password", "PASS", "Upcloud password", required: true
|
9
|
+
option "--ssh-key", "SSH_KEY", "Path to ssh public key", required: true
|
10
|
+
option "--plan", "PLAN", "Server size", default: '1xCPU-1GB'
|
11
|
+
option "--zone", "ZONE", "Zone", default: 'fi-hel1'
|
12
|
+
option "--version", "VERSION", "Define installed Kontena version", default: 'latest'
|
13
|
+
|
14
|
+
def execute
|
15
|
+
require_api_url
|
16
|
+
require_current_grid
|
17
|
+
|
18
|
+
require 'kontena/machine/upcloud'
|
19
|
+
grid = fetch_grid
|
20
|
+
provisioner = Kontena::Machine::Upcloud::NodeProvisioner.new(client(require_token), username, password)
|
21
|
+
provisioner.run!(
|
22
|
+
master_uri: api_url,
|
23
|
+
grid_token: grid['token'],
|
24
|
+
grid: current_grid,
|
25
|
+
ssh_key: ssh_key,
|
26
|
+
name: name,
|
27
|
+
plan: plan,
|
28
|
+
zone: zone,
|
29
|
+
version: version
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param [String] id
|
34
|
+
# @return [Hash]
|
35
|
+
def fetch_grid
|
36
|
+
client(require_token).get("grids/#{current_grid}")
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Kontena::Plugin::Upcloud::Nodes
|
2
|
+
class RestartCommand < Clamp::Command
|
3
|
+
include Kontena::Cli::Common
|
4
|
+
include Kontena::Cli::GridOptions
|
5
|
+
|
6
|
+
parameter "NAME", "Node name"
|
7
|
+
option "--username", "USER", "Upcloud username", required: true
|
8
|
+
option "--password", "PASS", "Upcloud password", required: true
|
9
|
+
|
10
|
+
def execute
|
11
|
+
require_api_url
|
12
|
+
require_current_grid
|
13
|
+
|
14
|
+
require 'kontena/machine/upcloud'
|
15
|
+
|
16
|
+
restarter = Kontena::Machine::Upcloud::NodeRestarter.new(username, password)
|
17
|
+
restarter.run!(name)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Kontena::Plugin::Upcloud::Nodes
|
2
|
+
class TerminateCommand < Clamp::Command
|
3
|
+
include Kontena::Cli::Common
|
4
|
+
include Kontena::Cli::GridOptions
|
5
|
+
|
6
|
+
parameter "NAME", "Node name"
|
7
|
+
option "--username", "USER", "Upcloud username", required: true
|
8
|
+
option "--password", "PASS", "Upcloud password", required: true
|
9
|
+
|
10
|
+
def execute
|
11
|
+
require_api_url
|
12
|
+
require_current_grid
|
13
|
+
|
14
|
+
require 'kontena/machine/upcloud'
|
15
|
+
grid = client(require_token).get("grids/#{current_grid}")
|
16
|
+
destroyer = Kontena::Machine::Upcloud::NodeDestroyer.new(client(require_token), username, password)
|
17
|
+
destroyer.run!(grid, name)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require_relative 'upcloud/master_command'
|
2
|
+
require_relative 'upcloud/node_command'
|
3
|
+
|
4
|
+
class Kontena::Plugin::UpcloudCommand < Kontena::Command
|
5
|
+
|
6
|
+
subcommand 'master', 'Upcloud master related commands', Kontena::Plugin::Upcloud::MasterCommand
|
7
|
+
subcommand 'node', 'Upcloud node related commands', Kontena::Plugin::Upcloud::NodeCommand
|
8
|
+
|
9
|
+
def execute
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kontena-plugin-upcloud
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kontena, Inc.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: kontena-cli
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.15.0.rc1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.15.0.rc1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: Kontena Upcloud plugin
|
56
|
+
email:
|
57
|
+
- info@kontena.io
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .rspec
|
64
|
+
- .travis.yml
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- kontena-plugin-upcloud.gemspec
|
69
|
+
- lib/kontena/machine/upcloud.rb
|
70
|
+
- lib/kontena/machine/upcloud/cloudinit.yml
|
71
|
+
- lib/kontena/machine/upcloud/cloudinit_master.yml
|
72
|
+
- lib/kontena/machine/upcloud/master_provisioner.rb
|
73
|
+
- lib/kontena/machine/upcloud/node_destroyer.rb
|
74
|
+
- lib/kontena/machine/upcloud/node_provisioner.rb
|
75
|
+
- lib/kontena/machine/upcloud/node_restarter.rb
|
76
|
+
- lib/kontena/machine/upcloud/upcloud_common.rb
|
77
|
+
- lib/kontena/plugin/upcloud.rb
|
78
|
+
- lib/kontena/plugin/upcloud/master/create_command.rb
|
79
|
+
- lib/kontena/plugin/upcloud/master_command.rb
|
80
|
+
- lib/kontena/plugin/upcloud/node_command.rb
|
81
|
+
- lib/kontena/plugin/upcloud/nodes/create_command.rb
|
82
|
+
- lib/kontena/plugin/upcloud/nodes/restart_command.rb
|
83
|
+
- lib/kontena/plugin/upcloud/nodes/terminate_command.rb
|
84
|
+
- lib/kontena/plugin/upcloud_command.rb
|
85
|
+
- lib/kontena_cli_plugin.rb
|
86
|
+
homepage: https://github.com/kontena/kontena-plugin-upcloud
|
87
|
+
licenses:
|
88
|
+
- Apache-2.0
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.4.5
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Kontena Upcloud plugin
|
110
|
+
test_files: []
|