vagrant-rimu 0.0.1 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +3 -2
- data/.gitignore +2 -0
- data/.travis.yml +5 -35
- data/Gemfile +4 -2
- data/README.md +12 -3
- data/Rakefile +6 -3
- data/Vagrantfile +12 -3
- data/gemfiles/vagrant_1.5.gemfile +3 -1
- data/gemfiles/vagrant_1.6.gemfile +5 -3
- data/gemfiles/vagrant_1.7.gemfile +10 -8
- data/lib/vagrant-rimu.rb +10 -0
- data/lib/vagrant-rimu/actions.rb +117 -89
- data/lib/vagrant-rimu/actions/abstract_action.rb +20 -0
- data/lib/vagrant-rimu/actions/billing_methods.rb +13 -7
- data/lib/vagrant-rimu/actions/connect_to_rimu.rb +12 -6
- data/lib/vagrant-rimu/actions/create.rb +25 -6
- data/lib/vagrant-rimu/actions/is_created.rb +4 -2
- data/lib/vagrant-rimu/actions/is_stopped.rb +5 -3
- data/lib/vagrant-rimu/actions/list_distributions.rb +13 -7
- data/lib/vagrant-rimu/actions/list_servers.rb +13 -7
- data/lib/vagrant-rimu/actions/message_action_not_supported.rb +19 -0
- data/lib/vagrant-rimu/actions/message_already_created.rb +4 -2
- data/lib/vagrant-rimu/actions/message_already_off.rb +4 -2
- data/lib/vagrant-rimu/actions/message_not_created.rb +4 -2
- data/lib/vagrant-rimu/actions/message_will_not_destroy.rb +4 -2
- data/lib/vagrant-rimu/actions/message_will_not_stop.rb +19 -0
- data/lib/vagrant-rimu/actions/modify_provision_path.rb +5 -3
- data/lib/vagrant-rimu/actions/move.rb +32 -5
- data/lib/vagrant-rimu/actions/read_ssh_info.rb +10 -7
- data/lib/vagrant-rimu/actions/read_state.rb +14 -6
- data/lib/vagrant-rimu/actions/rebuild.rb +34 -6
- data/lib/vagrant-rimu/actions/reload.rb +11 -4
- data/lib/vagrant-rimu/actions/setup_sudo.rb +15 -8
- data/lib/vagrant-rimu/actions/setup_user.rb +45 -25
- data/lib/vagrant-rimu/actions/ssh_utils.rb +44 -0
- data/lib/vagrant-rimu/actions/start_instance.rb +6 -4
- data/lib/vagrant-rimu/actions/stop_instance.rb +18 -7
- data/lib/vagrant-rimu/actions/terminate_instance.rb +12 -6
- data/lib/vagrant-rimu/commands/abstract_command.rb +47 -0
- data/lib/vagrant-rimu/commands/billing_methods.rb +10 -10
- data/lib/vagrant-rimu/commands/distributions.rb +10 -10
- data/lib/vagrant-rimu/commands/list_servers.rb +10 -10
- data/lib/vagrant-rimu/commands/move.rb +10 -10
- data/lib/vagrant-rimu/commands/rebuild.rb +5 -7
- data/lib/vagrant-rimu/commands/rimu_command.rb +13 -0
- data/lib/vagrant-rimu/commands/root.rb +26 -43
- data/lib/vagrant-rimu/commands/utils.rb +22 -0
- data/lib/vagrant-rimu/config.rb +5 -2
- data/lib/vagrant-rimu/errors.rb +6 -0
- data/lib/vagrant-rimu/logging.rb +28 -0
- data/lib/vagrant-rimu/plugin.rb +11 -37
- data/lib/vagrant-rimu/provider.rb +4 -2
- data/lib/vagrant-rimu/version.rb +1 -1
- data/locales/en.yml +70 -19
- data/spec/spec_helper.rb +13 -6
- data/spec/vagrant-rimu/actions/billing_methods_spec.rb +49 -0
- data/spec/vagrant-rimu/actions/connect_to_rimu_spec.rb +2 -1
- data/spec/vagrant-rimu/actions/create_spec.rb +167 -0
- data/spec/vagrant-rimu/actions/is_created_spec.rb +49 -0
- data/spec/vagrant-rimu/actions/is_stopped_spec.rb +49 -0
- data/spec/vagrant-rimu/actions/list_distributions_spec.rb +49 -0
- data/spec/vagrant-rimu/actions/list_servers_spec.rb +51 -0
- 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/modify_provision_path_spec.rb +2 -7
- data/spec/vagrant-rimu/actions/move_spec.rb +75 -0
- data/spec/vagrant-rimu/actions/read_ssh_info_spec.rb +21 -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/billing_methods_spec.rb +17 -0
- data/spec/vagrant-rimu/commands/distributions_spec.rb +17 -0
- data/spec/vagrant-rimu/commands/list_servers_spec.rb +17 -0
- data/spec/vagrant-rimu/commands/move_spec.rb +17 -0
- data/spec/vagrant-rimu/commands/rebuild_spec.rb +20 -0
- data/spec/vagrant-rimu/config_spec.rb +1 -1
- data/test/Vagrantfile +4 -2
- data/vagrant-rimu.gemspec +5 -1
- metadata +81 -27
@@ -1,20 +1,22 @@
|
|
1
1
|
require 'log4r'
|
2
2
|
|
3
|
+
require 'vagrant-rimu/actions/abstract_action'
|
4
|
+
|
3
5
|
module VagrantPlugins
|
4
6
|
module Rimu
|
5
7
|
module Actions
|
6
8
|
# This action reads the SSH info for the machine and puts it into the
|
7
9
|
# `:machine_ssh_info` key in the environment.
|
8
|
-
class ReadSSHInfo
|
10
|
+
class ReadSSHInfo < AbstractAction
|
9
11
|
def initialize(app, env)
|
10
12
|
@app = app
|
11
13
|
@machine = env[:machine]
|
12
|
-
@
|
13
|
-
@logger = Log4r::Logger.new("vagrant_rimu::action::read_ssh_info")
|
14
|
+
@logger = Log4r::Logger.new('vagrant_rimu::action::read_ssh_info')
|
14
15
|
end
|
15
16
|
|
16
|
-
def
|
17
|
-
env[:
|
17
|
+
def execute(env)
|
18
|
+
client = env[:rimu_api]
|
19
|
+
env[:machine_ssh_info] = read_ssh_info(client, @machine)
|
18
20
|
|
19
21
|
@app.call(env)
|
20
22
|
end
|
@@ -32,9 +34,10 @@ module VagrantPlugins
|
|
32
34
|
end
|
33
35
|
|
34
36
|
return {
|
35
|
-
:host => server.allocated_ips[
|
37
|
+
:host => server.allocated_ips['primary_ip'],
|
36
38
|
:port => 22,
|
37
|
-
:username =>
|
39
|
+
:username => 'root',
|
40
|
+
:private_key_path => machine.config.ssh.private_key_path,
|
38
41
|
}
|
39
42
|
end
|
40
43
|
end
|
@@ -1,25 +1,32 @@
|
|
1
1
|
require 'log4r'
|
2
2
|
|
3
|
+
require 'vagrant-rimu/actions/abstract_action'
|
4
|
+
|
3
5
|
module VagrantPlugins
|
4
6
|
module Rimu
|
5
7
|
module Actions
|
6
|
-
class ReadState
|
8
|
+
class ReadState < AbstractAction
|
7
9
|
def initialize(app, env)
|
8
10
|
@app = app
|
9
11
|
@machine = env[:machine]
|
10
|
-
@client = env[:rimu_api]
|
11
12
|
@logger = Log4r::Logger.new('vagrant_rimu::action::read_state')
|
12
13
|
end
|
13
14
|
|
14
|
-
def
|
15
|
-
env[:
|
16
|
-
|
15
|
+
def execute(env)
|
16
|
+
client = env[:rimu_api]
|
17
|
+
env[:machine_state] = read_state(client, @machine)
|
18
|
+
@logger.info I18n.t('vagrant_rimu.states.current_state', {:state => env[:machine_state]})
|
17
19
|
@app.call(env)
|
18
20
|
end
|
19
21
|
|
20
22
|
def read_state(client, machine)
|
21
23
|
return :not_created if machine.id.nil?
|
22
|
-
|
24
|
+
begin
|
25
|
+
server = client.servers.status(machine.id.to_i)
|
26
|
+
rescue ::Rimu::RimuAPI::RimuRequestError, ::Rimu::RimuAPI::RimuResponseError => e
|
27
|
+
@logger.debug(e)
|
28
|
+
return :destroyed
|
29
|
+
end
|
23
30
|
return :not_created if server.nil?
|
24
31
|
status = server.running_state
|
25
32
|
return :not_created if status.nil?
|
@@ -28,6 +35,7 @@ module VagrantPlugins
|
|
28
35
|
'NOTRUNNING' => :off,
|
29
36
|
'RESTARTING' => :shutting_down,
|
30
37
|
'POWERCYCLING' => :shutting_down,
|
38
|
+
'DESTROYED' => :destroyed
|
31
39
|
}
|
32
40
|
states[status.to_s]
|
33
41
|
end
|
@@ -1,20 +1,25 @@
|
|
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
|
-
class Rebuild
|
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
|
11
|
-
@client = env[:rimu_api]
|
12
14
|
@machine = env[:machine]
|
13
15
|
@logger = Log4r::Logger.new('vagrant::rimu::rebuild')
|
14
16
|
end
|
15
17
|
|
16
|
-
|
18
|
+
# rubocop:disable Metrics/AbcSize
|
19
|
+
def execute(env)
|
20
|
+
client = env[:rimu_api]
|
17
21
|
env[:ui].info I18n.t('vagrant_rimu.rebuilding')
|
22
|
+
|
18
23
|
params = {
|
19
24
|
:instantiation_options => {
|
20
25
|
:domain_name => @machine.provider_config.host_name,
|
@@ -35,15 +40,38 @@ module VagrantPlugins
|
|
35
40
|
}
|
36
41
|
params.delete(:instantiation_via_clone_options) if @machine.provider_config.vps_to_clone.nil?
|
37
42
|
params.delete(:instantiation_options) if params.has_key?(:instantiation_via_clone_options)
|
38
|
-
@
|
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
|
51
|
+
|
52
|
+
begin
|
53
|
+
client.servers.reinstall(@machine.id.to_i, params)
|
54
|
+
rescue ::Rimu::RimuAPI::RimuRequestError, ::Rimu::RimuAPI::RimuResponseError => e
|
55
|
+
raise Errors::ApiError, {:stderr=>e}
|
56
|
+
end
|
57
|
+
|
39
58
|
switch_user = @machine.provider_config.setup?
|
40
59
|
user = @machine.config.ssh.username
|
41
|
-
|
60
|
+
if switch_user
|
61
|
+
@machine.config.ssh.username = 'root'
|
62
|
+
@machine.config.ssh.password = root_pass
|
63
|
+
end
|
64
|
+
|
42
65
|
retryable(:tries => 120, :sleep => 10) do
|
43
66
|
next if env[:interrupted]
|
44
|
-
raise 'not ready'
|
67
|
+
raise 'not ready' unless @machine.communicate.ready?
|
45
68
|
end
|
69
|
+
|
70
|
+
# upload root ssh key
|
71
|
+
upload_key(env)
|
72
|
+
|
46
73
|
@machine.config.ssh.username = user
|
74
|
+
|
47
75
|
@app.call(env)
|
48
76
|
end
|
49
77
|
end
|
@@ -1,19 +1,26 @@
|
|
1
1
|
require 'log4r'
|
2
2
|
|
3
|
+
require 'vagrant-rimu/actions/abstract_action'
|
4
|
+
|
3
5
|
module VagrantPlugins
|
4
6
|
module Rimu
|
5
7
|
module Actions
|
6
|
-
class Reload
|
8
|
+
class Reload < AbstractAction
|
7
9
|
def initialize(app, env)
|
8
10
|
@app = app
|
9
|
-
@client = env[:rimu_api]
|
10
11
|
@machine = env[:machine]
|
11
12
|
@logger = Log4r::Logger.new('vagrant::rimu::reload')
|
12
13
|
end
|
13
14
|
|
14
|
-
def
|
15
|
+
def execute(env)
|
16
|
+
client = env[:rimu_api]
|
15
17
|
env[:ui].info I18n.t('vagrant_rimu.reloading')
|
16
|
-
|
18
|
+
|
19
|
+
begin
|
20
|
+
client.servers.reboot(@machine.id.to_i)
|
21
|
+
rescue ::Rimu::RimuAPI::RimuRequestError, ::Rimu::RimuAPI::RimuResponseError => e
|
22
|
+
raise Errors::ApiError, {:stderr=>e}
|
23
|
+
end
|
17
24
|
|
18
25
|
@app.call(env)
|
19
26
|
end
|
@@ -1,16 +1,18 @@
|
|
1
1
|
require 'log4r'
|
2
2
|
|
3
|
+
require 'vagrant-rimu/actions/abstract_action'
|
4
|
+
|
3
5
|
module VagrantPlugins
|
4
6
|
module Rimu
|
5
7
|
module Actions
|
6
|
-
class SetupSudo
|
8
|
+
class SetupSudo < AbstractAction
|
7
9
|
def initialize(app, env)
|
8
10
|
@app = app
|
9
11
|
@machine = env[:machine]
|
10
12
|
@logger = Log4r::Logger.new('vagrant::rimu::setup_sudo')
|
11
13
|
end
|
12
14
|
|
13
|
-
def
|
15
|
+
def execute(env)
|
14
16
|
# check if setup is enabled
|
15
17
|
return @app.call(env) unless @machine.provider_config.setup?
|
16
18
|
|
@@ -18,10 +20,20 @@ module VagrantPlugins
|
|
18
20
|
user = @machine.config.ssh.username
|
19
21
|
@machine.config.ssh.username = 'root'
|
20
22
|
|
23
|
+
# modify the sudoers file
|
24
|
+
modify_sudo(env)
|
25
|
+
|
26
|
+
# reset ssh username
|
27
|
+
@machine.config.ssh.username = user
|
28
|
+
|
29
|
+
@app.call(env)
|
30
|
+
end
|
31
|
+
|
32
|
+
def modify_sudo(env)
|
21
33
|
# check for guest name available in Vagrant 1.2 first
|
22
34
|
guest_name = @machine.guest.name if @machine.guest.respond_to?(:name)
|
23
35
|
guest_name ||= @machine.guest.to_s.downcase
|
24
|
-
|
36
|
+
|
25
37
|
case guest_name
|
26
38
|
when /redhat/
|
27
39
|
env[:ui].info I18n.t('vagrant_rimu.modifying_sudo')
|
@@ -31,11 +43,6 @@ module VagrantPlugins
|
|
31
43
|
sed -i'.bk' -e 's/\(Defaults\s\+requiretty\)/# \1/' /etc/sudoers
|
32
44
|
BASH
|
33
45
|
end
|
34
|
-
|
35
|
-
# reset ssh username
|
36
|
-
@machine.config.ssh.username = user
|
37
|
-
|
38
|
-
@app.call(env)
|
39
46
|
end
|
40
47
|
end
|
41
48
|
end
|
@@ -1,16 +1,22 @@
|
|
1
1
|
require 'log4r'
|
2
2
|
|
3
|
+
require 'vagrant-rimu/actions/ssh_utils'
|
4
|
+
require 'vagrant-rimu/actions/abstract_action'
|
5
|
+
|
3
6
|
module VagrantPlugins
|
4
7
|
module Rimu
|
5
8
|
module Actions
|
6
|
-
class SetupUser
|
9
|
+
class SetupUser < AbstractAction
|
10
|
+
include VagrantPlugins::Rimu::Actions::SshUtils
|
11
|
+
|
7
12
|
def initialize(app, env)
|
8
13
|
@app = app
|
9
14
|
@machine = env[:machine]
|
10
15
|
@logger = Log4r::Logger.new('vagrant::rimu::setup_user')
|
11
16
|
end
|
12
17
|
|
13
|
-
|
18
|
+
# rubocop:disable Metrics/AbcSize
|
19
|
+
def execute(env)
|
14
20
|
# check if setup is enabled
|
15
21
|
return @app.call(env) unless @machine.provider_config.setup?
|
16
22
|
|
@@ -21,11 +27,40 @@ module VagrantPlugins
|
|
21
27
|
user = @machine.config.ssh.username
|
22
28
|
@machine.config.ssh.username = 'root'
|
23
29
|
|
30
|
+
# create user account
|
31
|
+
create_user(env, user)
|
32
|
+
|
33
|
+
# create the .ssh directory in the users home
|
34
|
+
@machine.communicate.execute("su #{user} -c 'mkdir -p ~/.ssh'")
|
35
|
+
|
36
|
+
# add the specified key to the authorized keys file
|
37
|
+
upload_key(env, user)
|
38
|
+
|
39
|
+
# reset username
|
40
|
+
@machine.config.ssh.username = user
|
41
|
+
|
42
|
+
@app.call(env)
|
43
|
+
end
|
44
|
+
|
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
|
58
|
+
|
59
|
+
def create_user(env, user)
|
24
60
|
env[:ui].info I18n.t('vagrant_rimu.creating_user', {
|
25
61
|
:user => user
|
26
62
|
})
|
27
|
-
|
28
|
-
# create user account
|
63
|
+
|
29
64
|
@machine.communicate.execute(<<-BASH)
|
30
65
|
if ! (grep ^#{user}: /etc/passwd); then
|
31
66
|
useradd -m -s /bin/bash #{user};
|
@@ -40,28 +75,13 @@ module VagrantPlugins
|
|
40
75
|
sed -i -e "/#{user}/ s/=.*/=(ALL:ALL) NOPASSWD: ALL/" /etc/sudoers;
|
41
76
|
fi
|
42
77
|
BASH
|
43
|
-
|
44
|
-
# create the .ssh directory in the users home
|
45
|
-
@machine.communicate.execute("su #{user} -c 'mkdir -p ~/.ssh'")
|
46
|
-
|
47
|
-
# add the specified key to the authorized keys file
|
48
|
-
path = @machine.config.ssh.private_key_path
|
49
|
-
path = path[0] if path.is_a?(Array)
|
50
|
-
path = File.expand_path(path, @machine.env.root_path)
|
51
|
-
pub_key = Rimu.public_key(path)
|
52
|
-
@machine.communicate.execute(<<-BASH)
|
53
|
-
if ! grep '#{pub_key}' /home/#{user}/.ssh/authorized_keys; then
|
54
|
-
echo '#{pub_key}' >> /home/#{user}/.ssh/authorized_keys;
|
55
|
-
fi
|
56
|
-
|
57
|
-
chown -R #{user} /home/#{user}/.ssh;
|
58
|
-
BASH
|
59
|
-
|
60
|
-
# reset username
|
61
|
-
@machine.config.ssh.username = user
|
62
|
-
|
63
|
-
@app.call(env)
|
64
78
|
end
|
79
|
+
|
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
|
65
85
|
end
|
66
86
|
end
|
67
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
|
@@ -1,20 +1,22 @@
|
|
1
1
|
require 'log4r'
|
2
2
|
|
3
|
+
require 'vagrant-rimu/actions/abstract_action'
|
4
|
+
|
3
5
|
module VagrantPlugins
|
4
6
|
module Rimu
|
5
7
|
module Actions
|
6
|
-
class StartInstance
|
8
|
+
class StartInstance < AbstractAction
|
7
9
|
def initialize(app, env)
|
8
10
|
@app = app
|
9
|
-
@client = env[:rimu_api]
|
10
11
|
@machine = env[:machine]
|
11
12
|
@logger = Log4r::Logger.new("vagrant_rimu::action::start_instance")
|
12
13
|
end
|
13
14
|
|
14
|
-
def
|
15
|
+
def execute(env)
|
16
|
+
client = env[:rimu_api]
|
15
17
|
env[:ui].info I18n.t('vagrant_rimu.starting')
|
16
18
|
begin
|
17
|
-
result =
|
19
|
+
result = client.servers.start(@machine.id.to_i)
|
18
20
|
raise StandardError, "No response from the API" if result.nil?
|
19
21
|
raise StandardError, "VPS is not be running" if result.running_state != 'RUNNING'
|
20
22
|
rescue StandardError => e
|
@@ -1,25 +1,36 @@
|
|
1
1
|
require 'log4r'
|
2
2
|
|
3
|
+
require 'vagrant-rimu/actions/abstract_action'
|
4
|
+
|
3
5
|
module VagrantPlugins
|
4
6
|
module Rimu
|
5
7
|
module Actions
|
6
8
|
# This stops the running instance.
|
7
|
-
class StopInstance
|
8
|
-
def initialize(app,
|
9
|
+
class StopInstance < AbstractAction
|
10
|
+
def initialize(app, _env)
|
9
11
|
@app = app
|
10
|
-
@client = env[:rimu_api]
|
11
12
|
@logger = Log4r::Logger.new('vagrant_rimu::action::stop_instance')
|
12
13
|
end
|
13
14
|
|
14
|
-
def
|
15
|
-
if env[:machine].state.id == :
|
15
|
+
def execute(env)
|
16
|
+
if env[:machine].state.id == :off
|
16
17
|
env[:ui].info(I18n.t('vagrant_rimu.already_status', :status => env[:machine].state.id))
|
17
18
|
else
|
18
|
-
env
|
19
|
-
@client.servers.shutdown(env[:machine].id.to_i)
|
19
|
+
shutdown(env)
|
20
20
|
end
|
21
|
+
|
21
22
|
@app.call(env)
|
22
23
|
end
|
24
|
+
|
25
|
+
def shutdown(env)
|
26
|
+
env[:ui].info(I18n.t('vagrant_rimu.stopping'))
|
27
|
+
client = env[:rimu_api]
|
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
|
33
|
+
end
|
23
34
|
end
|
24
35
|
end
|
25
36
|
end
|