kontena-plugin-packet 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/.gitmodules +0 -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-packet.gemspec +24 -0
- data/lib/kontena/machine/packet/cloudinit.yml +67 -0
- data/lib/kontena/machine/packet/cloudinit_master.yml +118 -0
- data/lib/kontena/machine/packet/master_provisioner.rb +93 -0
- data/lib/kontena/machine/packet/node_destroyer.rb +42 -0
- data/lib/kontena/machine/packet/node_provisioner.rb +77 -0
- data/lib/kontena/machine/packet/node_restarter.rb +41 -0
- data/lib/kontena/machine/packet/packet_common.rb +89 -0
- data/lib/kontena/machine/packet.rb +7 -0
- data/lib/kontena/plugin/packet/master/create_command.rb +44 -0
- data/lib/kontena/plugin/packet/master_command.rb +9 -0
- data/lib/kontena/plugin/packet/node_command.rb +13 -0
- data/lib/kontena/plugin/packet/nodes/create_command.rb +46 -0
- data/lib/kontena/plugin/packet/nodes/restart_command.rb +17 -0
- data/lib/kontena/plugin/packet/nodes/terminate_command.rb +26 -0
- data/lib/kontena/plugin/packet.rb +7 -0
- data/lib/kontena/plugin/packet_command.rb +11 -0
- data/lib/kontena_cli_plugin.rb +5 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NTNjNDJjZDcyMzI0YWEwNjA0MTcyZmU2OTVmMDIyY2Q3NWQ5MTdkYQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
M2ViMTZiMzI0NDQwMDhlNmQwNzkxMzVlODM3Y2VlNzI3YzQ0MjE0ZA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NzE4NjE2ZDllNzMyMGUxM2NhMjg3Yjg0YmE4NTQ1ZTk1NTFlNjdlMTg2MGYy
|
10
|
+
OWVlYmYyMmIzYmE1ODUzMWZkMzAzOTk2NTQzOTg1MzJhMDI2MTgyZGVhZWM3
|
11
|
+
YTRkZjBhYmUyOTZkMjljMjQyNGRlY2I4OTIzNzJhNmJkMmI1MTM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NDExNzliZmFjM2NmNTE3YjVjMjdiYjU5ZjU2YmMzZmQ0ZTM3NDM1NzM2YmZl
|
14
|
+
MDg1NjQwM2YxYzQyNWEzZTUyY2VhMWE2ZDdjMTAyY2ZjODQyMWY5ZDIxMjYx
|
15
|
+
OWFiZmMyZjJjZDE1ZDU0ZGQ5MTlkN2UxNDEyZTkwZTUxYjBlY2U=
|
data/.gitignore
ADDED
data/.gitmodules
ADDED
File without changes
|
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: "cUyvZs8EwaLZrE1xQFNTKq4Ft6evckt2qeU3lB0PuNONYUfRli2RqOUjD8So7yiPYucNKlqJ2u641WRV4AYY8TUnu2jKFGlEEmZuYkWj0jv6HAy02vWt+d4fjgq6R4+TCW+7wKQcrN8zYH9KJImPcN9S01XqaTm4oHsaZZk4dRWL7PnKHAnnxPnpSpytF2jgtETmfOQWAfECOtR5+ypFmmmoCz+6/RPO6Ys+mIL0MbbJQxqq+FEothgoZD92cR/kzZI4YIwoijw54JlIIpRlK9Y1szfC13LxaCujYfic2ny7HnfV8tfl7lt/OVE/NQCYJfK4Bao73zMemQ2th80O68WzF9px5p5gRrPhumjT8Oxf9MTEcH46PDQprznZW0UnZF51oPGDQWDIFwLgiokalKgzR/tPHM8sm/kJs6BPlTUHxkRDWWfiSR+rIz8t94HSBK2N9mCdesIM9oNUx8tUbEvQXmVOGmpRivHr2Fa5rtv0/dbXW0Y78XyF7WNPBIeuFwDQLTTwtzbYxuhC6V0q9yV9Tos2fRqzIn1Ddc01xOjRVfnz8J8cw1su7a0SarXZgnjzWuxU6N/xMyh4QNKvJPbUAMKi243tN+QyG0Kq8nT4SL525khZBoHx1wr9sRDSjd9vgHi51/cV3YGh+9FXsFJ8kkRCE825k/gnZxo3JvA="
|
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-packet
|
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 Packet Plugin
|
2
|
+
|
3
|
+
This plugin provides support for Packet provisioning to Kontena CLI.
|
4
|
+
|
5
|
+
|
6
|
+
## Contributing
|
7
|
+
|
8
|
+
1. Fork it ( https://github.com/kontena/kontena-plugin-packet )
|
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,24 @@
|
|
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/packet'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "kontena-plugin-packet"
|
8
|
+
spec.version = Kontena::Plugin::Packet::VERSION
|
9
|
+
spec.authors = ["Kontena, Inc."]
|
10
|
+
spec.email = ["info@kontena.io"]
|
11
|
+
|
12
|
+
spec.summary = "Kontena Packet plugin"
|
13
|
+
spec.description = "Packet provision plugin for Kontena"
|
14
|
+
spec.homepage = "https://github.com/kontena/kontena-plugin-packet"
|
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_runtime_dependency 'packethost', '>= 0.0.6'
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
end
|
@@ -0,0 +1,67 @@
|
|
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
|
+
KONTENA_PRIVATE_IP=$private_ipv4
|
12
|
+
- path: /etc/systemd/system/docker.service.d/50-kontena.conf
|
13
|
+
content: |
|
14
|
+
[Service]
|
15
|
+
Environment='DOCKER_OPTS=--insecure-registry="10.81.0.0/19" --bip="172.17.43.1/16"'
|
16
|
+
Environment='DOCKER_CGROUPS=--exec-opt native.cgroupdriver=cgroupfs'
|
17
|
+
- path: /etc/sysctl.d/99-inotify.conf
|
18
|
+
owner: root
|
19
|
+
permissions: 0644
|
20
|
+
content: |
|
21
|
+
fs.inotify.max_user_instances = 8192
|
22
|
+
- path: /etc/resolv.conf
|
23
|
+
permissions: 0644
|
24
|
+
owner: root
|
25
|
+
content: |
|
26
|
+
nameserver 172.17.43.1
|
27
|
+
nameserver 8.8.8.8
|
28
|
+
nameserver 8.8.4.4
|
29
|
+
coreos:
|
30
|
+
units:
|
31
|
+
- name: 10-weave.network
|
32
|
+
runtime: false
|
33
|
+
content: |
|
34
|
+
[Match]
|
35
|
+
Type=bridge
|
36
|
+
Name=weave*
|
37
|
+
|
38
|
+
[Network]
|
39
|
+
- name: kontena-agent.service
|
40
|
+
command: start
|
41
|
+
enable: true
|
42
|
+
content: |
|
43
|
+
[Unit]
|
44
|
+
Description=kontena-agent
|
45
|
+
After=network-online.target
|
46
|
+
After=docker.service
|
47
|
+
Description=Kontena Agent
|
48
|
+
Documentation=http://www.kontena.io/
|
49
|
+
Requires=network-online.target
|
50
|
+
Requires=docker.service
|
51
|
+
|
52
|
+
[Service]
|
53
|
+
Restart=always
|
54
|
+
RestartSec=5
|
55
|
+
EnvironmentFile=/etc/kontena-agent.env
|
56
|
+
ExecStartPre=-/usr/bin/docker stop kontena-agent
|
57
|
+
ExecStartPre=-/usr/bin/docker rm kontena-agent
|
58
|
+
ExecStartPre=/usr/bin/docker pull kontena/agent:${KONTENA_VERSION}
|
59
|
+
ExecStart=/usr/bin/docker run --name kontena-agent \
|
60
|
+
-e KONTENA_URI=${KONTENA_URI} \
|
61
|
+
-e KONTENA_TOKEN=${KONTENA_TOKEN} \
|
62
|
+
-e KONTENA_PEER_INTERFACE=${KONTENA_PEER_INTERFACE} \
|
63
|
+
-e KONTENA_PRIVATE_IP=${KONTENA_PRIVATE_IP} \
|
64
|
+
-v=/var/run/docker.sock:/var/run/docker.sock \
|
65
|
+
-v=/etc/kontena-agent.env:/etc/kontena.env \
|
66
|
+
--net=host \
|
67
|
+
kontena/agent:${KONTENA_VERSION}
|
@@ -0,0 +1,118 @@
|
|
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
|
+
ExecStartPre=-/usr/bin/docker stop kontena-server-api
|
82
|
+
ExecStartPre=-/usr/bin/docker rm kontena-server-api
|
83
|
+
ExecStartPre=/usr/bin/docker pull kontena/server:${KONTENA_VERSION}
|
84
|
+
ExecStart=/usr/bin/docker run --name kontena-server-api \
|
85
|
+
<% if mongodb_uri -%>
|
86
|
+
-e MONGODB_URI=<%= mongodb_uri %> \
|
87
|
+
<% else -%>
|
88
|
+
--link kontena-server-mongo:mongodb \
|
89
|
+
-e MONGODB_URI=mongodb://mongodb:27017/kontena_server \
|
90
|
+
<% end -%>
|
91
|
+
<% if auth_server %>
|
92
|
+
-e AUTH_API_URL=<%= auth_server %> \
|
93
|
+
<% end -%>
|
94
|
+
-e VAULT_KEY=${KONTENA_VAULT_KEY} -e VAULT_IV=${KONTENA_VAULT_IV} \
|
95
|
+
kontena/server:${KONTENA_VERSION}
|
96
|
+
|
97
|
+
- name: kontena-server-haproxy.service
|
98
|
+
command: start
|
99
|
+
enable: true
|
100
|
+
content: |
|
101
|
+
[Unit]
|
102
|
+
Description=kontena-server-haproxy
|
103
|
+
After=network-online.target
|
104
|
+
After=docker.service
|
105
|
+
Description=Kontena Server HAProxy
|
106
|
+
Documentation=http://www.kontena.io/
|
107
|
+
Requires=network-online.target
|
108
|
+
Requires=docker.service
|
109
|
+
Requires=kontena-server-api.service
|
110
|
+
|
111
|
+
[Service]
|
112
|
+
Restart=always
|
113
|
+
RestartSec=5
|
114
|
+
EnvironmentFile=/etc/kontena-server.env
|
115
|
+
ExecStartPre=-/usr/bin/docker stop kontena-server-haproxy
|
116
|
+
ExecStartPre=-/usr/bin/docker rm kontena-server-haproxy
|
117
|
+
ExecStartPre=/usr/bin/docker pull kontena/haproxy:latest
|
118
|
+
ExecStart=/opt/bin/kontena-haproxy.sh
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'shell-spinner'
|
2
|
+
|
3
|
+
module Kontena
|
4
|
+
module Machine
|
5
|
+
module Packet
|
6
|
+
class MasterProvisioner
|
7
|
+
include RandomName
|
8
|
+
include Machine::CertHelper
|
9
|
+
include PacketCommon
|
10
|
+
|
11
|
+
attr_reader :client, :http_client
|
12
|
+
|
13
|
+
# @param [String] token Packet token
|
14
|
+
def initialize(token)
|
15
|
+
@client = login(token)
|
16
|
+
end
|
17
|
+
|
18
|
+
def run!(opts)
|
19
|
+
abort('Project does not exist in Packet') unless project = find_project(opts[:project])
|
20
|
+
abort('Facility does not exist in Packet') unless facility = find_facility(opts[:facility])
|
21
|
+
abort('Operating system coreos_stable does not exist in Packet') unless os = find_os('coreos_stable')
|
22
|
+
abort('Device type does not exist in Packet') unless plan = find_plan(opts[:plan])
|
23
|
+
|
24
|
+
check_or_create_ssh_key(File.expand_path(opts[:ssh_key])) if opts[:ssh_key]
|
25
|
+
|
26
|
+
if opts[:ssl_cert]
|
27
|
+
abort('Invalid ssl cert') unless File.exists?(File.expand_path(opts[:ssl_cert]))
|
28
|
+
ssl_cert = File.read(File.expand_path(opts[:ssl_cert]))
|
29
|
+
else
|
30
|
+
ShellSpinner "Generating self-signed SSL certificate" do
|
31
|
+
ssl_cert = generate_self_signed_cert
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
userdata_vars = {
|
36
|
+
ssl_cert: ssl_cert,
|
37
|
+
auth_server: opts[:auth_server],
|
38
|
+
version: opts[:version],
|
39
|
+
vault_secret: opts[:vault_secret],
|
40
|
+
vault_iv: opts[:vault_iv],
|
41
|
+
mongodb_uri: opts[:mongodb_uri]
|
42
|
+
}
|
43
|
+
|
44
|
+
device = project.new_device(
|
45
|
+
hostname: generate_name,
|
46
|
+
facility: facility.to_hash,
|
47
|
+
operating_system: os.to_hash,
|
48
|
+
plan: plan.to_hash,
|
49
|
+
billing_cycle: opts[:billing],
|
50
|
+
locked: true,
|
51
|
+
userdata: user_data(userdata_vars, 'cloudinit_master.yml')
|
52
|
+
)
|
53
|
+
|
54
|
+
ShellSpinner "Creating Packet device #{device.hostname.colorize(:cyan)} " do
|
55
|
+
api_retry "Packet API reported an error, please try again" do
|
56
|
+
response = client.create_device(device)
|
57
|
+
raise response.body unless response.success?
|
58
|
+
end
|
59
|
+
|
60
|
+
until device && [:active, :provisioning, :powering_on].include?(device.state)
|
61
|
+
device = find_device(project.id, device.hostname) rescue nil
|
62
|
+
sleep 5
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
public_ip = device_public_ip(device)
|
67
|
+
master_url = "https://#{public_ip['address']}"
|
68
|
+
|
69
|
+
Excon.defaults[:ssl_verify_peer] = false
|
70
|
+
@http_client = Excon.new("#{master_url}", :connect_timeout => 10)
|
71
|
+
|
72
|
+
ShellSpinner "Waiting for #{device.hostname.colorize(:cyan)} to start (estimate 4 minutes)" do
|
73
|
+
sleep 5 until master_running?
|
74
|
+
end
|
75
|
+
|
76
|
+
puts "Kontena Master is now running at #{master_url}"
|
77
|
+
puts "Use #{"kontena login --name=#{device.hostname.sub('kontena-master-', '')} #{master_url}".colorize(:light_black)} to complete Kontena Master setup"
|
78
|
+
end
|
79
|
+
|
80
|
+
def generate_name
|
81
|
+
"kontena-master-#{super}-#{rand(1..9)}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def master_running?
|
85
|
+
http_client.get(path: '/').status == 200
|
86
|
+
rescue
|
87
|
+
false
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'shell-spinner'
|
2
|
+
|
3
|
+
module Kontena
|
4
|
+
module Machine
|
5
|
+
module Packet
|
6
|
+
class NodeDestroyer
|
7
|
+
include RandomName
|
8
|
+
include PacketCommon
|
9
|
+
|
10
|
+
attr_reader :client, :api_client
|
11
|
+
|
12
|
+
# @param [Kontena::Client] api_client Kontena api client
|
13
|
+
# @param [String] token Packet api token
|
14
|
+
def initialize(api_client, token)
|
15
|
+
@api_client = api_client
|
16
|
+
@client = login(token)
|
17
|
+
end
|
18
|
+
|
19
|
+
def run!(grid, project_id, name)
|
20
|
+
device = client.list_devices(project_id).find{|d| d.hostname == name}
|
21
|
+
abort("Device #{name.colorize(:cyan)} not found in Packet") unless device
|
22
|
+
|
23
|
+
ShellSpinner "Terminating Packet device #{name.colorize(:cyan)} " do
|
24
|
+
begin
|
25
|
+
response = client.delete_device(device.id)
|
26
|
+
raise unless response.success?
|
27
|
+
rescue
|
28
|
+
abort "Cannot delete device #{name.colorize(:cyan)} in Packet"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
node = api_client.get("grids/#{grid['id']}/nodes")['nodes'].find{|n| n['name'] == name}
|
33
|
+
if node
|
34
|
+
ShellSpinner "Removing node #{name.colorize(:cyan)} from grid #{grid['name'].colorize(:cyan)} " do
|
35
|
+
api_client.delete("grids/#{grid['id']}/nodes/#{name}")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'shell-spinner'
|
2
|
+
|
3
|
+
module Kontena
|
4
|
+
module Machine
|
5
|
+
module Packet
|
6
|
+
class NodeProvisioner
|
7
|
+
include RandomName
|
8
|
+
include PacketCommon
|
9
|
+
|
10
|
+
attr_reader :client, :api_client
|
11
|
+
|
12
|
+
# @param [Kontena::Client] api_client Kontena api client
|
13
|
+
# @param [String] token Digital Ocean token
|
14
|
+
def initialize(api_client, token)
|
15
|
+
@api_client = api_client
|
16
|
+
@client = login(token)
|
17
|
+
end
|
18
|
+
|
19
|
+
def run!(opts)
|
20
|
+
abort('Project does not exist in Packet') unless project = find_project(opts[:project])
|
21
|
+
abort('Facility does not exist in Packet') unless facility = find_facility(opts[:facility])
|
22
|
+
abort('Operating system coreos_stable does not exist in Packet') unless os = find_os('coreos_stable')
|
23
|
+
abort('Device type does not exist in Packet') unless plan = find_plan(opts[:plan])
|
24
|
+
|
25
|
+
check_or_create_ssh_key(opts[:ssh_key]) if opts[:ssh_key]
|
26
|
+
|
27
|
+
userdata_vars = {
|
28
|
+
version: opts[:version],
|
29
|
+
master_uri: opts[:master_uri],
|
30
|
+
grid_token: opts[:grid_token],
|
31
|
+
}
|
32
|
+
|
33
|
+
device = project.new_device(
|
34
|
+
hostname: generate_name,
|
35
|
+
facility: facility.to_hash,
|
36
|
+
operating_system: os.to_hash,
|
37
|
+
plan: plan.to_hash,
|
38
|
+
billing_cycle: opts[:billing],
|
39
|
+
locked: false,
|
40
|
+
userdata: user_data(userdata_vars, 'cloudinit.yml')
|
41
|
+
)
|
42
|
+
|
43
|
+
ShellSpinner "Creating Packet device #{device.hostname.colorize(:cyan)} " do
|
44
|
+
api_retry "Packet API reported an error, please try again" do
|
45
|
+
response = client.create_device(device)
|
46
|
+
raise response.body unless response.success?
|
47
|
+
end
|
48
|
+
|
49
|
+
until device && [:active, :provisioning, :powering_on].include?(device.state)
|
50
|
+
device = find_device(project.id, device.hostname) rescue nil
|
51
|
+
sleep 5
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
node = nil
|
56
|
+
ShellSpinner "Waiting for node #{device.hostname.colorize(:cyan)} join to grid #{opts[:grid].colorize(:cyan)} (estimate 4 minutes) " do
|
57
|
+
sleep 2 until node = device_exists_in_grid?(opts[:grid], device)
|
58
|
+
end
|
59
|
+
set_labels(node, ["region=#{opts[:facility]}", "provider=packet"])
|
60
|
+
end
|
61
|
+
|
62
|
+
def generate_name
|
63
|
+
"#{super}-#{rand(1..99)}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def device_exists_in_grid?(grid, device)
|
67
|
+
api_client.get("grids/#{grid}/nodes")['nodes'].find{|n| n['name'] == device.hostname}
|
68
|
+
end
|
69
|
+
|
70
|
+
def set_labels(node, labels)
|
71
|
+
data = {labels: labels}
|
72
|
+
api_client.put("nodes/#{node['id']}", data, {}, {'Kontena-Grid-Token' => node['grid']['token']})
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'shell-spinner'
|
2
|
+
|
3
|
+
module Kontena
|
4
|
+
module Machine
|
5
|
+
module Packet
|
6
|
+
class NodeRestarter
|
7
|
+
include RandomName
|
8
|
+
include PacketCommon
|
9
|
+
|
10
|
+
attr_reader :client
|
11
|
+
|
12
|
+
# @param [String] token Packet api token
|
13
|
+
def initialize(token)
|
14
|
+
@client = login(token)
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param [String] project_id Packet project id
|
18
|
+
# @param [String] token Node hostname
|
19
|
+
def run!(project_id, name)
|
20
|
+
device = client.list_devices(project_id).find{|d| d.hostname == name}
|
21
|
+
abort("Device #{name.colorize(:cyan)} not found in Packet") unless device
|
22
|
+
abort("Your version of 'packethost' gem does not support rebooting servers") unless client.respond_to?(:reboot_device)
|
23
|
+
|
24
|
+
ShellSpinner "Restarting Packet device #{device.hostname.colorize(:cyan)} " do
|
25
|
+
begin
|
26
|
+
response = client.reboot_device(device)
|
27
|
+
raise unless response.success?
|
28
|
+
rescue
|
29
|
+
abort "Cannot delete device #{name.colorize(:cyan)} in Packet"
|
30
|
+
end
|
31
|
+
sleep 5
|
32
|
+
until device && device.state == :active
|
33
|
+
device = find_device(project.id, device.hostname) rescue nil
|
34
|
+
sleep 5
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module Kontena
|
4
|
+
module Machine
|
5
|
+
module Packet
|
6
|
+
module PacketCommon
|
7
|
+
# @param [String] token Packet token
|
8
|
+
def login(token)
|
9
|
+
::Packet::Client.new(token)
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_ssh_key(ssh_key)
|
13
|
+
client.create_ssh_key(ssh_key_label(ssh_key))
|
14
|
+
end
|
15
|
+
|
16
|
+
def ssh_key_exist?(ssh_key)
|
17
|
+
client.list_ssh_keys.any?{|key| key.key == ssh_key}
|
18
|
+
end
|
19
|
+
|
20
|
+
def ssh_key_label(ssh_key)
|
21
|
+
label = ssh_key[/^ssh.+?\s+\S+\s+(.*)$/, 1].to_s.strip
|
22
|
+
label.empty? ? "kontena-ssh-key-#{rand(1..9)}" : label
|
23
|
+
end
|
24
|
+
|
25
|
+
# @param [String] keyfile_path Path to ssh keyfile
|
26
|
+
def check_or_create_ssh_key(keyfile_path)
|
27
|
+
abort('Ssh key file not found') unless File.exist?(keyfile_path)
|
28
|
+
abort('Ssh key file not readable') unless File.readable?(keyfile_path)
|
29
|
+
ssh_key = File.read(keyfile_path).strip
|
30
|
+
create_ssh_key(ssh_key) unless ssh_key_exist?(ssh_key)
|
31
|
+
end
|
32
|
+
|
33
|
+
def find_project(project_id)
|
34
|
+
client.list_projects.find{|project| project.id == project_id}
|
35
|
+
end
|
36
|
+
|
37
|
+
def find_device(project_id, device_hostname)
|
38
|
+
client.list_devices(project_id).find{|device| device.hostname == device_hostname}
|
39
|
+
end
|
40
|
+
|
41
|
+
def find_facility(facility_code)
|
42
|
+
client.list_facilities.find{|f| f.code == facility_code}
|
43
|
+
end
|
44
|
+
|
45
|
+
def find_os(os_code)
|
46
|
+
client.list_operating_systems.find{|os| os.slug == os_code}
|
47
|
+
end
|
48
|
+
|
49
|
+
def find_plan(plan_code)
|
50
|
+
client.list_plans.find{|plan| plan.slug == plan_code}
|
51
|
+
end
|
52
|
+
|
53
|
+
def device_public_ip(device)
|
54
|
+
api_retry "Packet API did not find a public ip address for the device" do
|
55
|
+
device.ip_addresses.find{|ip| ip['public'] && ip['address_family'] == 4}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Retry API requests to recover from random tls errors
|
60
|
+
# @param [String] message Message to output when giving up
|
61
|
+
# @param [Fixnum] times Default: 5
|
62
|
+
def api_retry(message, times=5, &block)
|
63
|
+
attempt = 1
|
64
|
+
begin
|
65
|
+
yield
|
66
|
+
rescue => error
|
67
|
+
ENV['DEBUG'] && puts("Packet API error: #{error}: #{error.message} - attempt #{attempt}")
|
68
|
+
attempt += 1
|
69
|
+
if attempt < times
|
70
|
+
sleep 5 and retry
|
71
|
+
else
|
72
|
+
abort(message)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def user_data(vars, template_filename)
|
78
|
+
cloudinit_template = File.join(__dir__ , template_filename)
|
79
|
+
erb(File.read(cloudinit_template), vars)
|
80
|
+
end
|
81
|
+
|
82
|
+
def erb(template, vars)
|
83
|
+
ERB.new(template, nil, '%<>-').result(OpenStruct.new(vars).instance_eval { binding })
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
@@ -0,0 +1,7 @@
|
|
1
|
+
require 'kontena/machine/random_name'
|
2
|
+
require 'kontena/machine/cert_helper'
|
3
|
+
require_relative 'packet/packet_common'
|
4
|
+
require_relative 'packet/node_provisioner'
|
5
|
+
require_relative 'packet/node_destroyer'
|
6
|
+
require_relative 'packet/node_restarter'
|
7
|
+
require_relative 'packet/master_provisioner'
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
module Kontena::Plugin::Packet::Master
|
4
|
+
class CreateCommand < Kontena::Command
|
5
|
+
include Kontena::Cli::Common
|
6
|
+
|
7
|
+
option "--token", "TOKEN", "Packet API token", required: true
|
8
|
+
option "--project", "PROJECT ID", "Packet project id", required: true
|
9
|
+
option "--ssl-cert", "PATH", "SSL certificate file (optional)"
|
10
|
+
option "--type", "TYPE", "Server type (baremetal_0, baremetal_1, ..)", default: 'baremetal_0', attribute_name: :plan
|
11
|
+
option "--facility", "FACILITY CODE", "Facility", default: 'ams1'
|
12
|
+
option "--billing", "BILLING", "Billing cycle", default: 'hourly'
|
13
|
+
option "--ssh-key", "PATH", "Path to ssh public key (optional)"
|
14
|
+
option "--vault-secret", "VAULT_SECRET", "Secret key for Vault (optional)"
|
15
|
+
option "--vault-iv", "VAULT_IV", "Initialization vector for Vault (optional)"
|
16
|
+
option "--mongodb-uri", "URI", "External MongoDB uri (optional)"
|
17
|
+
option "--version", "VERSION", "Define installed Kontena version", default: 'latest'
|
18
|
+
option "--auth-provider-url", "AUTH_PROVIDER_URL", "Define authentication provider url"
|
19
|
+
|
20
|
+
def execute
|
21
|
+
require_relative '../../../machine/packet'
|
22
|
+
|
23
|
+
provisioner = provisioner(token)
|
24
|
+
provisioner.run!(
|
25
|
+
project: project,
|
26
|
+
billing: billing,
|
27
|
+
ssh_key: ssh_key,
|
28
|
+
ssl_cert: ssl_cert,
|
29
|
+
plan: plan,
|
30
|
+
facility: facility,
|
31
|
+
version: version,
|
32
|
+
auth_server: auth_provider_url,
|
33
|
+
vault_secret: vault_secret || SecureRandom.hex(24),
|
34
|
+
vault_iv: vault_iv || SecureRandom.hex(24),
|
35
|
+
mongodb_uri: mongodb_uri
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
# @param [String] token
|
40
|
+
def provisioner(token)
|
41
|
+
Kontena::Machine::Packet::MasterProvisioner.new(token)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
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::Packet::NodeCommand < Kontena::Command
|
6
|
+
|
7
|
+
subcommand "create", "Create a new node to Packet", Kontena::Plugin::Packet::Nodes::CreateCommand
|
8
|
+
subcommand "restart", "Restart a Packet node", Kontena::Plugin::Packet::Nodes::RestartCommand
|
9
|
+
subcommand "terminate", "Terminate a Packet node", Kontena::Plugin::Packet::Nodes::TerminateCommand
|
10
|
+
|
11
|
+
def execute
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Kontena::Plugin::Packet::Nodes
|
2
|
+
class CreateCommand < Kontena::Command
|
3
|
+
include Kontena::Cli::Common
|
4
|
+
include Kontena::Cli::GridOptions
|
5
|
+
|
6
|
+
parameter "[NAME]", "Node name"
|
7
|
+
option "--token", "TOKEN", "Packet API token", required: true
|
8
|
+
option "--project", "PROJECT ID", "Packet project id", required: true
|
9
|
+
option "--type", "TYPE", "Server type (baremetal_0, baremetal_1, ..)", default: 'baremetal_0', attribute_name: :plan
|
10
|
+
option "--facility", "FACILITY CODE", "Facility", default: 'ams1'
|
11
|
+
option "--billing", "BILLING", "Billing cycle", default: 'hourly'
|
12
|
+
option "--ssh-key", "PATH", "Path to ssh public key (optional)"
|
13
|
+
option "--version", "VERSION", "Define installed Kontena version", default: 'latest'
|
14
|
+
|
15
|
+
def execute
|
16
|
+
require_api_url
|
17
|
+
require_current_grid
|
18
|
+
|
19
|
+
require_relative '../../../machine/packet'
|
20
|
+
grid = fetch_grid
|
21
|
+
provisioner = provisioner(client(require_token), token)
|
22
|
+
provisioner.run!(
|
23
|
+
master_uri: api_url,
|
24
|
+
grid_token: grid['token'],
|
25
|
+
grid: current_grid,
|
26
|
+
project: project,
|
27
|
+
billing: billing,
|
28
|
+
ssh_key: ssh_key,
|
29
|
+
plan: plan,
|
30
|
+
facility: facility,
|
31
|
+
version: version
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
# @param [Kontena::Client] client
|
36
|
+
# @param [String] token
|
37
|
+
def provisioner(client, token)
|
38
|
+
Kontena::Machine::Packet::NodeProvisioner.new(client, token)
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [Hash]
|
42
|
+
def fetch_grid
|
43
|
+
client(require_token).get("grids/#{current_grid}")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Kontena::Plugin::Packet::Nodes
|
2
|
+
class RestartCommand < Kontena::Command
|
3
|
+
include Kontena::Cli::Common
|
4
|
+
include Kontena::Cli::GridOptions
|
5
|
+
|
6
|
+
parameter "NAME", "Node name"
|
7
|
+
option "--token", "TOKEN", "Packet API token", required: true
|
8
|
+
option "--project", "PROJECT ID", "Packet project id", required: true
|
9
|
+
|
10
|
+
def execute
|
11
|
+
require_relative '../../../machine/packet'
|
12
|
+
|
13
|
+
restarter = Kontena::Machine::Packet::NodeRestarter.new(token)
|
14
|
+
restarter.run!(project, name)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Kontena::Plugin::Packet::Nodes
|
2
|
+
class TerminateCommand < Kontena::Command
|
3
|
+
include Kontena::Cli::Common
|
4
|
+
include Kontena::Cli::GridOptions
|
5
|
+
|
6
|
+
parameter "NAME", "Node name"
|
7
|
+
option "--token", "TOKEN", "Packet API token", required: true
|
8
|
+
option "--project", "PROJECT ID", "Packet project id", required: true
|
9
|
+
|
10
|
+
def execute
|
11
|
+
require_api_url
|
12
|
+
require_current_grid
|
13
|
+
|
14
|
+
require_relative '../../../machine/packet'
|
15
|
+
grid = client(require_token).get("grids/#{current_grid}")
|
16
|
+
destroyer = destroyer(client(require_token), token)
|
17
|
+
destroyer.run!(grid, project, name)
|
18
|
+
end
|
19
|
+
|
20
|
+
# @param [Kontena::Client] client
|
21
|
+
# @param [String] token
|
22
|
+
def destroyer(client, token)
|
23
|
+
Kontena::Machine::Packet::NodeDestroyer.new(client, token)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require_relative 'packet/master_command'
|
2
|
+
require_relative 'packet/node_command'
|
3
|
+
|
4
|
+
class Kontena::Plugin::PacketCommand < Kontena::Command
|
5
|
+
|
6
|
+
subcommand 'master', 'Packet master related commands', Kontena::Plugin::Packet::MasterCommand
|
7
|
+
subcommand 'node', 'Packet node related commands', Kontena::Plugin::Packet::NodeCommand
|
8
|
+
|
9
|
+
def execute
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kontena-plugin-packet
|
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-11 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: packethost
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.6
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.6
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.11'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.11'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: Packet provision plugin for Kontena
|
70
|
+
email:
|
71
|
+
- info@kontena.io
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .gitmodules
|
78
|
+
- .rspec
|
79
|
+
- .travis.yml
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- kontena-plugin-packet.gemspec
|
84
|
+
- lib/kontena/machine/packet.rb
|
85
|
+
- lib/kontena/machine/packet/cloudinit.yml
|
86
|
+
- lib/kontena/machine/packet/cloudinit_master.yml
|
87
|
+
- lib/kontena/machine/packet/master_provisioner.rb
|
88
|
+
- lib/kontena/machine/packet/node_destroyer.rb
|
89
|
+
- lib/kontena/machine/packet/node_provisioner.rb
|
90
|
+
- lib/kontena/machine/packet/node_restarter.rb
|
91
|
+
- lib/kontena/machine/packet/packet_common.rb
|
92
|
+
- lib/kontena/plugin/packet.rb
|
93
|
+
- lib/kontena/plugin/packet/master/create_command.rb
|
94
|
+
- lib/kontena/plugin/packet/master_command.rb
|
95
|
+
- lib/kontena/plugin/packet/node_command.rb
|
96
|
+
- lib/kontena/plugin/packet/nodes/create_command.rb
|
97
|
+
- lib/kontena/plugin/packet/nodes/restart_command.rb
|
98
|
+
- lib/kontena/plugin/packet/nodes/terminate_command.rb
|
99
|
+
- lib/kontena/plugin/packet_command.rb
|
100
|
+
- lib/kontena_cli_plugin.rb
|
101
|
+
homepage: https://github.com/kontena/kontena-plugin-packet
|
102
|
+
licenses:
|
103
|
+
- Apache-2.0
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ! '>='
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.4.5
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Kontena Packet plugin
|
125
|
+
test_files: []
|