vagrant-noderings 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f32d1aeb7b7253221ea142df1e8b20a13bc78f8e96f0d800e09731277db53ba0
4
+ data.tar.gz: 491039a990e00fc93737d5c22916e59f94b514aa638d484aa65a0e00e2438c0f
5
+ SHA512:
6
+ metadata.gz: 8e309a84fc6352cfac3e676ad756a9c4051f5e3362e9bd963713ae2e25af88cadb809cb8fbe218dc1bdb8dad74c508452089891bc902ea90051c41e7d3b0b51e
7
+ data.tar.gz: 530ea874e3c67310ae33cc42b84fccf1b6e2d3f4cc95610deb458afbf04b6127ece5e9277567732d9688389d12e508fbd0bf0741bf69fc35670636b939605a0f
data/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses
5
+ [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.0] - 2026-11-25
10
+
11
+ ### Added
12
+
13
+ - The `noderings` provider: `vagrant up` orders the cheapest matching NodeRings
14
+ marketplace offer (or the best rated, or an exact plan and region), waits for SSH, and
15
+ runs provisioners. No box is needed; the operating system comes from `distro`.
16
+ - `vagrant halt`, `reload`, `ssh`, `provision`, `status` and `destroy`. Destroy also
17
+ deletes the temporary SSH key.
18
+ - A per-machine SSH key, generated in `.vagrant/` and uploaded as a temporary NodeRings
19
+ key, or existing NodeRings keys via `ssh_keys`.
20
+ - Synced folders over rsync.
21
+ - Optional firewall ruleset, tags, billing type and provider selection.
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2023 jeanluc
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,155 @@
1
+ # vagrant-noderings
2
+
3
+ [![CI](https://github.com/noderings/vagrant-noderings/actions/workflows/ci.yml/badge.svg)](https://github.com/noderings/vagrant-noderings/actions/workflows/ci.yml)
4
+ [![Gem Version](https://img.shields.io/gem/v/vagrant-noderings.svg)](https://rubygems.org/gems/vagrant-noderings)
5
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
6
+
7
+ A [Vagrant](https://www.vagrantup.com) provider for [NodeRings](https://noderings.com). Run
8
+ your development and test machines on NodeRings virtual machines with the usual
9
+ `vagrant up`, `vagrant ssh` and `vagrant destroy`.
10
+
11
+ New to it? The step-by-step guide [How to use Vagrant on NodeRings: a cloud VPS as a disposable dev box](https://noderings.com/blog/vagrant-vps) walks through a first run.
12
+
13
+ ```ruby
14
+ Vagrant.configure("2") do |config|
15
+ config.vm.provider :noderings do |provider|
16
+ provider.plan = "SC-GC-1C-1G-20"
17
+ provider.country = "United States"
18
+ provider.city = "Ashburn"
19
+ provider.distro = "ubuntu_24_04"
20
+ end
21
+
22
+ config.vm.provision "shell", inline: "apt-get update && apt-get install -y nginx"
23
+ end
24
+ ```
25
+
26
+ ```shell
27
+ export NODERINGS_TOKEN=... # a NodeRings service account token
28
+ vagrant up --provider=noderings
29
+ vagrant ssh
30
+ vagrant destroy
31
+ ```
32
+
33
+ `vagrant up` orders the cheapest NodeRings offer for the plan in that city, waits until
34
+ SSH answers, syncs the project folder to `/vagrant` and runs the provisioners. No box is
35
+ needed: the operating system comes from `distro`.
36
+
37
+ ## Requirements
38
+
39
+ * Vagrant 2.2 or later
40
+ * `rsync` on your workstation, for synced folders
41
+ * A NodeRings service account token. Create one in the NodeRings console under
42
+ **Organization → Access Control → Service accounts**.
43
+ * A payment method or credit on the organization. Ordering a server is billed; hourly
44
+ (usage) plans stop billing when `vagrant destroy` deletes the server.
45
+
46
+ ## Installation
47
+
48
+ ```shell
49
+ vagrant plugin install vagrant-noderings
50
+ ```
51
+
52
+ ## Commands
53
+
54
+ | Command | What happens on NodeRings |
55
+ | --- | --- |
56
+ | `vagrant up` | Orders the server, or starts it if it is stopped, then provisions it |
57
+ | `vagrant ssh` | Logs in as `root` with the machine's key |
58
+ | `vagrant provision` | Runs the provisioners again |
59
+ | `vagrant halt` | Stops the server; its disk and IP addresses are kept |
60
+ | `vagrant reload` | Stops and starts the server, then provisions if asked to |
61
+ | `vagrant status` | Shows `running`, `stopped` or `not created` |
62
+ | `vagrant destroy` | Deletes the server and its temporary SSH key |
63
+
64
+ ## Configuration
65
+
66
+ Set these on the provider in your `Vagrantfile`:
67
+
68
+ | Option | Default | Description |
69
+ | --- | --- | --- |
70
+ | `token` | `NODERINGS_TOKEN` environment variable | API token. Prefer the environment variable to keep it out of the `Vagrantfile`. |
71
+ | `api_url` | `https://api.noderings.com` | API endpoint (`NODERINGS_API_URL`). |
72
+ | `organization_id` | none | Organization to act in, for tokens that can reach more than one (`NODERINGS_ORGANIZATION_ID`). |
73
+ | `plan` | none | Plan code to order, such as `SC-GC-1C-1G-20`. Required with `country` and `city`. |
74
+ | `country` | none | Country of the offer, such as `United States`. |
75
+ | `city` | none | City of the offer, such as `Ashburn`. |
76
+ | `billing_type` | `usage` | `usage` (hourly), `subscription` (monthly) or `free`. |
77
+ | `sort` | `price` | Order the cheapest matching offer, or the best rated with `rating`. |
78
+ | `provider_id` | none | Only consider offers from this provider. |
79
+ | `plan_id`, `region_id` | none | An exact plan and region, instead of `plan`, `country` and `city`. |
80
+ | `distro` | `ubuntu_24_04` | Operating system: `ubuntu_22_04`, `ubuntu_24_04`, `ubuntu_26_04`, `debian_12`, `debian_13`, `fedora_43`, `fedora_44`, `centos_9`, `centos_10`, `almalinux_9`, `almalinux_10`, `rocky_9` or `rocky_10`. |
81
+ | `hostname` | `vagrant-<machine>-<random>` | Hostname of the server (one DNS label). |
82
+ | `ssh_keys` | `[]` | Names or IDs of NodeRings SSH keys to install instead of a generated key. |
83
+ | `firewall_ruleset` | none | Name or ID of a firewall ruleset to attach. It must allow SSH from your workstation. |
84
+ | `tags` | `["vagrant"]` | Tags on the server. |
85
+ | `wait_timeout` | `900` | Seconds to wait for each operation. |
86
+
87
+ To see which plans are sold where, use the NodeRings console marketplace, or
88
+ `knife noderings plan list --country "United States" --city Ashburn` from
89
+ [knife-noderings](https://github.com/noderings/knife-noderings).
90
+
91
+ ### SSH keys
92
+
93
+ By default the provider generates an RSA key for each machine in
94
+ `.vagrant/machines/<name>/noderings/state/`, uploads its public half to NodeRings as a
95
+ temporary key, logs in with it, and deletes both on `vagrant destroy`.
96
+
97
+ To use keys already stored in NodeRings, list them in `ssh_keys` and point Vagrant at
98
+ the matching private key:
99
+
100
+ ```ruby
101
+ config.vm.provider :noderings do |provider, override|
102
+ provider.ssh_keys = ["laptop"]
103
+ override.ssh.private_key_path = "~/.ssh/id_ed25519"
104
+ end
105
+ ```
106
+
107
+ ### Synced folders
108
+
109
+ The project folder is synced to `/vagrant` with rsync when the machine comes up and on
110
+ `vagrant reload`. Run `vagrant rsync` to sync again, or `vagrant rsync-auto` to sync on
111
+ every change. NFS and SMB folders are not available on a remote server.
112
+
113
+ ### Several machines
114
+
115
+ ```ruby
116
+ Vagrant.configure("2") do |config|
117
+ config.vm.provider :noderings do |provider|
118
+ provider.plan = "SC-GC-1C-1G-20"
119
+ provider.country = "United States"
120
+ provider.city = "Ashburn"
121
+ end
122
+
123
+ config.vm.define "web" do |web|
124
+ web.vm.provider(:noderings) { |p| p.distro = "ubuntu_24_04" }
125
+ end
126
+
127
+ config.vm.define "db" do |db|
128
+ db.vm.provider(:noderings) { |p| p.distro = "debian_13" }
129
+ end
130
+ end
131
+ ```
132
+
133
+ `vagrant up --provider=noderings` orders both servers in parallel.
134
+
135
+ ## Development
136
+
137
+ ```shell
138
+ bundle install
139
+ bundle exec rake # RuboCop and the unit tests
140
+ ```
141
+
142
+ The unit tests run against an in-memory NodeRings API, so they need no token. To try a
143
+ change with the real Vagrant and the real API (this orders a billed server):
144
+
145
+ ```shell
146
+ gem build vagrant-noderings.gemspec
147
+ vagrant plugin install ./vagrant-noderings-0.1.0.gem
148
+ NODERINGS_TOKEN=... vagrant up --provider=noderings
149
+ ```
150
+
151
+ See [CONTRIBUTING.md](CONTRIBUTING.md).
152
+
153
+ ## License
154
+
155
+ Copyright NodeRings. Licensed under the [Apache License, Version 2.0](LICENSE).
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ module Noderings
5
+ module Action
6
+ # Removes the temporary key when the server is already gone.
7
+ class CleanupFiles
8
+ def initialize(app, _env)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ Session.new(env[:machine]).cleanup if env[:machine].data_dir.join("state").exist?
14
+ @app.call(env)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ module Noderings
5
+ module Action
6
+ # Orders the server, waits for its address and for SSH.
7
+ class CreateServer
8
+ def initialize(app, _env)
9
+ @app = app
10
+ @logger = Log4r::Logger.new("vagrant_noderings::action::create_server")
11
+ end
12
+
13
+ def call(env)
14
+ machine = env[:machine]
15
+ session = Session.new(machine)
16
+ config = session.config
17
+ compute = session.compute
18
+ client = session.client
19
+
20
+ plan_id, region_id, what = offer(session)
21
+ keys = session.ssh_key_ids
22
+ hostname = session.hostname
23
+ env[:ui].info(I18n.t("vagrant_noderings.ordering", hostname: hostname, offer: what,
24
+ distro: compute.normalize_distro(config.distro)))
25
+ vm = session.call("ordering #{hostname}") do
26
+ compute.order_vm(client, hostname, plan_id, region_id, distro: config.distro, ssh_key_ids: keys,
27
+ tags: config.tags, wait: false, timeout: config.wait_timeout)
28
+ end
29
+ # Remember the server at once, so an interrupted `up` can still be destroyed.
30
+ machine.id = vm["id"]
31
+ env[:ui].info(I18n.t("vagrant_noderings.ordered", id: vm["id"]))
32
+
33
+ vm = session.call("waiting for #{hostname}") { compute.wait_address(client, vm["id"], config.wait_timeout) }
34
+ if config.firewall_ruleset
35
+ ruleset = session.call("resolving the firewall ruleset") { compute.resolve_ruleset(client, config.firewall_ruleset) }
36
+ session.call("attaching the firewall") { compute.attach_firewall(client, vm["id"], ruleset, timeout: config.wait_timeout) }
37
+ end
38
+ env[:ui].info(I18n.t("vagrant_noderings.address", address: vm["ipv4"] || vm["ipv6"]))
39
+ WaitForCommunicator.wait(env, config.wait_timeout) unless env[:interrupted]
40
+ @app.call(env)
41
+ end
42
+
43
+ def offer(session)
44
+ config = session.config
45
+ return [config.plan_id, config.region_id, "plan #{config.plan_id}"] if config.plan_id && config.region_id
46
+
47
+ plan_id, region_id, offer = session.call("finding an offer") do
48
+ session.compute.choose_offer(session.client, config.plan, config.country, config.city,
49
+ billing_type: config.billing_type, provider_id: config.provider_id, sort: config.sort)
50
+ end
51
+ [plan_id, region_id, "#{config.plan} from #{offer['provider_name']} in #{config.city}, #{config.country}"]
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ module Noderings
5
+ module Action
6
+ # Deletes the server and the temporary SSH key.
7
+ class DestroyServer
8
+ def initialize(app, _env)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ machine = env[:machine]
14
+ session = Session.new(machine)
15
+ env[:ui].info(I18n.t("vagrant_noderings.destroying"))
16
+ session.call("deleting the server") do
17
+ session.compute.waiter(session.client, session.config.wait_timeout).retry_busy do
18
+ session.client.delete_virtual_machine(machine.id)
19
+ rescue NoderingsVagrant::APIError => e
20
+ raise unless e.not_found?
21
+ end
22
+ end
23
+ session.cleanup
24
+ machine.id = nil
25
+ @app.call(env)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ module Noderings
5
+ module Action
6
+ # Sets env[:result] to whether the server exists.
7
+ class IsCreated
8
+ def initialize(app, _env)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ env[:result] = env[:machine].state.id != :not_created
14
+ @app.call(env)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ module Noderings
5
+ module Action
6
+ # Sets env[:result] to whether the server is stopped.
7
+ class IsStopped
8
+ def initialize(app, _env)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ env[:result] = env[:machine].state.id == :stopped
14
+ @app.call(env)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ module Noderings
5
+ module Action
6
+ # Puts the SSH details of the server in env[:machine_ssh_info].
7
+ class ReadSSHInfo
8
+ def initialize(app, _env)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ env[:machine_ssh_info] = read(env[:machine])
14
+ @app.call(env)
15
+ end
16
+
17
+ def read(machine)
18
+ session = Session.new(machine)
19
+ vm = session.vm
20
+ return nil if vm.nil?
21
+
22
+ host = vm["ipv4"].to_s.empty? ? vm["ipv6"] : vm["ipv4"]
23
+ return nil if host.to_s.empty?
24
+
25
+ info = { host: host, port: 22, username: "root" }
26
+ info[:private_key_path] = [session.private_key_path.to_s] if session.generated_key?
27
+ info
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ module Noderings
5
+ module Action
6
+ # Puts the server's state in env[:machine_state_id].
7
+ #
8
+ # NodeRings reports a server that has booted after its order as "created";
9
+ # Vagrant calls that running.
10
+ class ReadState
11
+ STATES = { "running" => :running, "created" => :running, "stopped" => :stopped }.freeze
12
+
13
+ def initialize(app, _env)
14
+ @app = app
15
+ end
16
+
17
+ def call(env)
18
+ machine = env[:machine]
19
+ if machine.id.nil?
20
+ env[:machine_state_id] = :not_created
21
+ else
22
+ vm = Session.new(machine).vm
23
+ if vm.nil?
24
+ # Deleted outside Vagrant.
25
+ machine.id = nil
26
+ env[:machine_state_id] = :not_created
27
+ else
28
+ state = NoderingsVagrant::Compute.power_state(vm)
29
+ env[:machine_state_id] = STATES.fetch(state, state.to_sym)
30
+ end
31
+ end
32
+ @app.call(env)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ module Noderings
5
+ module Action
6
+ class StartServer
7
+ def initialize(app, _env)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ session = Session.new(env[:machine])
13
+ env[:ui].info(I18n.t("vagrant_noderings.starting"))
14
+ session.call("starting the server") do
15
+ session.compute.set_power(session.client, env[:machine].id, "running", timeout: session.config.wait_timeout)
16
+ end
17
+ WaitForCommunicator.wait(env, session.config.wait_timeout)
18
+ @app.call(env)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VagrantPlugins
4
+ module Noderings
5
+ module Action
6
+ # Stops the server. Its disk and IP addresses are kept.
7
+ class StopServer
8
+ def initialize(app, _env)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ if env[:machine].state.id == :stopped
14
+ env[:ui].info(I18n.t("vagrant_noderings.already_stopped"))
15
+ else
16
+ session = Session.new(env[:machine])
17
+ env[:ui].info(I18n.t("vagrant_noderings.stopping"))
18
+ session.call("stopping the server") do
19
+ session.compute.set_power(session.client, env[:machine].id, "stopped", timeout: session.config.wait_timeout)
20
+ end
21
+ end
22
+ @app.call(env)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end