vagrant-rimu 0.0.2 → 0.0.7

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.
Files changed (77) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +3 -2
  3. data/.gitignore +2 -0
  4. data/.travis.yml +5 -35
  5. data/Gemfile +4 -2
  6. data/README.md +13 -4
  7. data/Rakefile +6 -3
  8. data/Vagrantfile +5 -0
  9. data/gemfiles/vagrant_1.5.gemfile +3 -1
  10. data/gemfiles/vagrant_1.6.gemfile +5 -3
  11. data/gemfiles/vagrant_1.7.gemfile +10 -8
  12. data/lib/vagrant-rimu/actions.rb +102 -80
  13. data/lib/vagrant-rimu/actions/abstract_action.rb +20 -0
  14. data/lib/vagrant-rimu/actions/billing_methods.rb +11 -4
  15. data/lib/vagrant-rimu/actions/connect_to_rimu.rb +12 -6
  16. data/lib/vagrant-rimu/actions/create.rb +24 -5
  17. data/lib/vagrant-rimu/actions/is_created.rb +4 -2
  18. data/lib/vagrant-rimu/actions/is_stopped.rb +5 -3
  19. data/lib/vagrant-rimu/actions/list_distributions.rb +11 -4
  20. data/lib/vagrant-rimu/actions/list_servers.rb +11 -6
  21. data/lib/vagrant-rimu/actions/message_action_not_supported.rb +19 -0
  22. data/lib/vagrant-rimu/actions/message_already_created.rb +4 -2
  23. data/lib/vagrant-rimu/actions/message_already_off.rb +4 -2
  24. data/lib/vagrant-rimu/actions/message_not_created.rb +4 -2
  25. data/lib/vagrant-rimu/actions/message_will_not_destroy.rb +4 -2
  26. data/lib/vagrant-rimu/actions/message_will_not_stop.rb +19 -0
  27. data/lib/vagrant-rimu/actions/modify_provision_path.rb +5 -3
  28. data/lib/vagrant-rimu/actions/move.rb +31 -4
  29. data/lib/vagrant-rimu/actions/read_ssh_info.rb +8 -5
  30. data/lib/vagrant-rimu/actions/read_state.rb +12 -4
  31. data/lib/vagrant-rimu/actions/rebuild.rb +33 -5
  32. data/lib/vagrant-rimu/actions/reload.rb +10 -3
  33. data/lib/vagrant-rimu/actions/setup_sudo.rb +15 -8
  34. data/lib/vagrant-rimu/actions/setup_user.rb +44 -30
  35. data/lib/vagrant-rimu/actions/ssh_utils.rb +44 -0
  36. data/lib/vagrant-rimu/actions/start_instance.rb +4 -2
  37. data/lib/vagrant-rimu/actions/stop_instance.rb +16 -6
  38. data/lib/vagrant-rimu/actions/terminate_instance.rb +10 -4
  39. data/lib/vagrant-rimu/commands/abstract_command.rb +47 -0
  40. data/lib/vagrant-rimu/commands/billing_methods.rb +10 -10
  41. data/lib/vagrant-rimu/commands/distributions.rb +10 -10
  42. data/lib/vagrant-rimu/commands/list_servers.rb +10 -10
  43. data/lib/vagrant-rimu/commands/move.rb +10 -10
  44. data/lib/vagrant-rimu/commands/rebuild.rb +5 -7
  45. data/lib/vagrant-rimu/commands/rimu_command.rb +13 -0
  46. data/lib/vagrant-rimu/commands/root.rb +26 -43
  47. data/lib/vagrant-rimu/commands/utils.rb +22 -0
  48. data/lib/vagrant-rimu/config.rb +3 -2
  49. data/lib/vagrant-rimu/errors.rb +4 -0
  50. data/lib/vagrant-rimu/plugin.rb +1 -1
  51. data/lib/vagrant-rimu/provider.rb +1 -1
  52. data/lib/vagrant-rimu/version.rb +1 -1
  53. data/locales/en.yml +70 -19
  54. data/spec/spec_helper.rb +1 -1
  55. data/spec/vagrant-rimu/actions/billing_methods_spec.rb +4 -4
  56. data/spec/vagrant-rimu/actions/connect_to_rimu_spec.rb +2 -1
  57. data/spec/vagrant-rimu/actions/create_spec.rb +167 -0
  58. data/spec/vagrant-rimu/actions/is_created_spec.rb +1 -1
  59. data/spec/vagrant-rimu/actions/is_stopped_spec.rb +2 -2
  60. data/spec/vagrant-rimu/actions/list_distributions_spec.rb +4 -4
  61. data/spec/vagrant-rimu/actions/list_servers_spec.rb +4 -4
  62. data/spec/vagrant-rimu/actions/message_action_not_supported_spec.rb +30 -0
  63. data/spec/vagrant-rimu/actions/message_already_created_spec.rb +1 -4
  64. data/spec/vagrant-rimu/actions/message_will_not_destroy_spec.rb +1 -2
  65. data/spec/vagrant-rimu/actions/message_will_not_stop_spec.rb +35 -0
  66. data/spec/vagrant-rimu/actions/move_spec.rb +75 -0
  67. data/spec/vagrant-rimu/actions/read_ssh_info_spec.rb +8 -0
  68. data/spec/vagrant-rimu/actions/rebuild_spec.rb +7 -1
  69. data/spec/vagrant-rimu/actions/stop_instance_spec.rb +4 -4
  70. data/spec/vagrant-rimu/commands/billing_methods_spec.rb +17 -0
  71. data/spec/vagrant-rimu/commands/distributions_spec.rb +17 -0
  72. data/spec/vagrant-rimu/commands/list_servers_spec.rb +17 -0
  73. data/spec/vagrant-rimu/commands/move_spec.rb +17 -0
  74. data/spec/vagrant-rimu/commands/rebuild_spec.rb +20 -0
  75. data/test/Vagrantfile +4 -2
  76. data/vagrant-rimu.gemspec +3 -1
  77. metadata +48 -6
