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
@@ -0,0 +1,47 @@
1
+ require 'colorize'
2
+
3
+ module VagrantPlugins
4
+ module Rimu
5
+ module Commands
6
+ class AbstractCommand < Vagrant.plugin('2', :command)
7
+ def initialize(argv, env)
8
+ @env = env
9
+ super(normalize_args(argv), env)
10
+ end
11
+
12
+ def execute(name)
13
+ env = {}
14
+ with_target_vms(nil, provider: :rimu) do |machine|
15
+ env[:machine] = machine
16
+ env[:ui] = @env.ui
17
+ end
18
+
19
+ before_cmd(name, @argv, env)
20
+
21
+ cmd(name, @argv, env)
22
+ @env.ui.info('')
23
+ # rubocop:disable Lint/RescueException
24
+ rescue Errors::RimuError, SystemExit, Interrupt => e
25
+ raise e
26
+ rescue Exception => e
27
+ puts I18n.t('vagrant_rimu.errors.global_error').red unless e.message
28
+ raise e
29
+ end
30
+ # rubocop:enable Lint/RescueException
31
+
32
+ def normalize_args(args)
33
+ return args if args.nil?
34
+ args.pop if args.size > 0 && args.last == '--'
35
+ args
36
+ end
37
+
38
+ def before_cmd(_name, _argv, _env)
39
+ end
40
+
41
+ def cmd(_name, _argv, _env)
42
+ fail 'Command not implemented. \'cmd\' method must be overridden in all subclasses'
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,16 +1,16 @@
1
+ require 'vagrant-rimu/commands/rimu_command'
2
+
1
3
  module VagrantPlugins
2
4
  module Rimu
3
5
  module Commands
4
- class BillingMethods < Vagrant.plugin('2', :command)
5
- def execute
6
- opts = OptionParser.new do |o|
7
- o.banner = 'Usage: vagrant rimu billing_methods [options]'
8
- end
9
- argv = parse_options(opts)
10
- return unless argv
11
- with_target_vms(argv, provider: :rimu) do |machine|
12
- machine.action('billing_methods')
13
- end
6
+ class BillingMethods < RimuCommand
7
+ def self.synopsis
8
+ I18n.t('vagrant_rimu.commands.billing_methods')
9
+ end
10
+
11
+ def cmd(name, argv, env)
12
+ fail Errors::NoArgRequiredForCommand, cmd: name unless argv.size == 0
13
+ env[:machine].action('billing_methods')
14
14
  end
15
15
  end
16
16
  end
@@ -1,16 +1,16 @@
1
+ require 'vagrant-rimu/commands/rimu_command'
2
+
1
3
  module VagrantPlugins
2
4
  module Rimu
3
5
  module Commands
4
- class Distributions < Vagrant.plugin('2', :command)
5
- def execute
6
- opts = OptionParser.new do |o|
7
- o.banner = 'Usage: vagrant rimu distributions [options]'
8
- end
9
- argv = parse_options(opts)
10
- return unless argv
11
- with_target_vms(argv, provider: :rimu) do |machine|
12
- machine.action('list_distributions')
13
- end
6
+ class Distributions < RimuCommand
7
+ def self.synopsis
8
+ I18n.t('vagrant_rimu.commands.list_distributions')
9
+ end
10
+
11
+ def cmd(name, argv, env)
12
+ fail Errors::NoArgRequiredForCommand, cmd: name unless argv.size == 0
13
+ env[:machine].action('list_distributions')
14
14
  end
15
15
  end
16
16
  end
@@ -1,16 +1,16 @@
1
+ require 'vagrant-rimu/commands/rimu_command'
2
+
1
3
  module VagrantPlugins
2
4
  module Rimu
3
5
  module Commands
4
- class ListServers < Vagrant.plugin('2', :command)
5
- def execute
6
- opts = OptionParser.new do |o|
7
- o.banner = 'Usage: vagrant rimu servers [options]'
8
- end
9
- argv = parse_options(opts)
10
- return unless argv
11
- with_target_vms(argv, provider: :rimu) do |machine|
12
- machine.action('list_servers')
13
- end
6
+ class ListServers < RimuCommand
7
+ def self.synopsis
8
+ I18n.t('vagrant_rimu.commands.list_servers')
9
+ end
10
+
11
+ def cmd(name, argv, env)
12
+ fail Errors::NoArgRequiredForCommand, cmd: name unless argv.size == 0
13
+ env[:machine].action('list_servers')
14
14
  end
15
15
  end
