vagrant-rimu 0.0.1
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.
- checksums.yaml +7 -0
- data/.codeclimate.yml +12 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.rubocop.yml +1170 -0
- data/.travis.yml +55 -0
- data/Gemfile +23 -0
- data/LICENSE +373 -0
- data/README.md +109 -0
- data/Rakefile +6 -0
- data/Vagrantfile +6 -0
- data/gemfiles/vagrant_1.5.gemfile +18 -0
- data/gemfiles/vagrant_1.6.gemfile +18 -0
- data/gemfiles/vagrant_1.7.gemfile +18 -0
- data/lib/vagrant-rimu/actions/billing_methods.rb +20 -0
- data/lib/vagrant-rimu/actions/connect_to_rimu.rb +23 -0
- data/lib/vagrant-rimu/actions/create.rb +91 -0
- data/lib/vagrant-rimu/actions/is_created.rb +16 -0
- data/lib/vagrant-rimu/actions/is_stopped.rb +17 -0
- data/lib/vagrant-rimu/actions/list_distributions.rb +20 -0
- data/lib/vagrant-rimu/actions/list_servers.rb +20 -0
- data/lib/vagrant-rimu/actions/message_already_created.rb +16 -0
- data/lib/vagrant-rimu/actions/message_already_off.rb +16 -0
- data/lib/vagrant-rimu/actions/message_not_created.rb +16 -0
- data/lib/vagrant-rimu/actions/message_will_not_destroy.rb +17 -0
- data/lib/vagrant-rimu/actions/modify_provision_path.rb +37 -0
- data/lib/vagrant-rimu/actions/move.rb +22 -0
- data/lib/vagrant-rimu/actions/read_ssh_info.rb +43 -0
- data/lib/vagrant-rimu/actions/read_state.rb +37 -0
- data/lib/vagrant-rimu/actions/rebuild.rb +52 -0
- data/lib/vagrant-rimu/actions/reload.rb +23 -0
- data/lib/vagrant-rimu/actions/setup_sudo.rb +43 -0
- data/lib/vagrant-rimu/actions/setup_user.rb +68 -0
- data/lib/vagrant-rimu/actions/start_instance.rb +29 -0
- data/lib/vagrant-rimu/actions/stop_instance.rb +26 -0
- data/lib/vagrant-rimu/actions/terminate_instance.rb +26 -0
- data/lib/vagrant-rimu/actions.rb +237 -0
- data/lib/vagrant-rimu/commands/billing_methods.rb +18 -0
- data/lib/vagrant-rimu/commands/distributions.rb +18 -0
- data/lib/vagrant-rimu/commands/list_servers.rb +18 -0
- data/lib/vagrant-rimu/commands/move.rb +18 -0
- data/lib/vagrant-rimu/commands/rebuild.rb +20 -0
- data/lib/vagrant-rimu/commands/root.rb +67 -0
- data/lib/vagrant-rimu/config.rb +190 -0
- data/lib/vagrant-rimu/errors.rb +21 -0
- data/lib/vagrant-rimu/plugin.rb +80 -0
- data/lib/vagrant-rimu/provider.rb +54 -0
- data/lib/vagrant-rimu/version.rb +5 -0
- data/lib/vagrant-rimu.rb +20 -0
- data/locales/en.yml +79 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/vagrant-rimu/actions/connect_to_rimu_spec.rb +38 -0
- data/spec/vagrant-rimu/actions/message_already_created_spec.rb +33 -0
- data/spec/vagrant-rimu/actions/message_already_off_spec.rb +33 -0
- data/spec/vagrant-rimu/actions/message_not_created_spec.rb +33 -0
- data/spec/vagrant-rimu/actions/message_will_not_destroy_spec.rb +36 -0
- data/spec/vagrant-rimu/actions/modify_provision_path_spec.rb +81 -0
- data/spec/vagrant-rimu/actions/read_ssh_info_spec.rb +62 -0
- data/spec/vagrant-rimu/actions/read_state_spec.rb +59 -0
- data/spec/vagrant-rimu/actions/rebuild_spec.rb +148 -0
- data/spec/vagrant-rimu/actions/reload_spec.rb +42 -0
- data/spec/vagrant-rimu/actions/setup_sudo_spec.rb +94 -0
- data/spec/vagrant-rimu/actions/setup_user_spec.rb +78 -0
- data/spec/vagrant-rimu/actions/start_instance_spec.rb +64 -0
- data/spec/vagrant-rimu/actions/stop_instance_spec.rb +57 -0
- data/spec/vagrant-rimu/actions/terminate_instance_spec.rb +54 -0
- data/spec/vagrant-rimu/actions_spec.rb +22 -0
- data/spec/vagrant-rimu/commands/billing_methods_spec.rb +4 -0
- data/spec/vagrant-rimu/commands/distributions_spec.rb +4 -0
- data/spec/vagrant-rimu/commands/list_servers_spec.rb +4 -0
- data/spec/vagrant-rimu/commands/move_spec.rb +4 -0
- data/spec/vagrant-rimu/commands/rebuild_spec.rb +4 -0
- data/spec/vagrant-rimu/commands/root_spec.rb +4 -0
- data/spec/vagrant-rimu/config_spec.rb +162 -0
- data/spec/vagrant-rimu/provider_spec.rb +13 -0
- data/test/Vagrantfile +30 -0
- data/test/scripts/provision.sh +3 -0
- data/test/test.sh +12 -0
- data/test/test_rimu_id_rsa +51 -0
- data/test/test_rimu_id_rsa.pub +1 -0
- data/vagrant-rimu.gemspec +25 -0
- metadata +238 -0
@@ -0,0 +1,237 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
require 'vagrant/action/builder'
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module Rimu
|
7
|
+
module Actions
|
8
|
+
include Vagrant::Action::Builtin
|
9
|
+
|
10
|
+
# This action is called to terminate the remote machine.
|
11
|
+
def self.action_destroy
|
12
|
+
Vagrant::Action::Builder.new.tap do |b|
|
13
|
+
b.use Call, DestroyConfirm do |env, b2|
|
14
|
+
if env[:result]
|
15
|
+
b2.use ConfigValidate
|
16
|
+
b.use Call, IsCreated do |env2, b3|
|
17
|
+
if !env2[:result]
|
18
|
+
b3.use MessageNotCreated
|
19
|
+
next
|
20
|
+
end
|
21
|
+
end
|
22
|
+
b2.use ConnectToRimu
|
23
|
+
b2.use TerminateInstance
|
24
|
+
else
|
25
|
+
b2.use MessageWillNotDestroy
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# This action is called to read the SSH info of the machine. The
|
32
|
+
# resulting state is expected to be put into the `:machine_ssh_info`
|
33
|
+
# key.
|
34
|
+
def self.action_read_ssh_info
|
35
|
+
Vagrant::Action::Builder.new.tap do |b|
|
36
|
+
b.use ConfigValidate
|
37
|
+
b.use ConnectToRimu
|
38
|
+
b.use ReadSSHInfo
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# This action is called to read the state of the machine. The
|
43
|
+
# resulting state is expected to be put into the `:machine_state_id`
|
44
|
+
# key.
|
45
|
+
def self.action_read_state
|
46
|
+
Vagrant::Action::Builder.new.tap do |b|
|
47
|
+
b.use ConfigValidate
|
48
|
+
b.use ConnectToRimu
|
49
|
+
b.use ReadState
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# This action is called to SSH into the machine.
|
54
|
+
def self.action_ssh
|
55
|
+
Vagrant::Action::Builder.new.tap do |b|
|
56
|
+
b.use ConfigValidate
|
57
|
+
b.use Call, IsCreated do |env, b2|
|
58
|
+
if !env[:result]
|
59
|
+
b2.use MessageNotCreated
|
60
|
+
next
|
61
|
+
end
|
62
|
+
|
63
|
+
b2.use SSHExec
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.action_ssh_run
|
69
|
+
Vagrant::Action::Builder.new.tap do |b|
|
70
|
+
b.use ConfigValidate
|
71
|
+
b.use Call, IsCreated do |env, b2|
|
72
|
+
if !env[:result]
|
73
|
+
b2.use MessageNotCreated
|
74
|
+
next
|
75
|
+
end
|
76
|
+
|
77
|
+
b2.use SSHRun
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# This action is called when `vagrant provision` is called.
|
83
|
+
def self.action_provision
|
84
|
+
return Vagrant::Action::Builder.new.tap do |builder|
|
85
|
+
builder.use ConfigValidate
|
86
|
+
builder.use ConnectToRimu
|
87
|
+
builder.use Call, IsCreated do |env, b|
|
88
|
+
case env[:machine_state]
|
89
|
+
when :active
|
90
|
+
b.use Provision
|
91
|
+
b.use ModifyProvisionPath
|
92
|
+
b.use SyncedFolders
|
93
|
+
when :off
|
94
|
+
env[:ui].info I18n.t('vagrant_rimu.off')
|
95
|
+
when :not_created
|
96
|
+
b.use MessageNotCreated
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.action_up
|
103
|
+
return Vagrant::Action::Builder.new.tap do |builder|
|
104
|
+
builder.use ConfigValidate
|
105
|
+
builder.use ConnectToRimu
|
106
|
+
builder.use Call, IsCreated do |env, b|
|
107
|
+
case env[:machine_state]
|
108
|
+
when :active
|
109
|
+
b.use MessageAlreadyCreated
|
110
|
+
when :off
|
111
|
+
b.use StartInstance
|
112
|
+
b.use action_provision
|
113
|
+
when :not_created
|
114
|
+
b.use Create
|
115
|
+
b.use SetupSudo
|
116
|
+
b.use SetupUser
|
117
|
+
b.use action_provision
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# This action is called to halt the remote machine.
|
124
|
+
def self.action_halt
|
125
|
+
Vagrant::Action::Builder.new.tap do |builder|
|
126
|
+
builder.use ConfigValidate
|
127
|
+
builder.use Call, IsCreated do |env, b1|
|
128
|
+
if env[:result]
|
129
|
+
b1.use Call, IsStopped do |env2, b2|
|
130
|
+
if env2[:result]
|
131
|
+
b2.use MessageAlreadyOff
|
132
|
+
else
|
133
|
+
b2.use ConnectToRimu
|
134
|
+
b2.use PowerOff
|
135
|
+
end
|
136
|
+
end
|
137
|
+
else
|
138
|
+
b1.use MessageNotCreated
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def self.action_reload
|
145
|
+
return Vagrant::Action::Builder.new.tap do |builder|
|
146
|
+
builder.use ConfigValidate
|
147
|
+
builder.use ConnectToRimu
|
148
|
+
builder.use Call, IsCreated do |env, b|
|
149
|
+
case env[:machine_state]
|
150
|
+
when :active
|
151
|
+
b.use Reload
|
152
|
+
b.use action_provision
|
153
|
+
when :off
|
154
|
+
env[:ui].info I18n.t('vagrant_rimu.off')
|
155
|
+
when :not_created
|
156
|
+
b.use MessageNotCreated
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def self.action_rebuild
|
163
|
+
return Vagrant::Action::Builder.new.tap do |builder|
|
164
|
+
builder.use ConfigValidate
|
165
|
+
builder.use ConnectToRimu
|
166
|
+
builder.use Call, IsCreated do |env, b|
|
167
|
+
case env[:machine_state]
|
168
|
+
when :active, :off
|
169
|
+
b.use Rebuild
|
170
|
+
b.use SetupSudo
|
171
|
+
b.use SetupUser
|
172
|
+
b.use action_provision
|
173
|
+
when :not_created
|
174
|
+
b.use MessageNotCreated
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def self.action_list_distributions
|
181
|
+
Vagrant::Action::Builder.new.tap do |b|
|
182
|
+
b.use ConfigValidate
|
183
|
+
b.use ConnectToRimu
|
184
|
+
b.use ListDistributions
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def self.action_list_servers
|
189
|
+
Vagrant::Action::Builder.new.tap do |b|
|
190
|
+
b.use ConfigValidate
|
191
|
+
b.use ConnectToRimu
|
192
|
+
b.use ListServers
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def self.action_billing_methods
|
197
|
+
Vagrant::Action::Builder.new.tap do |b|
|
198
|
+
b.use ConfigValidate
|
199
|
+
b.use ConnectToRimu
|
200
|
+
b.use BillingMethods
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def self.action_move
|
205
|
+
Vagrant::Action::Builder.new.tap do |b|
|
206
|
+
b.use ConfigValidate
|
207
|
+
b.use ConnectToRimu
|
208
|
+
b.use Move
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
action_root = Pathname.new(File.expand_path('../actions', __FILE__))
|
213
|
+
autoload :ConnectToRimu, action_root.join('connect_to_rimu')
|
214
|
+
autoload :StopInstance, action_root.join('stop_instance')
|
215
|
+
autoload :TerminateInstance, action_root.join('terminate_instance')
|
216
|
+
autoload :IsCreated, action_root.join('is_created')
|
217
|
+
autoload :IsStopped, action_root.join('is_stopped')
|
218
|
+
autoload :ReadSSHInfo, action_root.join('read_ssh_info')
|
219
|
+
autoload :ReadState, action_root.join('read_state')
|
220
|
+
autoload :StartInstance, action_root.join('start_instance')
|
221
|
+
autoload :Create, action_root.join('create')
|
222
|
+
autoload :SetupSudo, action_root.join('setup_sudo')
|
223
|
+
autoload :SetupUser, action_root.join('setup_user')
|
224
|
+
autoload :ModifyProvisionPath, action_root.join('modify_provision_path')
|
225
|
+
autoload :Reload, action_root.join('reload')
|
226
|
+
autoload :Rebuild, action_root.join('rebuild')
|
227
|
+
autoload :ListDistributions, action_root.join('list_distributions')
|
228
|
+
autoload :ListServers, action_root.join('list_servers')
|
229
|
+
autoload :BillingMethods, action_root.join('billing_methods')
|
230
|
+
autoload :Move, action_root.join('move')
|
231
|
+
autoload :MessageAlreadyOff, action_root.join('message_already_off')
|
232
|
+
autoload :MessageNotCreated, action_root.join('message_not_created')
|
233
|
+
autoload :MessageWillNotDestroy, action_root.join('message_will_not_destroy')
|
234
|
+
autoload :MessageAlreadyCreated, action_root.join('message_already_created')
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Rimu
|
3
|
+
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
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Rimu
|
3
|
+
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
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Rimu
|
3
|
+
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
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Rimu
|
3
|
+
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
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Rimu
|
5
|
+
module Commands
|
6
|
+
class Rebuild < Vagrant.plugin('2', :command)
|
7
|
+
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|
|
13
|
+
machine.action(:rebuild)
|
14
|
+
end
|
15
|
+
0
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Rimu
|
5
|
+
module Commands
|
6
|
+
class Root < Vagrant.plugin('2', :command)
|
7
|
+
def self.synopsis
|
8
|
+
'query Rimu for various options'
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(argv, env)
|
12
|
+
@main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
|
13
|
+
|
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
|
34
|
+
end
|
35
|
+
|
36
|
+
super(argv, env)
|
37
|
+
end
|
38
|
+
|
39
|
+
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
|
47
|
+
end
|
48
|
+
|
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`'
|
61
|
+
end
|
62
|
+
@env.ui.info(opts.help, prefix: false)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Rimu
|
3
|
+
class Config < Vagrant.plugin('2', :config)
|
4
|
+
# The API key for accessing Rimu.
|
5
|
+
#
|
6
|
+
# @return [String]
|
7
|
+
attr_accessor :api_key
|
8
|
+
|
9
|
+
# Rimu api url.
|
10
|
+
#
|
11
|
+
# @return [String]
|
12
|
+
attr_accessor :api_url
|
13
|
+
|
14
|
+
# Rimu distribution to install
|
15
|
+
#
|
16
|
+
# @return [String]
|
17
|
+
attr_accessor :distro_code
|
18
|
+
|
19
|
+
# Rimu data_centre
|
20
|
+
# DCDALLAS | DCLONDON | DCSYDNEY | DCBRISBANE | DCAUCKLAND | DCFRANKFURT
|
21
|
+
#
|
22
|
+
# @return [String]
|
23
|
+
attr_accessor :data_centre
|
24
|
+
|
25
|
+
# File system image size on primary partition in MB
|
26
|
+
#
|
27
|
+
# @return [Fixnum]
|
28
|
+
attr_accessor :disk_space_mb
|
29
|
+
|
30
|
+
# File system image size on secondary partition in MB
|
31
|
+
# Mostly not used.
|
32
|
+
#
|
33
|
+
# @return [Fixnum]
|
34
|
+
attr_accessor :disk_space_2_mb
|
35
|
+
|
36
|
+
# Memory size in MB
|
37
|
+
#
|
38
|
+
# @return [Fixnum]
|
39
|
+
attr_accessor :memory_mb
|
40
|
+
|
41
|
+
# You can specify a vps_type
|
42
|
+
# LOW_CONTENTION | REGULAR | DEDICATED
|
43
|
+
#
|
44
|
+
# @return [String]
|
45
|
+
attr_accessor :vps_type
|
46
|
+
|
47
|
+
# The label you want to give the server.
|
48
|
+
# It will need to be a fully qualified domain name (FQDN).
|
49
|
+
#
|
50
|
+
# @return [String]
|
51
|
+
attr_accessor :host_name
|
52
|
+
|
53
|
+
# The password to use when setting up the server.
|
54
|
+
# If not provided, a random one will be set.
|
55
|
+
#
|
56
|
+
# @return [String]
|
57
|
+
attr_accessor :root_password
|
58
|
+
|
59
|
+
# The control panel to install on the VPS.
|
60
|
+
# Currently only webmin is supported
|
61
|
+
#
|
62
|
+
# @return [String]
|
63
|
+
attr_accessor :control_panel
|
64
|
+
|
65
|
+
# Set this if you want the newly setup VPS to be a clone of another VPS
|
66
|
+
# The clone source VPS will be paused for a few seconds to a few minutes
|
67
|
+
# to take the snapshot.
|
68
|
+
#
|
69
|
+
# @return [Fixnum]
|
70
|
+
attr_accessor :vps_to_clone
|
71
|
+
|
72
|
+
# The reason for requiring more than one IP address.
|
73
|
+
# The number of IP addresses will be limited.
|
74
|
+
#
|
75
|
+
# @return [String]
|
76
|
+
attr_accessor :extra_ip_reason
|
77
|
+
|
78
|
+
# How many IPs you need. Typically 1.
|
79
|
+
#
|
80
|
+
# @return [Fixnum]
|
81
|
+
attr_accessor :num_ips
|
82
|
+
|
83
|
+
# This option is often used for customers wanting to setup a VPS
|
84
|
+
# with private IPs
|
85
|
+
#
|
86
|
+
# @return [String]
|
87
|
+
attr_accessor :private_ips
|
88
|
+
|
89
|
+
# Set the billing id if you want to control how it is billed.
|
90
|
+
# run `vagrant rimu billing-methods` to find what billing methods/ids
|
91
|
+
# you have setup on your account.
|
92
|
+
#
|
93
|
+
# @return [Fixnum]
|
94
|
+
attr_accessor :billing_id
|
95
|
+
|
96
|
+
# The host server on which to setup the server.
|
97
|
+
# Typically you will want to leave this blank and let the API decide
|
98
|
+
# what is best/available.
|
99
|
+
#
|
100
|
+
# An exception may be if you are a customer with a dedicated server
|
101
|
+
# that is a VPS host. And in that case you may want to force a VPS
|
102
|
+
# to be setup on a particular server of yours.
|
103
|
+
#
|
104
|
+
# @return [Fixnum]
|
105
|
+
attr_accessor :host_server_id
|
106
|
+
|
107
|
+
# Do minimal setup work.
|
108
|
+
#
|
109
|
+
# @return [bool]
|
110
|
+
attr_accessor :minimal_init
|
111
|
+
|
112
|
+
attr_accessor :setup
|
113
|
+
|
114
|
+
alias_method :setup?, :setup
|
115
|
+
|
116
|
+
def initialize
|
117
|
+
@api_key = UNSET_VALUE
|
118
|
+
@api_url = UNSET_VALUE
|
119
|
+
@distro_code = UNSET_VALUE
|
120
|
+
@setup = UNSET_VALUE
|
121
|
+
@disk_space_mb = UNSET_VALUE
|
122
|
+
@disk_space_2_mb = UNSET_VALUE
|
123
|
+
@memory_mb = UNSET_VALUE
|
124
|
+
@vps_type = UNSET_VALUE
|
125
|
+
@host_name = UNSET_VALUE
|
126
|
+
@root_password = UNSET_VALUE
|
127
|
+
@control_panel = UNSET_VALUE
|
128
|
+
@vps_to_clone = UNSET_VALUE
|
129
|
+
@extra_ip_reason = UNSET_VALUE
|
130
|
+
@num_ips = UNSET_VALUE
|
131
|
+
@private_ips = UNSET_VALUE
|
132
|
+
@billing_id = UNSET_VALUE
|
133
|
+
@host_server_id = UNSET_VALUE
|
134
|
+
@minimal_init = UNSET_VALUE
|
135
|
+
@data_centre = UNSET_VALUE
|
136
|
+
end
|
137
|
+
|
138
|
+
def finalize!
|
139
|
+
@api_key = ENV['RIMU_API_KEY'] if @api_key == UNSET_VALUE
|
140
|
+
@api_url = ENV['RIMU_URL'] if @api_url == UNSET_VALUE
|
141
|
+
@distro_code = "centos6.64" if @distro_code == UNSET_VALUE
|
142
|
+
@disk_space_mb = 20000 if @disk_space_mb == UNSET_VALUE
|
143
|
+
# @disk_space_mb = @disk_space_mb.to_i if @disk_space_mb.kind_of? String
|
144
|
+
@disk_space_2_mb = nil if @disk_space_2_mb == UNSET_VALUE
|
145
|
+
# @disk_space_2_mb = @disk_space_2_mb.to_i if @disk_space_2_mb.kind_of? String
|
146
|
+
@memory_mb = 1024 if @memory_mb == UNSET_VALUE
|
147
|
+
# @memory_mb = @memory_mb.to_i if @memory_mb.kind_of? String
|
148
|
+
@vps_type = nil if @vps_type == UNSET_VALUE
|
149
|
+
@host_name = nil if @host_name == UNSET_VALUE
|
150
|
+
@root_password = nil if @root_password == UNSET_VALUE
|
151
|
+
@control_panel = nil if @control_panel == UNSET_VALUE
|
152
|
+
@vps_to_clone = nil if @vps_to_clone == UNSET_VALUE
|
153
|
+
@extra_ip_reason = nil if @extra_ip_reason == UNSET_VALUE
|
154
|
+
@num_ips = nil if @num_ips == UNSET_VALUE
|
155
|
+
@private_ips = nil if @private_ips == UNSET_VALUE
|
156
|
+
@billing_id = nil if @billing_id == UNSET_VALUE
|
157
|
+
@host_server_id = nil if @host_server_id == UNSET_VALUE
|
158
|
+
@minimal_init = nil if @minimal_init == UNSET_VALUE
|
159
|
+
@data_centre = nil if @data_centre == UNSET_VALUE
|
160
|
+
@setup = true if @setup == UNSET_VALUE
|
161
|
+
end
|
162
|
+
|
163
|
+
def validate(machine)
|
164
|
+
errors = []
|
165
|
+
errors << I18n.t('vagrant_rimu.config.api_key') if !@api_key
|
166
|
+
errors << I18n.t('vagrant_rimu.config.host_name') if !@host_name
|
167
|
+
if @host_name
|
168
|
+
errors << I18n.t('vagrant_rimu.config.invalid_host_name', {:host_name => @host_name}) \
|
169
|
+
unless @host_name.match(/\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/)
|
170
|
+
end
|
171
|
+
|
172
|
+
key = machine.config.ssh.private_key_path
|
173
|
+
key = key[0] if key.is_a?(Array)
|
174
|
+
if !key
|
175
|
+
errors << I18n.t('vagrant_rimu.config.private_key')
|
176
|
+
else
|
177
|
+
if !File.file?(File.expand_path("#{key}", machine.env.root_path))
|
178
|
+
errors << I18n.t('vagrant_rimu.config.missing_private_key', key: "#{key}")
|
179
|
+
else
|
180
|
+
if !File.file?(File.expand_path("#{key}.pub", machine.env.root_path))
|
181
|
+
errors << I18n.t('vagrant_rimu.config.public_key', key: "#{key}.pub")
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
{ 'Rimu Provider' => errors }
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Rimu
|
3
|
+
module Errors
|
4
|
+
class RimuError < Vagrant::Errors::VagrantError
|
5
|
+
error_namespace("vagrant_rimu.errors")
|
6
|
+
end
|
7
|
+
|
8
|
+
class PublicKeyError < RimuError
|
9
|
+
error_key(:public_key)
|
10
|
+
end
|
11
|
+
|
12
|
+
class RsyncError < RimuError
|
13
|
+
error_key(:rsync)
|
14
|
+
end
|
15
|
+
|
16
|
+
class ApiError < RimuError
|
17
|
+
error_key(:api_error)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
begin
|
2
|
+
require 'vagrant'
|
3
|
+
rescue LoadError
|
4
|
+
raise 'The Vagrant Rimu plugin must be run within Vagrant.'
|
5
|
+
end
|
6
|
+
|
7
|
+
if Vagrant::VERSION < '1.5.0'
|
8
|
+
raise 'The Vagrant Rimu plugin is only compatible with Vagrant 1.5+'
|
9
|
+
end
|
10
|
+
|
11
|
+
module VagrantPlugins
|
12
|
+
module Rimu
|
13
|
+
class Plugin < Vagrant.plugin('2')
|
14
|
+
name 'Rimu'
|
15
|
+
description <<-DESC
|
16
|
+
This plugin installs a provider that allows Vagrant to manage
|
17
|
+
virtual machines using Rimuhosting's API.
|
18
|
+
DESC
|
19
|
+
|
20
|
+
config(:rimu, :provider) do
|
21
|
+
require_relative "config"
|
22
|
+
Config
|
23
|
+
end
|
24
|
+
|
25
|
+
provider(:rimu, {:box_optional => true, :parallel => true}) do
|
26
|
+
# Setup logging and i18n
|
27
|
+
setup_logging
|
28
|
+
setup_i18n
|
29
|
+
# Return the provider
|
30
|
+
require_relative "provider"
|
31
|
+
Provider
|
32
|
+
end
|
33
|
+
|
34
|
+
command(:rimu) do
|
35
|
+
require_relative "commands/root"
|
36
|
+
Commands::Root
|
37
|
+
end
|
38
|
+
|
39
|
+
command(:rebuild) do
|
40
|
+
require_relative "commands/rebuild"
|
41
|
+
Commands::Rebuild
|
42
|
+
end
|
43
|
+
|
44
|
+
# This initializes the internationalization strings.
|
45
|
+
def self.setup_i18n
|
46
|
+
I18n.load_path << File.expand_path("locales/en.yml", Rimu.source_root)
|
47
|
+
I18n.reload!
|
48
|
+
end
|
49
|
+
|
50
|
+
# This sets up our log level to be whatever VAGRANT_LOG is.
|
51
|
+
def self.setup_logging
|
52
|
+
require "log4r"
|
53
|
+
|
54
|
+
level = nil
|
55
|
+
begin
|
56
|
+
level = Log4r.const_get(ENV["VAGRANT_LOG"].upcase)
|
57
|
+
rescue NameError
|
58
|
+
# This means that the logging constant wasn't found,
|
59
|
+
# which is fine. We just keep `level` as `nil`. But
|
60
|
+
# we tell the user.
|
61
|
+
level = nil
|
62
|
+
end
|
63
|
+
|
64
|
+
# Some constants, such as "true" resolve to booleans, so the
|
65
|
+
# above error checking doesn't catch it. This will check to make
|
66
|
+
# sure that the log level is an integer, as Log4r requires.
|
67
|
+
level = nil if !level.is_a?(Integer)
|
68
|
+
|
69
|
+
# Set the logging level on all "vagrant" namespaced
|
70
|
+
# logs as long as we have a valid level.
|
71
|
+
if level
|
72
|
+
logger = Log4r::Logger.new("vagrant_rimu")
|
73
|
+
logger.outputters = Log4r::Outputter.stderr
|
74
|
+
logger.level = level
|
75
|
+
logger = nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|