@@ -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
12
  @logger = Log4r::Logger.new('vagrant_rimu::action::read_state')
11
13
  end
12
14
 
13
- def call(env)
15
+ def execute(env)
14
16
  client = env[:rimu_api]
15
17
  env[:machine_state] = read_state(client, @machine)
16
- @logger.info "Machine state is '#{env[:machine_state]}'"
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
- server = client.servers.status(machine.id.to_i)
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,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
- 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
@@ -12,9 +15,11 @@ module VagrantPlugins
12
15
  @logger = Log4r::Logger.new('vagrant::rimu::rebuild')
13
16
  end
14
17
 
15
- def call(env)
18
+ # rubocop:disable Metrics/AbcSize
19
+ def execute(env)
16
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
- client.servers.reinstall(@machine.id.to_i, params)
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
- @machine.config.ssh.username = 'root' if switch_user
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' if !@machine.communicate.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
11
  @machine = env[:machine]
10
12
  @logger = Log4r::Logger.new('vagrant::rimu::reload')
11
13
  end
12
14
 
13
- def call(env)
15
+ def execute(env)
14
16
  client = env[:rimu_api]
15
17
  env[:ui].info I18n.t('vagrant_rimu.reloading')
16
- client.servers.reboot(@machine.id.to_i)
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 call(env)
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
- def call(env)
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,34 +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 = 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
65
79
 
66
- def public_key(private_key_path)
67
- File.read("#{private_key_path}.pub")
68
- rescue
69
- raise Errors::PublicKeyError, :path => "#{private_key_path}.pub"
70
- 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
71
85
  end
72
86
  end
73
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,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 StartInstance
8
+ class StartInstance < AbstractAction
7
9
  def initialize(app, env)
8
10
  @app = app
9
11
  @machine = env[:machine]
10
12
  @logger = Log4r::Logger.new("vagrant_rimu::action::start_instance")
11
13
  end
12
14
 
13
- def call(env)
15
+ def execute(env)
14
16
  client = env[:rimu_api]
15
17
  env[:ui].info I18n.t('vagrant_rimu.starting')
16
18
  begin
@@ -1,26 +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
9
+ class StopInstance < AbstractAction
8
10
  def initialize(app, _env)
9
11
  @app = app
10
12
  @logger = Log4r::Logger.new('vagrant_rimu::action::stop_instance')
11
13
  end
12
14
 
13
- def call(env)
14
- if env[:machine].state.id == :stopped
15
+ def execute(env)
16
+ if env[:machine].state.id == :off
15
17
  env[:ui].info(I18n.t('vagrant_rimu.already_status', :status => env[:machine].state.id))
16
18
  else
17
- env[:ui].info(I18n.t('vagrant_rimu.stopping'))
18
- client = env[:rimu_api]
19
- client.servers.shutdown(env[:machine].id.to_i)
19
+ shutdown(env)
20
20
  end
21
21
 
22
22
  @app.call(env)
23
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
24
34
  end
25
35
  end
26
36
  end
@@ -1,21 +1,27 @@
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 terminates the running server, if there is one.
7
- class TerminateInstance
9
+ class TerminateInstance < AbstractAction
8
10
  def initialize(app, _env)
9
11
  @app = app
10
12
  @logger = Log4r::Logger.new("vagrant_rimu::action::terminate_instance")
11
13
  end
12
14
 
13
- def call(env)
15
+ def execute(env)
14
16
  if env[:machine].id
15
17
  env[:ui].info(I18n.t("vagrant_rimu.terminating"))
16
18
  client = env[:rimu_api]
17
- client.servers.cancel(env[:machine].id.to_i)
18
- env[:machine].id = nil
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
19
25
  end
20
26
 
21
27
  @app.call(env)