16
16
  end
@@ -1,16 +1,16 @@
1
+ require 'vagrant-rimu/commands/abstract_command'
2
+
1
3
  module VagrantPlugins
2
4
  module Rimu
3
5
  module Commands
4
- class Move < Vagrant.plugin('2', :command)
5
- def execute
6
- opts = OptionParser.new do |o|
7
- o.banner = 'Usage: vagrant rimu move [options]'
8
- end
9
- argv = parse_options(opts)
10
- return unless argv
11
- with_target_vms(argv, provider: :rimu) do |machine|
12
- machine.action('move')
13
- end
6
+ class Move < AbstractCommand
7
+ def self.synopsis
8
+ I18n.t('vagrant_rimu.commands.move')
9
+ end
10
+
11
+ def cmd(name, argv, env)
12
+ fail Errors::NoArgRequiredForCommand, cmd: name unless argv.size == 0
13
+ env[:machine].action('move')
14
14
  end
15
15
  end
16
16
  end
@@ -1,15 +1,13 @@
1
- require 'optparse'
2
-
3
1
  module VagrantPlugins
4
2
  module Rimu
5
3
  module Commands
6
4
  class Rebuild < Vagrant.plugin('2', :command)
5
+ def self.synopsis
6
+ I18n.t('vagrant_rimu.commands.rebuild')
7
+ end
8
+
7
9
  def execute
8
- opts = OptionParser.new do |o|
9
- o.banner = 'Usage: vagrant rebuild [vm-name]'
10
- end
11
- argv = parse_options(opts)
12
- with_target_vms(argv) do |machine|
10
+ with_target_vms(nil, provider: :rimu) do |machine|
13
11
  machine.action(:rebuild)
14
12
  end
15
13
  0
@@ -0,0 +1,13 @@
1
+ require 'vagrant-rimu/commands/abstract_command'
2
+
3
+ module VagrantPlugins
4
+ module Rimu
5
+ module Commands
6
+ class RimuCommand < AbstractCommand
7
+ def before_cmd(_name, _argv, env)
8
+ VagrantPlugins::Rimu::Actions::ConnectToRimu.new(nil, env).call(env)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,65 +1,48 @@
1
- require 'optparse'
2
-
3
1
  module VagrantPlugins
4
2
  module Rimu
5
3
  module Commands
4
+ COMMANDS = [
5
+ { name: :'billing-methods', file: 'billing_methods', clazz: 'BillingMethods' },
6
+ { name: :'distributions', file: 'distributions', clazz: 'Distributions' },
7
+ { name: :'servers', file: 'list_servers', clazz: 'ListServers' },
8
+ { name: :'move-vps', file: 'move', clazz: 'Move' },
9
+ # { name: :'rebuild', file: 'rebuild', clazz: 'Rebuild' },
10
+ ]
11
+
6
12
  class Root < Vagrant.plugin('2', :command)
7
13
  def self.synopsis
8
- 'query Rimu for various options'
14
+ I18n.t('vagrant_rimu.commands.root_synopsis')
9
15
  end
10
16
 
11
17
  def initialize(argv, env)
18
+ @env = env
12
19
  @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
20
+ @commands = Vagrant::Registry.new
13
21
 
14
- @subcommands = Vagrant::Registry.new
15
-
16
- @subcommands.register(:distributions) do
17
- require File.expand_path('../distributions', __FILE__)
18
- Distributions
19
- end
20
-
21
- @subcommands.register(:move) do
22
- require File.expand_path('../move', __FILE__)
23
- Move
24
- end
25
-
26
- @subcommands.register(:billing_methods) do
27
- require File.expand_path('../billing_methods', __FILE__)
28
- BillingMethods
29
- end
30
-
31
- @subcommands.register(:servers) do
32
- require File.expand_path('../list_servers', __FILE__)
33
- ListServers
22
+ COMMANDS.each do |cmd|
23
+ @commands.register(cmd[:name]) do
24
+ require_relative cmd[:file]
25
+ Commands.const_get(cmd[:clazz])
26
+ end
34
27
  end
35
28
 
36
29
  super(argv, env)
37
30
  end
38
31
 
39
32
  def execute
40
- if @main_args.include?('-h') || @main_args.include?('--help')
41
- return help
42
- end
43
- command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
44
- return help if !command_class || !@sub_command
45
- @logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
46
- command_class.new(@sub_args, @env).execute
33
+ command_class = @commands.get(@sub_command.to_sym) if @sub_command
34
+ return usage unless command_class && @sub_command
35
+ command_class.new(@sub_args, @env).execute(@sub_command)
47
36
  end
