vagrant-rimu 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +12 -3
- data/Vagrantfile +15 -10
- data/lib/vagrant-rimu/actions/connect_to_rimu.rb +7 -3
- data/lib/vagrant-rimu/actions/create.rb +7 -1
- data/lib/vagrant-rimu/actions/is_created.rb +18 -18
- data/lib/vagrant-rimu/actions/is_stopped.rb +1 -1
- data/lib/vagrant-rimu/actions/message_action_not_supported.rb +19 -0
- data/lib/vagrant-rimu/actions/message_will_not_stop.rb +19 -0
- data/lib/vagrant-rimu/actions/modify_provision_path.rb +1 -1
- data/lib/vagrant-rimu/actions/move.rb +1 -1
- data/lib/vagrant-rimu/actions/read_ssh_info.rb +4 -3
- data/lib/vagrant-rimu/actions/read_state.rb +1 -1
- data/lib/vagrant-rimu/actions/rebuild.rb +21 -2
- data/lib/vagrant-rimu/actions/setup_user.rb +22 -19
- data/lib/vagrant-rimu/actions/ssh_utils.rb +44 -0
- data/lib/vagrant-rimu/actions/stop_instance.rb +6 -2
- data/lib/vagrant-rimu/actions/terminate_instance.rb +6 -2
- data/lib/vagrant-rimu/actions.rb +99 -85
- data/lib/vagrant-rimu/commands/abstract_command.rb +1 -1
- data/lib/vagrant-rimu/commands/rebuild.rb +6 -7
- data/lib/vagrant-rimu/commands/root.rb +1 -1
- data/lib/vagrant-rimu/config.rb +2 -2
- data/lib/vagrant-rimu/plugin.rb +1 -1
- data/lib/vagrant-rimu/provider.rb +1 -1
- data/lib/vagrant-rimu/version.rb +1 -1
- data/locales/en.yml +26 -8
- data/spec/spec_helper.rb +1 -1
- data/spec/vagrant-rimu/actions/connect_to_rimu_spec.rb +2 -1
- data/spec/vagrant-rimu/actions/create_spec.rb +4 -1
- data/spec/vagrant-rimu/actions/is_created_spec.rb +1 -1
- data/spec/vagrant-rimu/actions/is_stopped_spec.rb +2 -2
- data/spec/vagrant-rimu/actions/message_action_not_supported_spec.rb +30 -0
- data/spec/vagrant-rimu/actions/message_already_created_spec.rb +1 -4
- data/spec/vagrant-rimu/actions/message_will_not_destroy_spec.rb +1 -2
- data/spec/vagrant-rimu/actions/message_will_not_stop_spec.rb +35 -0
- data/spec/vagrant-rimu/actions/read_ssh_info_spec.rb +8 -0
- data/spec/vagrant-rimu/actions/rebuild_spec.rb +7 -1
- data/spec/vagrant-rimu/actions/stop_instance_spec.rb +4 -4
- data/spec/vagrant-rimu/commands/rebuild_spec.rb +20 -17
- data/test/Vagrantfile +3 -1
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66afd16aef93caf2b58833dd8c218f9be014b519
|
4
|
+
data.tar.gz: c1c06699b53ada7335a3cf96f24309a8dce80f1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d060d6ae54309888091429a985d45e8883050e5d1b4f07ffc306cce8c75fa83b3024a2c803ead5e2ff683430157d552673cb25b267d8423c1315a8e28b41f47
|
7
|
+
data.tar.gz: 575a609d1d24821f625f3cf95ebc99395a26cb5da2f371cf9fc40e92547e176ac46e1d816ce5235fbbe158d3d42d9725f7966cc27b8d24ba82a19499f3f52d1f
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -35,7 +35,8 @@ The most basic `Vagrantfile` to create a VPS on Rimu is shown below
|
|
35
35
|
```ruby
|
36
36
|
Vagrant.configure('2') do |config|
|
37
37
|
|
38
|
-
config.vm.provider :rimu do |provider|
|
38
|
+
config.vm.provider :rimu do |provider, override|
|
39
|
+
override.ssh.insert_key = true
|
39
40
|
override.ssh.private_key_path = '~/.ssh/id_rsa'
|
40
41
|
|
41
42
|
provider.api_key = 'YOUR RIMU API KEY'
|
@@ -91,8 +92,16 @@ The provider supports the following Vagrant sub-commands:
|
|
91
92
|
- `vagrant status` - Outputs the status (active, off, not created) for the
|
92
93
|
Rimu VPS.
|
93
94
|
- `vagrant ssh` - Logs into the Rimu VPS using the configured user account.
|
94
|
-
- `vagrant rimu` -
|
95
|
-
|
95
|
+
- `vagrant rimu` - Rimu provider specific commands
|
96
|
+
|
97
|
+
**Rimu Specific Commands**
|
98
|
+
|
99
|
+
The Rimu specific commands are available as sub commands of `vagrant rimu`.
|
100
|
+
The following `vagrant rimu` command provides the following sub commands:
|
101
|
+
- `distributions` - Lists the distributions supported.
|
102
|
+
- `servers` - Lists the servers under your account.
|
103
|
+
- `billing methods` - Lists the billing methods setup for your account.
|
104
|
+
- `move-vps` - Moves your VPS to a different host.
|
96
105
|
|
97
106
|
## Contributing
|
98
107
|
|
data/Vagrantfile
CHANGED
@@ -1,10 +1,15 @@
|
|
1
|
-
REQUIRED_PLUGINS = %w(vagrant-rimu)
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
REQUIRED_PLUGINS = %w(vagrant-rimu)
|
2
|
+
abort "Please set the environment variable RIMU_API_KEY in order to run vagrant with the rimu provider" unless ENV.key? 'RIMU_API_KEY'
|
3
|
+
|
4
|
+
Vagrant.configure('2') do |config|
|
5
|
+
config.ssh.insert_key = true
|
6
|
+
config.vm.synced_folder '.', '/vagrant', :disabled => true
|
7
|
+
config.vm.provider :rimu do |provider, override|
|
8
|
+
override.ssh.private_key_path = 'test/test_rimu_id_rsa'
|
9
|
+
override.ssh.insert_key = true
|
10
|
+
provider.api_key = ENV['RIMU_API_KEY']
|
11
|
+
provider.host_name = 'rimu.example.com'
|
12
|
+
provider.disk_space_mb = 4000
|
13
|
+
end
|
14
|
+
config.vm.provision "shell", inline: "echo 'done' > ~/provision"
|
15
|
+
end
|
@@ -14,9 +14,13 @@ module VagrantPlugins
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def execute(env)
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
if env[:rimu_api].nil? || ! env[:rimu_api].respond_to?(:api_key)
|
18
|
+
@logger.info('Connecting to Rimu api_url...')
|
19
|
+
rimu = ::Rimu::RimuAPI.new({:api_url => @config.api_url, :api_key=> @config.api_key})
|
20
|
+
env[:rimu_api] = rimu
|
21
|
+
else
|
22
|
+
@logger.info('Not creating a new client object...')
|
23
|
+
end
|
20
24
|
@app.call(env) unless @app.nil?
|
21
25
|
end
|
22
26
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'log4r'
|
2
2
|
require 'vagrant'
|
3
3
|
|
4
|
+
require 'vagrant-rimu/actions/ssh_utils'
|
4
5
|
require 'vagrant-rimu/actions/abstract_action'
|
5
6
|
|
6
7
|
module VagrantPlugins
|
@@ -8,6 +9,7 @@ module VagrantPlugins
|
|
8
9
|
module Actions
|
9
10
|
class Create < AbstractAction
|
10
11
|
include Vagrant::Util::Retryable
|
12
|
+
include VagrantPlugins::Rimu::Actions::SshUtils
|
11
13
|
|
12
14
|
def initialize(app, env)
|
13
15
|
@app = app
|
@@ -75,9 +77,13 @@ module VagrantPlugins
|
|
75
77
|
if params.has_key?(:instantiation_options)
|
76
78
|
retryable(:tries => 120, :sleep => 10) do
|
77
79
|
next if env[:interrupted]
|
78
|
-
raise 'not ready'
|
80
|
+
raise 'not ready' unless @machine.communicate.ready?
|
79
81
|
end
|
80
82
|
end
|
83
|
+
|
84
|
+
# upload root ssh key
|
85
|
+
upload_key(env)
|
86
|
+
|
81
87
|
@machine.config.ssh.username = user
|
82
88
|
|
83
89
|
@app.call(env)
|
@@ -1,18 +1,18 @@
|
|
1
|
-
require 'vagrant-rimu/actions/abstract_action'
|
2
|
-
|
3
|
-
module VagrantPlugins
|
4
|
-
module Rimu
|
5
|
-
module Actions
|
6
|
-
class IsCreated < AbstractAction
|
7
|
-
def initialize(app, _env)
|
8
|
-
@app = app
|
9
|
-
end
|
10
|
-
|
11
|
-
def execute(env)
|
12
|
-
env[:result] = env[:machine].state.id != :not_created
|
13
|
-
@app.call(env)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
1
|
+
require 'vagrant-rimu/actions/abstract_action'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Rimu
|
5
|
+
module Actions
|
6
|
+
class IsCreated < AbstractAction
|
7
|
+
def initialize(app, _env)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def execute(env)
|
12
|
+
env[:result] = env[:machine].state.id != :not_created
|
13
|
+
@app.call(env)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'vagrant-rimu/actions/abstract_action'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Rimu
|
5
|
+
module Actions
|
6
|
+
class MessageActionNotSupported < AbstractAction
|
7
|
+
def initialize(app, _env)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def execute(env)
|
12
|
+
env[:ui].info(I18n.t('vagrant_rimu.action_not_supported'))
|
13
|
+
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'vagrant-rimu/actions/abstract_action'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Rimu
|
5
|
+
module Actions
|
6
|
+
class MessageWillNotStop < AbstractAction
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
@machine = env[:machine]
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute(env)
|
13
|
+
env[:ui].info(I18n.t('vagrant_rimu.will_not_stop', {:name => @machine.name}))
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -16,7 +16,7 @@ module VagrantPlugins
|
|
16
16
|
# check if provisioning is enabled
|
17
17
|
enabled = true
|
18
18
|
enabled = env[:provision_enabled] if env.has_key?(:provision_enabled)
|
19
|
-
return @app.call(env)
|
19
|
+
return @app.call(env) unless enabled
|
20
20
|
|
21
21
|
username = @machine.ssh_info()[:username]
|
22
22
|
|
@@ -11,7 +11,7 @@ module VagrantPlugins
|
|
11
11
|
def initialize(app, env)
|
12
12
|
@app = app
|
13
13
|
@machine = env[:machine]
|
14
|
-
@logger = Log4r::Logger.new(
|
14
|
+
@logger = Log4r::Logger.new('vagrant_rimu::action::read_ssh_info')
|
15
15
|
end
|
16
16
|
|
17
17
|
def execute(env)
|
@@ -34,9 +34,10 @@ module VagrantPlugins
|
|
34
34
|
end
|
35
35
|
|
36
36
|
return {
|
37
|
-
:host => server.allocated_ips[
|
37
|
+
:host => server.allocated_ips['primary_ip'],
|
38
38
|
:port => 22,
|
39
|
-
:username =>
|
39
|
+
:username => 'root',
|
40
|
+
:private_key_path => machine.config.ssh.private_key_path,
|
40
41
|
}
|
41
42
|
end
|
42
43
|
end
|
@@ -15,7 +15,7 @@ module VagrantPlugins
|
|
15
15
|
def execute(env)
|
16
16
|
client = env[:rimu_api]
|
17
17
|
env[:machine_state] = read_state(client, @machine)
|
18
|
-
@logger.info
|
18
|
+
@logger.info I18n.t('vagrant_rimu.states.current_state', {:state => env[:machine_state]})
|
19
19
|
@app.call(env)
|
20
20
|
end
|
21
21
|
|
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'log4r'
|
2
2
|
|
3
|
+
require 'vagrant-rimu/actions/ssh_utils'
|
4
|
+
|
3
5
|
module VagrantPlugins
|
4
6
|
module Rimu
|
5
7
|
module Actions
|
6
8
|
class Rebuild < AbstractAction
|
7
9
|
include Vagrant::Util::Retryable
|
10
|
+
include VagrantPlugins::Rimu::Actions::SshUtils
|
8
11
|
|
9
12
|
def initialize(app, env)
|
10
13
|
@app = app
|
@@ -37,6 +40,14 @@ module VagrantPlugins
|
|
37
40
|
}
|
38
41
|
params.delete(:instantiation_via_clone_options) if @machine.provider_config.vps_to_clone.nil?
|
39
42
|
params.delete(:instantiation_options) if params.has_key?(:instantiation_via_clone_options)
|
43
|
+
if @machine.provider_config.root_password
|
44
|
+
root_pass = @machine.provider_config.root_password
|
45
|
+
else
|
46
|
+
root_pass = Digest::SHA2.new.update(@machine.provider_config.api_key).to_s
|
47
|
+
end
|
48
|
+
if params.has_key?(:instantiation_options)
|
49
|
+
params[:instantiation_options][:password] = root_pass
|
50
|
+
end
|
40
51
|
|
41
52
|
begin
|
42
53
|
client.servers.reinstall(@machine.id.to_i, params)
|
@@ -46,11 +57,19 @@ module VagrantPlugins
|
|
46
57
|
|
47
58
|
switch_user = @machine.provider_config.setup?
|
48
59
|
user = @machine.config.ssh.username
|
49
|
-
|
60
|
+
if switch_user
|
61
|
+
@machine.config.ssh.username = 'root'
|
62
|
+
@machine.config.ssh.password = root_pass
|
63
|
+
end
|
64
|
+
|
50
65
|
retryable(:tries => 120, :sleep => 10) do
|
51
66
|
next if env[:interrupted]
|
52
|
-
raise 'not ready'
|
67
|
+
raise 'not ready' unless @machine.communicate.ready?
|
53
68
|
end
|
69
|
+
|
70
|
+
# upload root ssh key
|
71
|
+
upload_key(env)
|
72
|
+
|
54
73
|
@machine.config.ssh.username = user
|
55
74
|
|
56
75
|
@app.call(env)
|
@@ -1,11 +1,14 @@
|
|
1
1
|
require 'log4r'
|
2
2
|
|
3
|
+
require 'vagrant-rimu/actions/ssh_utils'
|
3
4
|
require 'vagrant-rimu/actions/abstract_action'
|
4
5
|
|
5
6
|
module VagrantPlugins
|
6
7
|
module Rimu
|
7
8
|
module Actions
|
8
9
|
class SetupUser < AbstractAction
|
10
|
+
include VagrantPlugins::Rimu::Actions::SshUtils
|
11
|
+
|
9
12
|
def initialize(app, env)
|
10
13
|
@app = app
|
11
14
|
@machine = env[:machine]
|
@@ -31,7 +34,7 @@ module VagrantPlugins
|
|
31
34
|
@machine.communicate.execute("su #{user} -c 'mkdir -p ~/.ssh'")
|
32
35
|
|
33
36
|
# add the specified key to the authorized keys file
|
34
|
-
upload_key(user)
|
37
|
+
upload_key(env, user)
|
35
38
|
|
36
39
|
# reset username
|
37
40
|
@machine.config.ssh.username = user
|
@@ -39,19 +42,19 @@ module VagrantPlugins
|
|
39
42
|
@app.call(env)
|
40
43
|
end
|
41
44
|
|
42
|
-
def upload_key(user)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
45
|
+
# def upload_key(user)
|
46
|
+
# path = @machine.config.ssh.private_key_path
|
47
|
+
# path = path[0] if path.is_a?(Array)
|
48
|
+
# path = File.expand_path(path, @machine.env.root_path)
|
49
|
+
# pub_key = public_key(path)
|
50
|
+
# @machine.communicate.execute(<<-BASH)
|
51
|
+
# if ! grep '#{pub_key}' /home/#{user}/.ssh/authorized_keys; then
|
52
|
+
# echo '#{pub_key}' >> /home/#{user}/.ssh/authorized_keys;
|
53
|
+
# fi
|
54
|
+
#
|
55
|
+
# chown -R #{user} /home/#{user}/.ssh;
|
56
|
+
# BASH
|
57
|
+
# end
|
55
58
|
|
56
59
|
def create_user(env, user)
|
57
60
|
env[:ui].info I18n.t('vagrant_rimu.creating_user', {
|
@@ -74,11 +77,11 @@ module VagrantPlugins
|
|
74
77
|
BASH
|
75
78
|
end
|
76
79
|
|
77
|
-
def public_key(private_key_path)
|
78
|
-
|
79
|
-
rescue
|
80
|
-
|
81
|
-
end
|
80
|
+
# def public_key(private_key_path)
|
81
|
+
# File.read("#{private_key_path}.pub")
|
82
|
+
# rescue
|
83
|
+
# raise Errors::PublicKeyError, :path => "#{private_key_path}.pub"
|
84
|
+
# end
|
82
85
|
end
|
83
86
|
end
|
84
87
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Rimu
|
5
|
+
module Actions
|
6
|
+
module SshUtils
|
7
|
+
|
8
|
+
# rubocop:disable Metrics/AbcSize
|
9
|
+
def upload_key(env, user=nil)
|
10
|
+
path = env[:machine].config.ssh.private_key_path
|
11
|
+
path = path[0] if path.is_a?(Array)
|
12
|
+
path = File.expand_path(path, env[:machine].env.root_path)
|
13
|
+
pub_key = public_key(path)
|
14
|
+
if user.nil?
|
15
|
+
env[:machine].communicate.execute(<<-BASH)
|
16
|
+
if [ ! -d /root/.ssh ]; then
|
17
|
+
mkdir /root/.ssh;
|
18
|
+
chmod 0700 /root/.ssh;
|
19
|
+
fi
|
20
|
+
if ! grep '#{pub_key.chomp}' /root/.ssh/authorized_keys; then
|
21
|
+
echo '#{pub_key}' >> /root/.ssh/authorized_keys;
|
22
|
+
fi
|
23
|
+
BASH
|
24
|
+
else
|
25
|
+
env[:machine].communicate.execute(<<-BASH)
|
26
|
+
if ! grep '#{pub_key.chomp}' /home/#{user}/.ssh/authorized_keys; then
|
27
|
+
echo '#{pub_key}' >> /home/#{user}/.ssh/authorized_keys;
|
28
|
+
fi
|
29
|
+
|
30
|
+
chown -R #{user} /home/#{user}/.ssh;
|
31
|
+
BASH
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def public_key(private_key_path)
|
36
|
+
File.read("#{private_key_path}.pub")
|
37
|
+
rescue
|
38
|
+
raise Errors::PublicKeyError, :path => "#{private_key_path}.pub"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
# rubocop:enable Metrics/AbcSize
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -13,7 +13,7 @@ module VagrantPlugins
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def execute(env)
|
16
|
-
if env[:machine].state.id == :
|
16
|
+
if env[:machine].state.id == :off
|
17
17
|
env[:ui].info(I18n.t('vagrant_rimu.already_status', :status => env[:machine].state.id))
|
18
18
|
else
|
19
19
|
shutdown(env)
|
@@ -25,7 +25,11 @@ module VagrantPlugins
|
|
25
25
|
def shutdown(env)
|
26
26
|
env[:ui].info(I18n.t('vagrant_rimu.stopping'))
|
27
27
|
client = env[:rimu_api]
|
28
|
-
|
28
|
+
begin
|
29
|
+
client.servers.shutdown(env[:machine].id.to_i)
|
30
|
+
rescue ::Rimu::RimuAPI::RimuRequestError, ::Rimu::RimuAPI::RimuResponseError => e
|
31
|
+
raise Errors::ApiError, {:stderr=>e}
|
32
|
+
end
|
29
33
|
end
|
30
34
|
end
|
31
35
|
end
|
@@ -16,8 +16,12 @@ module VagrantPlugins
|
|
16
16
|
if env[:machine].id
|
17
17
|
env[:ui].info(I18n.t("vagrant_rimu.terminating"))
|
18
18
|
client = env[:rimu_api]
|
19
|
-
|
20
|
-
|
19
|
+
begin
|
20
|
+
client.servers.cancel(env[:machine].id.to_i)
|
21
|
+
env[:machine].id = nil
|
22
|
+
rescue ::Rimu::RimuAPI::RimuRequestError, ::Rimu::RimuAPI::RimuResponseError => e
|
23
|
+
raise Errors::ApiError, {:stderr=>e}
|
24
|
+
end
|
21
25
|
end
|
22
26
|
|
23
27
|
@app.call(env)
|