vagrant-vultr_pro 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.projections.json +4 -0
- data/CHANGELOG.md +23 -0
- data/Gemfile +9 -0
- data/LICENSE.md +20 -0
- data/README.md +116 -0
- data/Rakefile +17 -0
- data/box/vultr.box +0 -0
- data/features/support/env.rb +11 -0
- data/features/vagrant-vultr.feature +78 -0
- data/lib/vagrant-vultr/action/check_state.rb +20 -0
- data/lib/vagrant-vultr/action/create.rb +73 -0
- data/lib/vagrant-vultr/action/destroy.rb +30 -0
- data/lib/vagrant-vultr/action/power_off.rb +25 -0
- data/lib/vagrant-vultr/action/power_on.rb +32 -0
- data/lib/vagrant-vultr/action/reload.rb +32 -0
- data/lib/vagrant-vultr/action/setup_ssh_key.rb +31 -0
- data/lib/vagrant-vultr/action.rb +132 -0
- data/lib/vagrant-vultr/config.rb +76 -0
- data/lib/vagrant-vultr/helpers/client.rb +156 -0
- data/lib/vagrant-vultr/plugin.rb +18 -0
- data/lib/vagrant-vultr/provider.rb +48 -0
- data/lib/vagrant-vultr_pro.rb +12 -0
- data/lib/vultr/version.rb +10 -0
- data/lib/vultr/vultr.rb +888 -0
- data/vagrant-vultr_pro.gemspec +24 -0
- metadata +152 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: af7e04eb1e12c5f8c361ca9048bb5845c48edb049a54df7253ac37de9f95c702
|
4
|
+
data.tar.gz: 0f2e346487d9e580924718d23067e90d83f31d5b3a47e371ccfe8ffdc11291a5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a86c1a36f3a57040692ed7d27838e5c24f8b06c16acd485bb0a39e7844335c690e82cebfa039f097ede800b35a2f508aac66a58294dab2646c3df2903f035583
|
7
|
+
data.tar.gz: bee7783e0e1db418ddf877a33d0be06e28f7f9f14564b23d0c1803f1c912e1d9cab195ab1beb216bbe05b401bdb1d33f28ff59465809c7747a3cd873a1070c94
|
data/.gitignore
ADDED
data/.projections.json
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
## 0.2.0
|
2
|
+
|
3
|
+
* Add the 'label', 'tag', and 'hostname' parameters to create_server.
|
4
|
+
|
5
|
+
* Add the 'ssh_key' and 'startup_script' parameters to create_server.
|
6
|
+
|
7
|
+
* Add the 'timeout' parameter to `client.rb`.
|
8
|
+
|
9
|
+
* Fix the bug of vultr v0.4.3 for `reboot` method.
|
10
|
+
|
11
|
+
* Fix the bug of `wait_to_power_on` method when ssh is not ready
|
12
|
+
|
13
|
+
## 0.1.2
|
14
|
+
|
15
|
+
* Fixed issues with renamed Vultr API (#4, #5)
|
16
|
+
|
17
|
+
## 0.1.1
|
18
|
+
|
19
|
+
* Fix issue with plan selection (#1)
|
20
|
+
|
21
|
+
## 0.1.0
|
22
|
+
|
23
|
+
* Initial release
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2015 Alex Rodionov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
vagrant-vultr_pro [](http://badge.fury.io/rb/vagrant-vultr)
|
2
|
+
============
|
3
|
+
|
4
|
+
Vagrant plugin that allows to use [Vultr](https://vultr.com/) as provider.
|
5
|
+
|
6
|
+
For now, basic operations like vagrant up/halt/reload/destroy/provision are supported.
|
7
|
+
|
8
|
+
Installation
|
9
|
+
------------
|
10
|
+
|
11
|
+
```bash
|
12
|
+
$ vagrant plugin install vagrant-vultr_pro
|
13
|
+
```
|
14
|
+
|
15
|
+
Usage
|
16
|
+
-----
|
17
|
+
|
18
|
+
Create simple Vagrantfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
Vagrant.configure(2) do |config|
|
22
|
+
config.vm.provider :vultr do |vultr, override|
|
23
|
+
override.ssh.private_key_path = '~/.ssh/id_rsa'
|
24
|
+
override.vm.box = 'vultr'
|
25
|
+
override.vm.box_url = 'https://github.com/p0deje/vagrant-vultr/raw/master/box/vultr.box'
|
26
|
+
|
27
|
+
vultr.token = 'YOUR_TOKEN' # You can also use VULTR_TOKEN environment variable
|
28
|
+
vultr.region = 'Seattle'
|
29
|
+
vultr.plan = '768 MB RAM,15 GB SSD,1.00 TB BW'
|
30
|
+
|
31
|
+
# Use either OS name or Snapshot identifier
|
32
|
+
vultr.os = 'Ubuntu 14.04 x64'
|
33
|
+
vultr.snapshot = '524557af2439b'
|
34
|
+
|
35
|
+
# Optional parameters
|
36
|
+
vultr.label = 'My Label'
|
37
|
+
vultr.tag = 'My Tag'
|
38
|
+
vultr.hostname = 'myhostname'
|
39
|
+
|
40
|
+
# New optional parameters
|
41
|
+
vultr.timeout = 300
|
42
|
+
vultr.ssh_key = 'vagrant'
|
43
|
+
vultr.startup_script = 'user'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
Now start vagrant box:
|
49
|
+
|
50
|
+
```bash
|
51
|
+
$ vagrant up --provider=vultr
|
52
|
+
```
|
53
|
+
|
54
|
+
Notes
|
55
|
+
-----
|
56
|
+
|
57
|
+
1. You have to specify `override.ssh.private_key_path`. Public key will be uploaded to Vultr as "vagrant" SSH key and will be used when servers are created.
|
58
|
+
2. Currently, servers are created with "root" user.
|
59
|
+
3. If you hit API rate limit, you can set `VULTR_RATE_LIMIT_INTERVAL_MS` environment variable to introduce delay between API requests.
|
60
|
+
|
61
|
+
Build
|
62
|
+
-------
|
63
|
+
|
64
|
+
First commit all modifications to git, and then upload gem to `https://rubygems.org` by command below:
|
65
|
+
|
66
|
+
```bash
|
67
|
+
$ rake release
|
68
|
+
```
|
69
|
+
|
70
|
+
If you have any mistake for uploaded gem, you can remove it from `https://rubygems.org` by command below:
|
71
|
+
|
72
|
+
```bash
|
73
|
+
$ gem yank vagrant-vultr_pro -v 0.2.0
|
74
|
+
```
|
75
|
+
|
76
|
+
Testing
|
77
|
+
-------
|
78
|
+
|
79
|
+
First of all, add the box that is used for testing:
|
80
|
+
|
81
|
+
```bash
|
82
|
+
$ bundle exec rake box:add
|
83
|
+
```
|
84
|
+
|
85
|
+
Since the tests involve actual calls to Vultr, you have to provide a valid API token:
|
86
|
+
|
87
|
+
```bash
|
88
|
+
$ export VULTR_TOKEN="token"
|
89
|
+
```
|
90
|
+
|
91
|
+
Now you can run tests:
|
92
|
+
|
93
|
+
```bash
|
94
|
+
$ bundle exec rake cucumber
|
95
|
+
```
|
96
|
+
|
97
|
+
Note that Vultr is not very stable, so tests sometimes may fail due to timeout or 404 API requests.
|
98
|
+
|
99
|
+
In the end, remove the box:
|
100
|
+
|
101
|
+
```bash
|
102
|
+
$ bundle exec rake box:remove
|
103
|
+
```
|
104
|
+
|
105
|
+
Contributing
|
106
|
+
------------
|
107
|
+
|
108
|
+
* Fork the project.
|
109
|
+
* Make your feature addition or bug fix.
|
110
|
+
* Commit, do not mess with Rakefile, version, or history. If you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull.
|
111
|
+
* Send me a pull request. Bonus points for topic branches.
|
112
|
+
|
113
|
+
Copyright
|
114
|
+
---------
|
115
|
+
|
116
|
+
Copyright (c) 2015 Alex Rodionov. See LICENSE.md for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
namespace :box do
|
5
|
+
desc 'Adds test vagrant box.'
|
6
|
+
task :add do
|
7
|
+
sh 'bundle exec vagrant box add --name vultr ./box/vultr.box'
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Removes testing vagrant box.'
|
11
|
+
task :remove do
|
12
|
+
sh 'bundle exec vagrant box remove vultr'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
require 'cucumber/rake/task'
|
17
|
+
Cucumber::Rake::Task.new
|
data/box/vultr.box
ADDED
Binary file
|
@@ -0,0 +1,78 @@
|
|
1
|
+
@announce
|
2
|
+
@no-clobber
|
3
|
+
Feature: vagrant-vultr_pro
|
4
|
+
In order to use Vultr
|
5
|
+
As a Vagrant provider
|
6
|
+
I want to use plugin for that
|
7
|
+
|
8
|
+
Background:
|
9
|
+
Given I write to "Vagrantfile" with:
|
10
|
+
"""
|
11
|
+
Vagrant.configure(2) do |config|
|
12
|
+
config.vm.box = 'vultr'
|
13
|
+
config.vm.synced_folder '.', '/vagrant', type: 'rsync'
|
14
|
+
config.ssh.private_key_path = '~/.ssh/id_rsa'
|
15
|
+
|
16
|
+
config.vm.provision 'shell',
|
17
|
+
inline: 'echo "it works" > /tmp/vultr-provision',
|
18
|
+
privileged: false
|
19
|
+
end
|
20
|
+
"""
|
21
|
+
|
22
|
+
Scenario: creates server on up
|
23
|
+
When I run `bundle exec vagrant up --provider=vultr`
|
24
|
+
Then the exit status should be 0
|
25
|
+
And the output should contain "Machine is booted and ready to use!"
|
26
|
+
When I run `bundle exec vagrant status`
|
27
|
+
Then the output should contain "active (vultr)"
|
28
|
+
|
29
|
+
Scenario: starts created server on up
|
30
|
+
When I run `bundle exec vagrant up --provider=vultr`
|
31
|
+
And I run `bundle exec vagrant halt`
|
32
|
+
And I run `bundle exec vagrant up --provider=vultr`
|
33
|
+
Then the exit status should be 0
|
34
|
+
And the output should contain "Machine is booted and ready to use!"
|
35
|
+
When I run `bundle exec vagrant status`
|
36
|
+
Then the output should contain "active (vultr)"
|
37
|
+
|
38
|
+
Scenario: syncs folders
|
39
|
+
When I run `bundle exec vagrant up --provider=vultr`
|
40
|
+
And I run `bundle exec vagrant ssh -c "test -d /vagrant"`
|
41
|
+
Then the exit status should be 0
|
42
|
+
|
43
|
+
Scenario: provisions server
|
44
|
+
When I run `bundle exec vagrant up --provider=vultr`
|
45
|
+
And I run `bundle exec vagrant ssh -c "cat /tmp/vultr-provision"`
|
46
|
+
Then the exit status should be 0
|
47
|
+
And the output should contain "it works"
|
48
|
+
|
49
|
+
Scenario: executes SSH to created server
|
50
|
+
When I run `bundle exec vagrant up --provider=vultr`
|
51
|
+
And I run `bundle exec vagrant ssh` interactively
|
52
|
+
And I type "uname -a"
|
53
|
+
And I close the stdin stream
|
54
|
+
Then the output should contain "vultr.guest"
|
55
|
+
|
56
|
+
Scenario: reboots server on reload
|
57
|
+
When I run `bundle exec vagrant up --provider=vultr`
|
58
|
+
And I run `bundle exec vagrant reload`
|
59
|
+
Then the exit status should be 0
|
60
|
+
And the output should contain "Machine is booted and ready to use!"
|
61
|
+
When I run `bundle exec vagrant status`
|
62
|
+
Then the output should contain "active (vultr)"
|
63
|
+
|
64
|
+
Scenario: shutdowns server on halt
|
65
|
+
When I run `bundle exec vagrant up --provider=vultr`
|
66
|
+
And I run `bundle exec vagrant halt`
|
67
|
+
Then the exit status should be 0
|
68
|
+
And the output should contain "Machine is stopped."
|
69
|
+
When I run `bundle exec vagrant status`
|
70
|
+
Then the output should contain "off (vultr)"
|
71
|
+
|
72
|
+
Scenario: removes server on destroy
|
73
|
+
When I run `bundle exec vagrant up --provider=vultr`
|
74
|
+
And I run `bundle exec vagrant destroy --force`
|
75
|
+
Then the exit status should be 0
|
76
|
+
And the output should contain "Machine is destroyed."
|
77
|
+
When I run `bundle exec vagrant status`
|
78
|
+
Then the output should contain "not created"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Vultr
|
3
|
+
module Action
|
4
|
+
class CheckState
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
@machine = env[:machine]
|
8
|
+
@logger = Log4r::Logger.new('vagrant::vultr::check_state')
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
env[:machine_state] = @machine.state.id
|
13
|
+
@logger.info "Machine state is '#{@machine.state.id}'."
|
14
|
+
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'vagrant-vultr/helpers/client'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Vultr
|
5
|
+
module Action
|
6
|
+
class Create
|
7
|
+
include Helpers::Client
|
8
|
+
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@machine = env[:machine]
|
12
|
+
@client = client
|
13
|
+
@logger = Log4r::Logger.new('vagrant::vultr::create')
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
region = env[:machine].provider_config.region
|
18
|
+
plan = env[:machine].provider_config.plan
|
19
|
+
os = env[:machine].provider_config.os
|
20
|
+
snapshot = env[:machine].provider_config.snapshot
|
21
|
+
enable_ipv6 = env[:machine].provider_config.enable_ipv6
|
22
|
+
enable_private_network = env[:machine].provider_config.enable_private_network
|
23
|
+
label = env[:machine].provider_config.label
|
24
|
+
tag = env[:machine].provider_config.tag
|
25
|
+
hostname = env[:machine].provider_config.hostname
|
26
|
+
ssh_key = env[:machine].provider_config.ssh_key
|
27
|
+
startup_script = env[:machine].provider_config.startup_script
|
28
|
+
|
29
|
+
@logger.info "Creating server with:"
|
30
|
+
@logger.info " -- Region: #{region}"
|
31
|
+
@logger.info " -- OS: #{os}"
|
32
|
+
@logger.info " -- Plan: #{plan}"
|
33
|
+
@logger.info " -- Snapshot: #{snapshot}"
|
34
|
+
@logger.info " -- Enable IPv6: #{enable_ipv6}"
|
35
|
+
@logger.info " -- Enable Private Network: #{enable_private_network}"
|
36
|
+
@logger.info " -- Label: #{label}"
|
37
|
+
@logger.info " -- Tag: #{tag}"
|
38
|
+
@logger.info " -- Hostname: #{hostname}"
|
39
|
+
@logger.info " -- Ssh key: #{ssh_key}"
|
40
|
+
@logger.info " -- Startup script: #{startup_script}"
|
41
|
+
|
42
|
+
attributes = {
|
43
|
+
region: region,
|
44
|
+
os: os,
|
45
|
+
plan: plan,
|
46
|
+
snapshot: snapshot,
|
47
|
+
enable_ipv6: enable_ipv6,
|
48
|
+
enable_private_network: enable_private_network,
|
49
|
+
label: label,
|
50
|
+
tag: tag,
|
51
|
+
hostname: hostname,
|
52
|
+
ssh_key_name: ssh_key,
|
53
|
+
startup_script_name: startup_script,
|
54
|
+
}
|
55
|
+
@machine.id = @client.create_server(attributes)
|
56
|
+
|
57
|
+
env[:ui].info 'Waiting for subscription to become active...'
|
58
|
+
@client.wait_to_activate(@machine.id)
|
59
|
+
|
60
|
+
env[:ui].info 'Waiting for server to start...'
|
61
|
+
@client.wait_to_power_on(@machine.id)
|
62
|
+
|
63
|
+
env[:ui].info 'Waiting for SSH to become active...'
|
64
|
+
@client.wait_for_ssh(@machine)
|
65
|
+
|
66
|
+
env[:ui].info 'Machine is booted and ready to use!'
|
67
|
+
|
68
|
+
@app.call(env)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'vagrant-vultr/helpers/client'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Vultr
|
5
|
+
module Action
|
6
|
+
class Destroy
|
7
|
+
include Helpers::Client
|
8
|
+
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@machine = env[:machine]
|
12
|
+
@client = client
|
13
|
+
@logger = Log4r::Logger.new('vagrant::vultr::destroy')
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
@client.destroy_server(@machine.id)
|
18
|
+
|
19
|
+
env[:ui].info 'Waiting for server to be destroyed...'
|
20
|
+
@client.wait_to_destroy(@machine.id)
|
21
|
+
|
22
|
+
env[:ui].info 'Machine is destroyed.'
|
23
|
+
@machine.id = nil
|
24
|
+
|
25
|
+
@app.call(env)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'vagrant-vultr/helpers/client'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Vultr
|
5
|
+
module Action
|
6
|
+
class PowerOff
|
7
|
+
include Helpers::Client
|
8
|
+
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@machine = env[:machine]
|
12
|
+
@client = client
|
13
|
+
@logger = Log4r::Logger.new('vagrant::vultr::power_off')
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
@client.stop_server(@machine.id)
|
18
|
+
env[:ui].info 'Machine is stopped.'
|
19
|
+
|
20
|
+
@app.call(env)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'vagrant-vultr/helpers/client'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Vultr
|
5
|
+
module Action
|
6
|
+
class PowerOn
|
7
|
+
include Helpers::Client
|
8
|
+
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@machine = env[:machine]
|
12
|
+
@client = client
|
13
|
+
@logger = Log4r::Logger.new('vagrant::vultr::power_on')
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
@client.start_server(@machine.id)
|
18
|
+
|
19
|
+
env[:ui].info 'Waiting for server to start...'
|
20
|
+
@client.wait_to_power_on(@machine.id)
|
21
|
+
|
22
|
+
env[:ui].info 'Waiting for SSH to become active...'
|
23
|
+
@client.wait_for_ssh(@machine)
|
24
|
+
|
25
|
+
env[:ui].info 'Machine is booted and ready to use!'
|
26
|
+
|
27
|
+
@app.call(env)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'vagrant-vultr/helpers/client'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Vultr
|
5
|
+
module Action
|
6
|
+
class Reload
|
7
|
+
include Helpers::Client
|
8
|
+
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@machine = env[:machine]
|
12
|
+
@client = client
|
13
|
+
@logger = Log4r::Logger.new('vagrant::vultr::reload')
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
@client.reboot_server(@machine.id)
|
18
|
+
env[:ui].info 'Machine is stopped.'
|
19
|
+
|
20
|
+
env[:ui].info 'Waiting for server to start...'
|
21
|
+
@client.wait_to_power_on(@machine.id)
|
22
|
+
env[:ui].info 'Waiting for SSH to become active...'
|
23
|
+
@client.wait_for_ssh(@machine)
|
24
|
+
|
25
|
+
env[:ui].info 'Machine is booted and ready to use!'
|
26
|
+
|
27
|
+
@app.call(env)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'vagrant-vultr/helpers/client'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Vultr
|
5
|
+
module Action
|
6
|
+
class SetupSSHKey
|
7
|
+
include Helpers::Client
|
8
|
+
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@machine = env[:machine]
|
12
|
+
@name = @machine.provider_config.ssh_key
|
13
|
+
@client = client
|
14
|
+
@logger = Log4r::Logger.new('vagrant::vultr::setup_ssh_key')
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
ssh_key_id = @client.ssh_key_id(@name)
|
19
|
+
unless ssh_key_id
|
20
|
+
@logger.info 'SSH key does not exist. Creating new one...'
|
21
|
+
key_path = File.expand_path("#{@machine.config.ssh.private_key_path.first}.pub")
|
22
|
+
ssh_key_id = @client.create_ssh_key(@name, File.read(key_path))
|
23
|
+
end
|
24
|
+
@logger.info "Using SSH key: #{ssh_key_id}."
|
25
|
+
|
26
|
+
@app.call(env)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'vagrant-vultr/action/check_state'
|
2
|
+
require 'vagrant-vultr/action/create'
|
3
|
+
require 'vagrant-vultr/action/destroy'
|
4
|
+
require 'vagrant-vultr/action/power_off'
|
5
|
+
require 'vagrant-vultr/action/power_on'
|
6
|
+
require 'vagrant-vultr/action/reload'
|
7
|
+
require 'vagrant-vultr/action/setup_ssh_key'
|
8
|
+
|
9
|
+
module VagrantPlugins
|
10
|
+
module Vultr
|
11
|
+
module Action
|
12
|
+
include Vagrant::Action::Builtin
|
13
|
+
|
14
|
+
def self.up
|
15
|
+
Vagrant::Action::Builder.new.tap do |b|
|
16
|
+
b.use ConfigValidate
|
17
|
+
b.use Call, CheckState do |env, b2|
|
18
|
+
case env[:machine_state]
|
19
|
+
when :active
|
20
|
+
env[:ui].info 'Machine is already booted.'
|
21
|
+
when :off
|
22
|
+
b2.use PowerOn
|
23
|
+
b2.use Provision
|
24
|
+
b2.use SyncedFolders
|
25
|
+
when :not_created
|
26
|
+
b2.use SetupSSHKey
|
27
|
+
b2.use Create
|
28
|
+
b2.use Provision
|
29
|
+
b2.use SyncedFolders
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.halt
|
36
|
+
Vagrant::Action::Builder.new.tap do |b|
|
37
|
+
b.use ConfigValidate
|
38
|
+
b.use Call, CheckState do |env, b2|
|
39
|
+
case env[:machine_state]
|
40
|
+
when :active
|
41
|
+
b2.use PowerOff
|
42
|
+
when :off
|
43
|
+
env[:ui].info 'Machine is not booted.'
|
44
|
+
when :not_created
|
45
|
+
env[:ui].info 'Machine is not created.'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.reload
|
52
|
+
Vagrant::Action::Builder.new.tap do |b|
|
53
|
+
b.use ConfigValidate
|
54
|
+
b.use Call, CheckState do |env, b2|
|
55
|
+
case env[:machine_state]
|
56
|
+
when :active
|
57
|
+
b2.use Reload
|
58
|
+
b2.use Provision
|
59
|
+
b2.use SyncedFolders
|
60
|
+
when :off
|
61
|
+
env[:ui].info 'Machine is not booted.'
|
62
|
+
when :not_created
|
63
|
+
env[:ui].info 'Machine is not created.'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.destroy
|
70
|
+
Vagrant::Action::Builder.new.tap do |b|
|
71
|
+
b.use ConfigValidate
|
72
|
+
b.use Call, CheckState do |env, b2|
|
73
|
+
case env[:machine_state]
|
74
|
+
when :active, :off
|
75
|
+
b2.use Destroy
|
76
|
+
when :not_created
|
77
|
+
env[:ui].info 'Machine is not created.'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.provision
|
84
|
+
Vagrant::Action::Builder.new.tap do |b|
|
85
|
+
b.use ConfigValidate
|
86
|
+
b.use Call, CheckState do |env, b2|
|
87
|
+
case env[:machine_state]
|
88
|
+
when :active
|
89
|
+
b2.use Provision
|
90
|
+
when :off
|
91
|
+
env[:ui].info 'Machine is not booted.'
|
92
|
+
when :not_created
|
93
|
+
env[:ui].info 'Machine is not created.'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.ssh
|
100
|
+
Vagrant::Action::Builder.new.tap do |b|
|
101
|
+
b.use ConfigValidate
|
102
|
+
b.use Call, CheckState do |env, b2|
|
103
|
+
case env[:machine_state]
|
104
|
+
when :active
|
105
|
+
b2.use SSHExec
|
106
|
+
when :off
|
107
|
+
env[:ui].info 'Machine is not booted.'
|
108
|
+
when :not_created
|
109
|
+
env[:ui].info 'Machine is not created.'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.ssh_run
|
116
|
+
Vagrant::Action::Builder.new.tap do |b|
|
117
|
+
b.use ConfigValidate
|
118
|
+
b.use Call, CheckState do |env, b2|
|
119
|
+
case env[:machine_state]
|
120
|
+
when :active
|
121
|
+
b2.use SSHRun
|
122
|
+
when :off
|
123
|
+
env[:ui].info 'Machine is not booted.'
|
124
|
+
when :not_created
|
125
|
+
env[:ui].info 'Machine is not created.'
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|