48
37
 
49
- def help
50
- opts = OptionParser.new do |o|
51
- o.banner = 'Usage: vagrant rimu <subcommand> [<args>]'
52
- o.separator ''
53
- o.separator 'Available subcommands:'
54
- keys = []
55
- @subcommands.each { |key, _value| keys << key.to_s }
56
- keys.sort.each do |key|
57
- o.separator " #{key}"
58
- end
59
- o.separator ''
60
- o.separator 'For help on any individual subcommand run `vagrant rimu <subcommand> -h`'
38
+ def usage
39
+ @env.ui.info I18n.t('vagrant_rimu.commands.root_usage')
40
+ @env.ui.info ''
41
+ @env.ui.info I18n.t('vagrant_rimu.commands.available_subcommands')
42
+ @commands.each do |key, value|
43
+ @env.ui.info " #{key.to_s.ljust(20)} #{value.synopsis}"
61
44
  end
62
- @env.ui.info(opts.help, prefix: false)
45
+ @env.ui.info ''
63
46
  end
64
47
  end
65
48
  end
@@ -0,0 +1,22 @@
1
+ require 'terminal-table'
2
+
3
+ module VagrantPlugins
4
+ module Rimu
5
+ module Commands
6
+ module Utils
7
+ # def display_item_list(env, items)
8
+ # rows = []
9
+ # items.each do |item|
10
+ # rows << [item.id, item.name]
11
+ # end
12
+ # display_table(env, %w(ID Name), rows)
13
+ # end
14
+
15
+ def display_table(env, headers, rows)
16
+ table = Terminal::Table.new headings: headers, rows: rows
17
+ env[:ui].info("\n#{table}")
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -137,6 +137,7 @@ module VagrantPlugins
137
137
  @data_centre = UNSET_VALUE
138
138
  end
139
139
 
140
+ # rubocop:disable Metrics/AbcSize
140
141
  def finalize!
141
142
  @api_key = ENV['RIMU_API_KEY'] if @api_key == UNSET_VALUE
142
143
  @api_url = ENV['RIMU_URL'] if @api_url == UNSET_VALUE
@@ -164,8 +165,8 @@ module VagrantPlugins
164
165
 
165
166
  def validate(machine)
166
167
  errors = []
167
- errors << I18n.t('vagrant_rimu.config.api_key') if !@api_key
168
- errors << I18n.t('vagrant_rimu.config.host_name') if !@host_name
168
+ errors << I18n.t('vagrant_rimu.config.api_key') unless @api_key
169
+ errors << I18n.t('vagrant_rimu.config.host_name') unless @host_name
169
170
  if @host_name
170
171
  errors << I18n.t('vagrant_rimu.config.invalid_host_name', {:host_name => @host_name}) \
171
172
  unless @host_name.match(/\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/)
@@ -18,6 +18,10 @@ module VagrantPlugins
18
18
  class ApiError < RimuError
19
19
  error_key(:api_error)
20
20
  end
21
+
22
+ class NoArgRequiredForCommand < RimuError
23
+ error_key(:no_args)
24
+ end
21
25
  end
22
26
  end
23
27
  end
@@ -45,7 +45,7 @@ module VagrantPlugins
45
45
  # Setup logging and i18n
46
46
  Rimu.init_i18n
47
47
  Rimu.init_logging
48
-
48
+
49
49
  require_relative "commands/rebuild"
50
50
  Commands::Rebuild
51
51
  end
@@ -33,7 +33,7 @@ module VagrantPlugins
33
33
  # key in the environment.
34
34
  env = @machine.action("read_state")
35
35
 
36
- state_id = env[:machine_state_id]
36
+ state_id = env[:machine_state]
37
37
 
38
38
  # Get the short and long description
39
39
  short = I18n.t("vagrant_rimu.states.short_#{state_id}")
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Rimu
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.7'
4
4
  end
5
5
  end
@@ -14,6 +14,8 @@ en:
14
14
  Starting the VPS...
15
15
  stopping: |-
16
16
  Stopping the VPS...
17
+ moving: |-
18
+ Moving the VPS to different host...
17
19
  terminating: |-
18
20
  Terminating the VPS...
19
21
  waiting_for_ready: |-
@@ -21,10 +23,15 @@ en:
21
23
  will_not_destroy: |-
22
24
  The VPS '%{name}' will not be destroyed, since the confirmation
