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,91 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
require 'vagrant'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module Rimu
|
6
|
+
module Actions
|
7
|
+
class Create
|
8
|
+
include Vagrant::Util::Retryable
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@client = env[:rimu_api]
|
12
|
+
@machine = env[:machine]
|
13
|
+
@logger = Log4r::Logger.new('vagrant::rimu::create')
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
env[:ui].info I18n.t('vagrant_rimu.creating')
|
18
|
+
params = {
|
19
|
+
:billing_oid => @machine.provider_config.billing_id,
|
20
|
+
:dc_location => @machine.provider_config.data_centre,
|
21
|
+
:host_server_oid => @machine.provider_config.host_server_id,
|
22
|
+
:instantiation_options => {
|
23
|
+
:domain_name => @machine.provider_config.host_name,
|
24
|
+
:password => @machine.provider_config.root_password,
|
25
|
+
:distro => @machine.provider_config.distro_code,
|
26
|
+
:control_panel => @machine.provider_config.control_panel,
|
27
|
+
},
|
28
|
+
:instantiation_via_clone_options => {
|
29
|
+
:domain_name => @machine.provider_config.host_name,
|
30
|
+
:vps_order_oid_to_clone => @machine.provider_config.vps_to_clone,
|
31
|
+
},
|
32
|
+
:ip_request => {
|
33
|
+
:extra_ip_reason => @machine.provider_config.extra_ip_reason,
|
34
|
+
:num_ips => @machine.provider_config.num_ips,
|
35
|
+
:requested_ips => @machine.provider_config.private_ips,
|
36
|
+
},
|
37
|
+
:is_just_minimal_init => @machine.provider_config.minimal_init,
|
38
|
+
:vps_parameters => {
|
39
|
+
:disk_space_mb => @machine.provider_config.disk_space_mb,
|
40
|
+
:memory_mb => @machine.provider_config.memory_mb,
|
41
|
+
:disk_space_2_mb => @machine.provider_config.disk_space_2_mb,
|
42
|
+
},
|
43
|
+
:vps_type => @machine.provider_config.vps_type,
|
44
|
+
}
|
45
|
+
params.delete(:instantiation_via_clone_options) if @machine.provider_config.vps_to_clone.nil?
|
46
|
+
params.delete(:instantiation_options) if params.has_key?(:instantiation_via_clone_options)
|
47
|
+
if @machine.provider_config.root_password
|
48
|
+
root_pass = @machine.provider_config.root_password
|
49
|
+
else
|
50
|
+
root_pass = Digest::SHA2.new.update(@machine.provider_config.api_key).to_s
|
51
|
+
end
|
52
|
+
if params.has_key?(:instantiation_options)
|
53
|
+
params[:instantiation_options][:password] = root_pass
|
54
|
+
end
|
55
|
+
result = @client.servers.create(params)
|
56
|
+
@machine.id = result.order_oid
|
57
|
+
env[:ui].info I18n.t('vagrant_rimu.ip_address', {:ip => result.allocated_ips["primary_ip"]})
|
58
|
+
switch_user = @machine.provider_config.setup?
|
59
|
+
user = @machine.config.ssh.username
|
60
|
+
if switch_user
|
61
|
+
@machine.config.ssh.username = 'root'
|
62
|
+
@machine.config.ssh.password = root_pass
|
63
|
+
end
|
64
|
+
if params.has_key?(:instantiation_options)
|
65
|
+
retryable(:tries => 120, :sleep => 10) do
|
66
|
+
next if env[:interrupted]
|
67
|
+
raise 'not ready' if !@machine.communicate.ready?
|
68
|
+
end
|
69
|
+
end
|
70
|
+
@machine.config.ssh.username = user
|
71
|
+
@app.call(env)
|
72
|
+
end
|
73
|
+
|
74
|
+
def recover(env)
|
75
|
+
return if env['vagrant.error'].is_a?(Vagrant::Errors::VagrantError)
|
76
|
+
if @machine.state.id != :not_created
|
77
|
+
terminate(env)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def terminate(env)
|
82
|
+
destroy_env = env.dup
|
83
|
+
destroy_env.delete(:interrupted)
|
84
|
+
destroy_env[:config_validate] = false
|
85
|
+
destroy_env[:force_confirm_destroy] = true
|
86
|
+
env[:action_runner].run(Actions.destroy, destroy_env)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Rimu
|
3
|
+
module Actions
|
4
|
+
class ListDistributions
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
@client = env[:rimu_api]
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
env[:ui].info '%-6s %s' % ['Distro Code', 'Distro Description']
|
12
|
+
@client.distributions.each do |dist|
|
13
|
+
env[:ui].info '%-6s %s' % [dist.distro_code, dist.distro_description]
|
14
|
+
end
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Rimu
|
3
|
+
module Actions
|
4
|
+
class ListServers
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
@client = env[:rimu_api]
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
env[:ui].info '%-8s %-30s %-20s %-10s %-9s' % ['ID', 'Hostname', 'Data Centre', 'Host Server', 'Status']
|
12
|
+
@client.orders.orders.each do |o|
|
13
|
+
env[:ui].info '%-8s %-30s %-20s %-10s %-9s' % [o.order_oid, o.domain_name, o.location["data_center_location_code"], o.host_server_oid, o.running_state]
|
14
|
+
end
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Rimu
|
3
|
+
module Actions
|
4
|
+
class MessageAlreadyCreated
|
5
|
+
def initialize(app, _env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info(I18n.t('vagrant_rimu.already_status', :status => 'created'))
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Rimu
|
3
|
+
module Actions
|
4
|
+
class MessageAlreadyOff
|
5
|
+
def initialize(app, _env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info(I18n.t("vagrant_rimu.already_status", :status => :off))
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Rimu
|
3
|
+
module Actions
|
4
|
+
class MessageNotCreated
|
5
|
+
def initialize(app, _env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info(I18n.t('vagrant_rimu.not_created'))
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Rimu
|
3
|
+
module Actions
|
4
|
+
class MessageWillNotDestroy
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
@machine = env[:machine]
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
env[:ui].info(I18n.t('vagrant_rimu.will_not_destroy', {:name => @machine.name}))
|
12
|
+
@app.call(env)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Rimu
|
5
|
+
module Actions
|
6
|
+
class ModifyProvisionPath
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
@machine = env[:machine]
|
10
|
+
@logger = Log4r::Logger.new('vagrant::rimu::modify_provision_path')
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
# check if provisioning is enabled
|
15
|
+
enabled = true
|
16
|
+
enabled = env[:provision_enabled] if env.has_key?(:provision_enabled)
|
17
|
+
return @app.call(env) if !enabled
|
18
|
+
|
19
|
+
username = @machine.ssh_info()[:username]
|
20
|
+
|
21
|
+
# change ownership of the provisioning path recursively to the
|
22
|
+
# ssh user
|
23
|
+
#
|
24
|
+
@machine.config.vm.provisioners.each do |provisioner|
|
25
|
+
cfg = provisioner.config
|
26
|
+
path = cfg.upload_path if cfg.respond_to? :upload_path
|
27
|
+
path = cfg.provisioning_path if cfg.respond_to? :provisioning_path
|
28
|
+
@machine.communicate.sudo("chown -R #{username} #{path}",
|
29
|
+
:error_check => false)
|
30
|
+
end
|
31
|
+
|
32
|
+
@app.call(env)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Rimu
|
5
|
+
module Actions
|
6
|
+
class Move
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
@machine = env[:machine]
|
10
|
+
@client = client
|
11
|
+
@logger = Log4r::Logger.new('vagrant::rimu::move')
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
env[:ui].info I18n.t('vagrant_rimu.move')
|
16
|
+
fail 'not implemented'
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Rimu
|
5
|
+
module Actions
|
6
|
+
# This action reads the SSH info for the machine and puts it into the
|
7
|
+
# `:machine_ssh_info` key in the environment.
|
8
|
+
class ReadSSHInfo
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@machine = env[:machine]
|
12
|
+
@client = env[:rimu_api]
|
13
|
+
@logger = Log4r::Logger.new("vagrant_rimu::action::read_ssh_info")
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
env[:machine_ssh_info] = read_ssh_info(@client, @machine)
|
18
|
+
|
19
|
+
@app.call(env)
|
20
|
+
end
|
21
|
+
|
22
|
+
def read_ssh_info(client, machine)
|
23
|
+
return nil if machine.id.nil?
|
24
|
+
|
25
|
+
# Find the machine
|
26
|
+
server = client.orders.order(machine.id.to_i)
|
27
|
+
if server.nil?
|
28
|
+
# The machine can't be found
|
29
|
+
@logger.info("Machine couldn't be found, assuming it got destroyed.")
|
30
|
+
machine.id = nil
|
31
|
+
return nil
|
32
|
+
end
|
33
|
+
|
34
|
+
return {
|
35
|
+
:host => server.allocated_ips["primary_ip"],
|
36
|
+
:port => 22,
|
37
|
+
:username => "root"
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Rimu
|
5
|
+
module Actions
|
6
|
+
class ReadState
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
@machine = env[:machine]
|
10
|
+
@client = env[:rimu_api]
|
11
|
+
@logger = Log4r::Logger.new('vagrant_rimu::action::read_state')
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
env[:machine_state] = read_state(@client, @machine)
|
16
|
+
@logger.info "Machine state is '#{env[:machine_state]}'"
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
|
20
|
+
def read_state(client, machine)
|
21
|
+
return :not_created if machine.id.nil?
|
22
|
+
server = client.servers.status(machine.id.to_i)
|
23
|
+
return :not_created if server.nil?
|
24
|
+
status = server.running_state
|
25
|
+
return :not_created if status.nil?
|
26
|
+
states = {
|
27
|
+
'RUNNING' => :active,
|
28
|
+
'NOTRUNNING' => :off,
|
29
|
+
'RESTARTING' => :shutting_down,
|
30
|
+
'POWERCYCLING' => :shutting_down,
|
31
|
+
}
|
32
|
+
states[status.to_s]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Rimu
|
5
|
+
module Actions
|
6
|
+
class Rebuild
|
7
|
+
include Vagrant::Util::Retryable
|
8
|
+
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@client = env[:rimu_api]
|
12
|
+
@machine = env[:machine]
|
13
|
+
@logger = Log4r::Logger.new('vagrant::rimu::rebuild')
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
env[:ui].info I18n.t('vagrant_rimu.rebuilding')
|
18
|
+
params = {
|
19
|
+
:instantiation_options => {
|
20
|
+
:domain_name => @machine.provider_config.host_name,
|
21
|
+
:password => @machine.provider_config.root_password,
|
22
|
+
:distro => @machine.provider_config.distro_code,
|
23
|
+
:control_panel => @machine.provider_config.control_panel,
|
24
|
+
},
|
25
|
+
:instantiation_via_clone_options => {
|
26
|
+
:domain_name => @machine.provider_config.host_name,
|
27
|
+
:vps_order_oid_to_clone => @machine.provider_config.vps_to_clone,
|
28
|
+
},
|
29
|
+
:is_just_minimal_init => @machine.provider_config.minimal_init,
|
30
|
+
:vps_parameters => {
|
31
|
+
:disk_space_mb => @machine.provider_config.disk_space_mb,
|
32
|
+
:memory_mb => @machine.provider_config.memory_mb,
|
33
|
+
:disk_space_2_mb => @machine.provider_config.disk_space_2_mb,
|
34
|
+
},
|
35
|
+
}
|
36
|
+
params.delete(:instantiation_via_clone_options) if @machine.provider_config.vps_to_clone.nil?
|
37
|
+
params.delete(:instantiation_options) if params.has_key?(:instantiation_via_clone_options)
|
38
|
+
@client.servers.reinstall(@machine.id.to_i, params)
|
39
|
+
switch_user = @machine.provider_config.setup?
|
40
|
+
user = @machine.config.ssh.username
|
41
|
+
@machine.config.ssh.username = 'root' if switch_user
|
42
|
+
retryable(:tries => 120, :sleep => 10) do
|
43
|
+
next if env[:interrupted]
|
44
|
+
raise 'not ready' if !@machine.communicate.ready?
|
45
|
+
end
|
46
|
+
@machine.config.ssh.username = user
|
47
|
+
@app.call(env)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Rimu
|
5
|
+
module Actions
|
6
|
+
class Reload
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
@client = env[:rimu_api]
|
10
|
+
@machine = env[:machine]
|
11
|
+
@logger = Log4r::Logger.new('vagrant::rimu::reload')
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
env[:ui].info I18n.t('vagrant_rimu.reloading')
|
16
|
+
@client.servers.reboot(@machine.id.to_i)
|
17
|
+
|
18
|
+
@app.call(env)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Rimu
|
5
|
+
module Actions
|
6
|
+
class SetupSudo
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
@machine = env[:machine]
|
10
|
+
@logger = Log4r::Logger.new('vagrant::rimu::setup_sudo')
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
# check if setup is enabled
|
15
|
+
return @app.call(env) unless @machine.provider_config.setup?
|
16
|
+
|
17
|
+
# override ssh username to root
|
18
|
+
user = @machine.config.ssh.username
|
19
|
+
@machine.config.ssh.username = 'root'
|
20
|
+
|
21
|
+
# check for guest name available in Vagrant 1.2 first
|
22
|
+
guest_name = @machine.guest.name if @machine.guest.respond_to?(:name)
|
23
|
+
guest_name ||= @machine.guest.to_s.downcase
|
24
|
+
|
25
|
+
case guest_name
|
26
|
+
when /redhat/
|
27
|
+
env[:ui].info I18n.t('vagrant_rimu.modifying_sudo')
|
28
|
+
|
29
|
+
# disable tty requirement for sudo
|
30
|
+
@machine.communicate.execute(<<-'BASH')
|
31
|
+
sed -i'.bk' -e 's/\(Defaults\s\+requiretty\)/# \1/' /etc/sudoers
|
32
|
+
BASH
|
33
|
+
end
|
34
|
+
|
35
|
+
# reset ssh username
|
36
|
+
@machine.config.ssh.username = user
|
37
|
+
|
38
|
+
@app.call(env)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Rimu
|
5
|
+
module Actions
|
6
|
+
class SetupUser
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
@machine = env[:machine]
|
10
|
+
@logger = Log4r::Logger.new('vagrant::rimu::setup_user')
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
# check if setup is enabled
|
15
|
+
return @app.call(env) unless @machine.provider_config.setup?
|
16
|
+
|
17
|
+
# check if a username has been specified
|
18
|
+
return @app.call(env) unless @machine.config.ssh.username
|
19
|
+
|
20
|
+
# override ssh username to root temporarily
|
21
|
+
user = @machine.config.ssh.username
|
22
|
+
@machine.config.ssh.username = 'root'
|
23
|
+
|
24
|
+
env[:ui].info I18n.t('vagrant_rimu.creating_user', {
|
25
|
+
:user => user
|
26
|
+
})
|
27
|
+
|
28
|
+
# create user account
|
29
|
+
@machine.communicate.execute(<<-BASH)
|
30
|
+
if ! (grep ^#{user}: /etc/passwd); then
|
31
|
+
useradd -m -s /bin/bash #{user};
|
32
|
+
fi
|
33
|
+
BASH
|
34
|
+
|
35
|
+
# grant user sudo access with no password requirement
|
36
|
+
@machine.communicate.execute(<<-BASH)
|
37
|
+
if ! (grep #{user} /etc/sudoers); then
|
38
|
+
echo "#{user} ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers;
|
39
|
+
else
|
40
|
+
sed -i -e "/#{user}/ s/=.*/=(ALL:ALL) NOPASSWD: ALL/" /etc/sudoers;
|
41
|
+
fi
|
42
|
+
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
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Rimu
|
5
|
+
module Actions
|
6
|
+
class StartInstance
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
@client = env[:rimu_api]
|
10
|
+
@machine = env[:machine]
|
11
|
+
@logger = Log4r::Logger.new("vagrant_rimu::action::start_instance")
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
env[:ui].info I18n.t('vagrant_rimu.starting')
|
16
|
+
begin
|
17
|
+
result = @client.servers.start(@machine.id.to_i)
|
18
|
+
raise StandardError, "No response from the API" if result.nil?
|
19
|
+
raise StandardError, "VPS is not be running" if result.running_state != 'RUNNING'
|
20
|
+
rescue StandardError => e
|
21
|
+
raise Errors::ApiError, {:stderr=>e}
|
22
|
+
end
|
23
|
+
env[:ui].info(I18n.t("vagrant_rimu.ready"))
|
24
|
+
@app.call(env)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Rimu
|
5
|
+
module Actions
|
6
|
+
# This stops the running instance.
|
7
|
+
class StopInstance
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
@client = env[:rimu_api]
|
11
|
+
@logger = Log4r::Logger.new('vagrant_rimu::action::stop_instance')
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
if env[:machine].state.id == :stopped
|
16
|
+
env[:ui].info(I18n.t('vagrant_rimu.already_status', :status => env[:machine].state.id))
|
17
|
+
else
|
18
|
+
env[:ui].info(I18n.t('vagrant_rimu.stopping'))
|
19
|
+
@client.servers.shutdown(env[:machine].id.to_i)
|
20
|
+
end
|
21
|
+
@app.call(env)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Rimu
|
5
|
+
module Actions
|
6
|
+
# This terminates the running server, if there is one.
|
7
|
+
class TerminateInstance
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
@client = env[:rimu_api]
|
11
|
+
@logger = Log4r::Logger.new("vagrant_rimu::action::terminate_instance")
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
if env[:machine].id
|
16
|
+
env[:ui].info(I18n.t("vagrant_rimu.terminating"))
|
17
|
+
@client.servers.cancel(env[:machine].id.to_i)
|
18
|
+
env[:machine].id = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
@app.call(env)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|