vagrant-rimu 0.0.4 → 0.0.5

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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/README.md +12 -3
  4. data/Vagrantfile +15 -10
  5. data/lib/vagrant-rimu/actions/connect_to_rimu.rb +7 -3
  6. data/lib/vagrant-rimu/actions/create.rb +7 -1
  7. data/lib/vagrant-rimu/actions/is_created.rb +18 -18
  8. data/lib/vagrant-rimu/actions/is_stopped.rb +1 -1
  9. data/lib/vagrant-rimu/actions/message_action_not_supported.rb +19 -0
  10. data/lib/vagrant-rimu/actions/message_will_not_stop.rb +19 -0
  11. data/lib/vagrant-rimu/actions/modify_provision_path.rb +1 -1
  12. data/lib/vagrant-rimu/actions/move.rb +1 -1
  13. data/lib/vagrant-rimu/actions/read_ssh_info.rb +4 -3
  14. data/lib/vagrant-rimu/actions/read_state.rb +1 -1
  15. data/lib/vagrant-rimu/actions/rebuild.rb +21 -2
  16. data/lib/vagrant-rimu/actions/setup_user.rb +22 -19
  17. data/lib/vagrant-rimu/actions/ssh_utils.rb +44 -0
  18. data/lib/vagrant-rimu/actions/stop_instance.rb +6 -2
  19. data/lib/vagrant-rimu/actions/terminate_instance.rb +6 -2
  20. data/lib/vagrant-rimu/actions.rb +99 -85
  21. data/lib/vagrant-rimu/commands/abstract_command.rb +1 -1
  22. data/lib/vagrant-rimu/commands/rebuild.rb +6 -7
  23. data/lib/vagrant-rimu/commands/root.rb +1 -1
  24. data/lib/vagrant-rimu/config.rb +2 -2
  25. data/lib/vagrant-rimu/plugin.rb +1 -1
  26. data/lib/vagrant-rimu/provider.rb +1 -1
  27. data/lib/vagrant-rimu/version.rb +1 -1
  28. data/locales/en.yml +26 -8
  29. data/spec/spec_helper.rb +1 -1
  30. data/spec/vagrant-rimu/actions/connect_to_rimu_spec.rb +2 -1
  31. data/spec/vagrant-rimu/actions/create_spec.rb +4 -1
  32. data/spec/vagrant-rimu/actions/is_created_spec.rb +1 -1
  33. data/spec/vagrant-rimu/actions/is_stopped_spec.rb +2 -2
  34. data/spec/vagrant-rimu/actions/message_action_not_supported_spec.rb +30 -0
  35. data/spec/vagrant-rimu/actions/message_already_created_spec.rb +1 -4
  36. data/spec/vagrant-rimu/actions/message_will_not_destroy_spec.rb +1 -2
  37. data/spec/vagrant-rimu/actions/message_will_not_stop_spec.rb +35 -0
  38. data/spec/vagrant-rimu/actions/read_ssh_info_spec.rb +8 -0
  39. data/spec/vagrant-rimu/actions/rebuild_spec.rb +7 -1
  40. data/spec/vagrant-rimu/actions/stop_instance_spec.rb +4 -4
  41. data/spec/vagrant-rimu/commands/rebuild_spec.rb +20 -17
  42. data/test/Vagrantfile +3 -1
  43. metadata +9 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d840a350e4933f16c609939b0e47a667fb231e52
4
- data.tar.gz: 2d6683d767c52a49ce99ef1a8e037ff7fcf568e5
3
+ metadata.gz: 66afd16aef93caf2b58833dd8c218f9be014b519
4
+ data.tar.gz: c1c06699b53ada7335a3cf96f24309a8dce80f1c
5
5
  SHA512:
6
- metadata.gz: 073c4eee2db28a3dd9c509fbee40535b0785251f194532e3bffb7f42b6a97cc7b3b78e3669a0a96575833d5b3d02f5eb736536aa05428da303fd43dfbc987af4
7
- data.tar.gz: b191f23da8e210fb597d9814f79b46930b4d6f1dc7779d0a9e4487acebbf399fe6dc4d88550d70266b4a4cbfa2323b53bc612979bc310b8a2ed49c3d541b4d04
6
+ metadata.gz: 0d060d6ae54309888091429a985d45e8883050e5d1b4f07ffc306cce8c75fa83b3024a2c803ead5e2ff683430157d552673cb25b267d8423c1315a8e28b41f47
7
+ data.tar.gz: 575a609d1d24821f625f3cf95ebc99395a26cb5da2f371cf9fc40e92547e176ac46e1d816ce5235fbbe158d3d42d9725f7966cc27b8d24ba82a19499f3f52d1f
data/.gitignore CHANGED
@@ -9,3 +9,5 @@
9
9
  /pkg/
10
10
  /spec/reports/
11
11
  /tmp/
12
+ /.vagrant
13
+ intial.txt
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` - Moves a VPS to a different host and provides info on
95
- `distributions`, `servers` and `billing methods`
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
- Vagrant.configure('2') do |config|
4
- config.vm.provider :rimu do |provider, override|
5
- override.ssh.private_key_path = 'test/test_rimu_id_rsa'
6
- provider.api_key = ENV['RIMU_API_KEY']
7
- provider.host_name = 'rimu.example.com'
8
- end
9
- config.vm.provision "shell", inline: "echo 'done' > ~/provision"
10
- end
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
- @logger.info('Connecting to Rimu api_url...')
18
- rimu = ::Rimu::RimuAPI.new({:api_url => @config.api_url, :api_key=> @config.api_key})
19
- env[:rimu_api] = rimu
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' if !@machine.communicate.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
@@ -9,7 +9,7 @@ module VagrantPlugins
9
9
  end
10
10
 
11
11
  def execute(env)
12
- env[:result] = env[:machine].state.id == :stopped
12
+ env[:result] = env[:machine].state.id == :off
13
13
 
14
14
  @app.call(env)
15
15
  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) if !enabled
19
+ return @app.call(env) unless enabled
20
20
 
21
21
  username = @machine.ssh_info()[:username]
22
22
 
@@ -36,7 +36,7 @@ module VagrantPlugins
36
36
 
37
37
  retryable(:tries => 120, :sleep => 10) do
38
38
  next if env[:interrupted]
39
- raise 'not ready' if !@machine.communicate.ready?
39
+ raise 'not ready' unless @machine.communicate.ready?
40
40
  end
41
41
 
42
42
  @machine.config.ssh.username = user
@@ -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("vagrant_rimu::action::read_ssh_info")
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["primary_ip"],
37
+ :host => server.allocated_ips['primary_ip'],
38
38
  :port => 22,
39
- :username => "root"
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 "Machine state is '#{env[:machine_state]}'"
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
- @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
+
50
65
  retryable(:tries => 120, :sleep => 10) do
51
66
  next if env[:interrupted]
52
- raise 'not ready' if !@machine.communicate.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
- path = @machine.config.ssh.private_key_path
44
- path = path[0] if path.is_a?(Array)
45
- path = File.expand_path(path, @machine.env.root_path)
46
- pub_key = public_key(path)
47
- @machine.communicate.execute(<<-BASH)
48
- if ! grep '#{pub_key}' /home/#{user}/.ssh/authorized_keys; then
49
- echo '#{pub_key}' >> /home/#{user}/.ssh/authorized_keys;
50
- fi
51
-
52
- chown -R #{user} /home/#{user}/.ssh;
53
- BASH
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
- File.read("#{private_key_path}.pub")
79
- rescue
80
- raise Errors::PublicKeyError, :path => "#{private_key_path}.pub"
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 == :stopped
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
- client.servers.shutdown(env[:machine].id.to_i)
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
- client.servers.cancel(env[:machine].id.to_i)
20
- 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
21
25
  end
22
26
 
23
27
  @app.call(env)