23
25
  was declined.
26
+ will_not_stop: |-
27
+ The VPS '%{name}' will not be stopped, as the Rimu API does not
28
+ support this action. To stop your VPS run `vagrant ssh` and then
29
+ `halt` on the VPS console.
24
30
  ip_address: |-
25
31
  Assigned IP address: %{ip}
26
32
  creating_user: "Creating user account: %{user}..."
27
33
  modifying_sudo: "Modifying sudoers file to remove tty requirement..."
34
+ action_not_supported: "The requested command is not supported by this provider"
28
35
  reloading: "Rebooting the VPS..."
29
36
  rebuilding: "Rebuilding the VPS..."
30
37
  config:
@@ -35,25 +42,6 @@ en:
35
42
  private_key: "A valid SSH private key path option: [private_key_path] is required"
36
43
  missing_private_key: "SSH private key not found: %{key}"
37
44
  public_key: "SSH public key not found: %{key}"
38
- errors:
39
- api_error: |-
40
- The API request failed. Please inspect the error message
41
- below for more info.
42
-
43
- Error: %{stderr}
44
- public_key: |-
45
- There was an issue reading the public key at:
46
-
47
- Path: %{path}
48
-
49
- Please check the file's permissions.
50
- rsync: |-
51
- There was an error when attemping to rsync a share folder.
52
- Please inspect the error message below for more info.
53
-
54
- Host path: %{hostpath}
55
- Guest path: %{guestpath}
56
- Error: %{stderr}
57
45
  states:
58
46
  short_not_created: |-
59
47
  not created
@@ -65,8 +53,12 @@ en:
65
53
  The VPS is starting.
66
54
  short_stopped: |-
67
55
  stopped
56
+ short_off: |-
57
+ stopped
68
58
  long_stopped: |-
69
59
  The VPS is stopped. Run `vagrant up` to start it.
60
+ long_off: |-
61
+ The VPS is stopped. Run `vagrant up` to start it.
70
62
  short_stopping: |-
71
63
  stopping
72
64
  long_stopping: |-
@@ -74,6 +66,65 @@ en:
74
66
  run `vagrant up` and start it.
75
67
  short_running: |-
76
68
  running
69
+ short_active: |-
70
+ running
77
71
  long_running: |-
78
72
  The VPS is running. To stop this machine, you can run
79
73
  `vagrant halt`. To destroy the machine, you can run `vagrant destroy`.
74
+ long_active: |-
75
+ The VPS is running. To stop this machine, you can run
76
+ `vagrant halt`. To destroy the machine, you can run `vagrant destroy`.
77
+ current_state: |-
78
+ Machine state is `%{state}`
79
+ commands:
80
+ root_synopsis: |-
81
+ Rimu provider specific commands
82
+ root_usage: |-
83
+ Usage: vagrant rimu <subcommand> [<args>]
84
+ rebuild_usage: |-
85
+ Usage: vagrant rebuild [vm-name]
86
+ available_subcommands: |-
87
+ Available subcommands:
88
+ billing_methods: |-
89
+ List billing methods
90
+ list_distributions: |-
91
+ List Distributions
92
+ list_servers: |-
93
+ List servers
94
+ move: |-
95
+ Moves server to different host
96
+ rebuild: |-
97
+ Rebuilds the server, retaining the current IP address
98
+ errors:
99
+ global_error: |-
100
+ An unknown error happened in Vagrant Rimu provider
101
+
102
+ To easily debug what happened, we recommend to set the environment
103
+ variable VAGRANT_RIMU_LOG to debug
104
+
105
+ $ export VAGRANT_RIMU_LOG=debug
106
+
107
+ If doing this does not help fixing your issue, there may be a bug
108
+ in the provider. Please submit an issue on Github at
109
+ https://github.com/akissa/vagrant-rimu
110
+ with the stracktrace and the logs.
111
+ no_args: |-
112
+ Command '%{cmd}' does not required any argument.
113
+ api_error: |-
114
+ The API request failed. Please inspect the error message
115
+ below for more info.
116
+
117
+ Error: %{stderr}
118
+ public_key: |-
119
+ There was an issue reading the public key at:
120
+
121
+ Path: %{path}
122
+
123
+ Please check the file permissions.
124
+ rsync: |-
125
+ There was an error when attemping to rsync a share folder.
126
+ Please inspect the error message below for more info.
127
+
128
+ Host path: %{hostpath}
129
+ Guest path: %{guestpath}
130
+ Error: %{stderr}