vagrant-proxmox 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sanity_checks.rb +1 -1
- data/lib/vagrant-proxmox.rb +1 -2
- data/lib/vagrant-proxmox/action.rb +133 -86
- data/lib/vagrant-proxmox/action/connect_proxmox.rb +10 -10
- data/lib/vagrant-proxmox/action/create_vm.rb +33 -28
- data/lib/vagrant-proxmox/action/destroy_vm.rb +10 -6
- data/lib/vagrant-proxmox/action/get_node_list.rb +8 -6
- data/lib/vagrant-proxmox/action/is_created.rb +1 -0
- data/lib/vagrant-proxmox/action/is_stopped.rb +1 -0
- data/lib/vagrant-proxmox/action/message_file_not_found.rb +21 -0
- data/lib/vagrant-proxmox/action/message_not_running.rb +20 -0
- data/lib/vagrant-proxmox/action/message_upload_server_error.rb +20 -0
- data/lib/vagrant-proxmox/action/proxmox_action.rb +6 -22
- data/lib/vagrant-proxmox/action/read_ssh_info.rb +1 -0
- data/lib/vagrant-proxmox/action/read_state.rb +11 -14
- data/lib/vagrant-proxmox/action/select_node.rb +23 -0
- data/lib/vagrant-proxmox/action/shutdown_vm.rb +8 -8
- data/lib/vagrant-proxmox/action/start_vm.rb +20 -12
- data/lib/vagrant-proxmox/action/stop_vm.rb +9 -8
- data/lib/vagrant-proxmox/action/sync_folders.rb +1 -1
- data/lib/vagrant-proxmox/action/upload_iso_file.rb +38 -0
- data/lib/vagrant-proxmox/action/upload_template_file.rb +38 -0
- data/lib/vagrant-proxmox/config.rb +85 -5
- data/lib/vagrant-proxmox/errors.rb +22 -2
- data/lib/vagrant-proxmox/plugin.rb +0 -14
- data/lib/vagrant-proxmox/proxmox/connection.rb +217 -0
- data/lib/vagrant-proxmox/proxmox/errors.rb +23 -0
- data/lib/vagrant-proxmox/version.rb +1 -1
- data/locales/en.yml +29 -2
- data/spec/actions/cleanup_after_destroy_action_spec.rb +2 -2
- data/spec/actions/connect_proxmox_action_spec.rb +32 -15
- data/spec/actions/create_vm_action_spec.rb +155 -130
- data/spec/actions/destroy_vm_action_spec.rb +50 -23
- data/spec/actions/get_node_list_action_spec.rb +25 -12
- data/spec/actions/is_created_action_spec.rb +8 -8
- data/spec/actions/is_stopped_action_spec.rb +8 -8
- data/spec/actions/message_already_running_action_spec.rb +2 -2
- data/spec/actions/message_already_stopped_action_spec.rb +2 -2
- data/spec/actions/message_file_not_found_spec.rb +23 -0
- data/spec/actions/message_not_created_action_spec.rb +2 -2
- data/spec/actions/message_not_running_action_spec.rb +23 -0
- data/spec/actions/message_upload_server_error_spec.rb +23 -0
- data/spec/actions/proxmox_action_shared.rb +0 -64
- data/spec/actions/proxmox_action_spec.rb +57 -0
- data/spec/actions/read_ssh_info_action_spec.rb +6 -6
- data/spec/actions/read_state_action_spec.rb +36 -34
- data/spec/actions/select_node_spec.rb +33 -0
- data/spec/actions/shutdown_vm_action_spec.rb +50 -22
- data/spec/actions/start_vm_action_spec.rb +87 -33
- data/spec/actions/stop_vm_action_spec.rb +50 -23
- data/spec/actions/sync_folders_action_spec.rb +9 -9
- data/spec/actions/upload_iso_file_action_spec.rb +70 -0
- data/spec/actions/upload_template_file_action_spec.rb +70 -0
- data/spec/commands/destroy_command_spec.rb +25 -25
- data/spec/commands/halt_command_spec.rb +17 -17
- data/spec/commands/provision_command_spec.rb +22 -9
- data/spec/commands/ssh_command_spec.rb +18 -5
- data/spec/commands/ssh_run_command_spec.rb +19 -6
- data/spec/commands/status_command_spec.rb +2 -2
- data/spec/commands/up_command_spec.rb +174 -34
- data/spec/config_spec.rb +325 -46
- data/spec/plugin_spec.rb +1 -8
- data/spec/provider_spec.rb +4 -4
- data/spec/proxmox/connection_spec.rb +662 -0
- data/spec/proxmox/rest_call_shared.rb +41 -0
- data/spec/sanity_checks_spec.rb +1 -1
- data/spec/spec_helper.rb +15 -97
- data/spec/spec_helpers/common_helpers.rb +111 -0
- data/spec/spec_helpers/time_helpers.rb +90 -0
- metadata +161 -45
@@ -2,8 +2,8 @@ module VagrantPlugins
|
|
2
2
|
module Proxmox
|
3
3
|
module Action
|
4
4
|
|
5
|
-
# This action gets a list of all the nodes
|
6
|
-
# and stores it under env[:proxmox_nodes]
|
5
|
+
# This action gets a list of all the nodes e.g. ['node1', 'node2'] of
|
6
|
+
# a Proxmox server cluster and stores it under env[:proxmox_nodes]
|
7
7
|
class GetNodeList < ProxmoxAction
|
8
8
|
|
9
9
|
def initialize app, env
|
@@ -11,10 +11,12 @@ module VagrantPlugins
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def call env
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
begin
|
15
|
+
env[:proxmox_nodes] = env[:proxmox_connection].get_node_list
|
16
|
+
next_action env
|
17
|
+
rescue => e
|
18
|
+
raise Errors::CommunicationError, error_msg: e.message
|
19
|
+
end
|
18
20
|
end
|
19
21
|
|
20
22
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Proxmox
|
3
|
+
module Action
|
4
|
+
|
5
|
+
class MessageFileNotFound < ProxmoxAction
|
6
|
+
|
7
|
+
def initialize app, env
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call env
|
12
|
+
#TODO add file name
|
13
|
+
env[:ui].info I18n.t('vagrant_proxmox.errors.file_not_found')
|
14
|
+
next_action env
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Proxmox
|
3
|
+
module Action
|
4
|
+
|
5
|
+
class MessageNotRunning < ProxmoxAction
|
6
|
+
|
7
|
+
def initialize app, env
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call env
|
12
|
+
env[:ui].info I18n.t('vagrant_proxmox.errors.vm_not_running')
|
13
|
+
next_action env
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Proxmox
|
3
|
+
module Action
|
4
|
+
|
5
|
+
class MessageUploadServerError < ProxmoxAction
|
6
|
+
|
7
|
+
def initialize app, env
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call env
|
12
|
+
env[:ui].info I18n.t('vagrant_proxmox.errors.upload_server_error')
|
13
|
+
next_action env
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -10,34 +10,18 @@ module VagrantPlugins
|
|
10
10
|
end
|
11
11
|
|
12
12
|
protected
|
13
|
-
def
|
14
|
-
|
13
|
+
def get_machine_ip_address env
|
14
|
+
env[:machine].config.vm.networks.select { |type, _| type == :public_network }.first[1][:ip] rescue nil
|
15
15
|
end
|
16
16
|
|
17
|
-
# Wait for the completion of the proxmox task with the given upid.
|
18
17
|
protected
|
19
|
-
def
|
20
|
-
|
21
|
-
retryable(on: VagrantPlugins::Proxmox::ProxmoxTaskNotFinished,
|
22
|
-
tries: env[:machine].provider_config.task_timeout,
|
23
|
-
sleep: env[:machine].provider_config.task_status_check_interval) do
|
24
|
-
exit_status = get_task_exitstatus task_upid, node, env
|
25
|
-
exit_status.nil? ? raise(VagrantPlugins::Proxmox::ProxmoxTaskNotFinished) : exit_status
|
26
|
-
end
|
27
|
-
rescue VagrantPlugins::Proxmox::ProxmoxTaskNotFinished
|
28
|
-
raise Errors::Timeout.new timeout_message
|
29
|
-
end
|
18
|
+
def get_machine_macaddress env
|
19
|
+
env[:machine].config.vm.networks.select { |type, _| type == :public_network }.first[1][:macaddress] rescue nil
|
30
20
|
end
|
31
21
|
|
32
22
|
protected
|
33
|
-
def
|
34
|
-
env[:
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
def get_task_exitstatus task_upid, node, env
|
39
|
-
response = RestClient.get "#{env[:machine].provider_config.endpoint}/nodes/#{node}/tasks/#{task_upid}/status", {cookies: {PVEAuthCookie: env[:proxmox_ticket]}}
|
40
|
-
parse_task_id(response)[:exitstatus]
|
23
|
+
def connection env
|
24
|
+
env[:proxmox_connection]
|
41
25
|
end
|
42
26
|
|
43
27
|
end
|
@@ -13,21 +13,18 @@ module VagrantPlugins
|
|
13
13
|
|
14
14
|
def call env
|
15
15
|
begin
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
rescue RestClient::InternalServerError
|
28
|
-
env[:machine_state_id] = :not_created
|
16
|
+
env[:machine_state_id] =
|
17
|
+
if env[:machine].id
|
18
|
+
node, vm_id = env[:machine].id.split '/'
|
19
|
+
env[:proxmox_connection].get_vm_state vm_id
|
20
|
+
else
|
21
|
+
:not_created
|
22
|
+
end
|
23
|
+
next_action env
|
24
|
+
rescue => e
|
25
|
+
raise Errors::CommunicationError, error_msg: e.message
|
29
26
|
end
|
30
|
-
|
27
|
+
|
31
28
|
end
|
32
29
|
|
33
30
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Proxmox
|
3
|
+
module Action
|
4
|
+
|
5
|
+
# This action reads the state of a Proxmox virtual machine and stores it
|
6
|
+
# in env[:machine_state_id].
|
7
|
+
class SelectNode < ProxmoxAction
|
8
|
+
|
9
|
+
def initialize app, env
|
10
|
+
@app = app
|
11
|
+
@logger = Log4r::Logger.new 'vagrant_proxmox::action::select_node'
|
12
|
+
end
|
13
|
+
|
14
|
+
def call env
|
15
|
+
env[:proxmox_selected_node] = env[:proxmox_nodes].sample
|
16
|
+
next_action env
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -2,7 +2,7 @@ module VagrantPlugins
|
|
2
2
|
module Proxmox
|
3
3
|
module Action
|
4
4
|
|
5
|
-
# This action shuts down
|
5
|
+
# This action shuts down the Proxmox virtual machine in env[:machine]
|
6
6
|
class ShutdownVm < ProxmoxAction
|
7
7
|
|
8
8
|
def initialize app, env
|
@@ -11,14 +11,14 @@ module VagrantPlugins
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def call env
|
14
|
-
endpoint = env[:machine].provider_config.endpoint
|
15
|
-
node, vm_id = env[:machine].id.split '/'
|
16
14
|
env[:ui].info I18n.t('vagrant_proxmox.shut_down_vm')
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
begin
|
16
|
+
node, vm_id = env[:machine].id.split '/'
|
17
|
+
exit_status = connection(env).shutdown_vm vm_id
|
18
|
+
exit_status == 'OK' ? exit_status : raise(VagrantPlugins::Proxmox::Errors::ProxmoxTaskFailed, proxmox_exit_status: exit_status)
|
19
|
+
rescue StandardError => e
|
20
|
+
raise VagrantPlugins::Proxmox::Errors::VMShutdownError, proxmox_exit_status: e.message
|
21
|
+
end
|
22
22
|
env[:ui].info I18n.t('vagrant_proxmox.done')
|
23
23
|
|
24
24
|
next_action env
|
@@ -2,7 +2,7 @@ module VagrantPlugins
|
|
2
2
|
module Proxmox
|
3
3
|
module Action
|
4
4
|
|
5
|
-
# This action starts
|
5
|
+
# This action starts the Proxmox virtual machine in env[:machine]
|
6
6
|
class StartVm < ProxmoxAction
|
7
7
|
|
8
8
|
def initialize app, env
|
@@ -11,23 +11,31 @@ module VagrantPlugins
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def call env
|
14
|
-
endpoint = env[:machine].provider_config.endpoint
|
15
|
-
node, vm_id = env[:machine].id.split '/'
|
16
14
|
env[:ui].info I18n.t('vagrant_proxmox.starting_vm')
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
begin
|
16
|
+
node, vm_id = env[:machine].id.split '/'
|
17
|
+
exit_status = connection(env).start_vm vm_id
|
18
|
+
exit_status == 'OK' ? exit_status : raise(VagrantPlugins::Proxmox::Errors::ProxmoxTaskFailed, proxmox_exit_status: exit_status)
|
19
|
+
rescue StandardError => e
|
20
|
+
raise VagrantPlugins::Proxmox::Errors::VMStartError, proxmox_exit_status: e.message
|
21
|
+
end
|
20
22
|
|
21
|
-
wait_for_completion parse_task_id(response), node, env, 'vagrant_proxmox.errors.start_vm_timeout'
|
22
23
|
env[:ui].info I18n.t('vagrant_proxmox.done')
|
23
24
|
|
24
25
|
env[:ui].info I18n.t('vagrant_proxmox.waiting_for_ssh_connection')
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
|
27
|
+
retryException = Class.new StandardError
|
28
|
+
|
29
|
+
begin
|
30
|
+
retryable(on: retryException,
|
31
|
+
tries: env[:machine].provider_config.ssh_timeout / env[:machine].provider_config.ssh_status_check_interval + 1,
|
32
|
+
sleep: env[:machine].provider_config.ssh_status_check_interval) do
|
33
|
+
raise retryException unless env[:interrupted] || env[:machine].communicate.ready?
|
34
|
+
end
|
35
|
+
rescue retryException
|
36
|
+
raise VagrantPlugins::Proxmox::Errors::SSHError
|
30
37
|
end
|
38
|
+
|
31
39
|
env[:ui].info I18n.t('vagrant_proxmox.done')
|
32
40
|
|
33
41
|
next_action env
|
@@ -2,7 +2,7 @@ module VagrantPlugins
|
|
2
2
|
module Proxmox
|
3
3
|
module Action
|
4
4
|
|
5
|
-
# This action stops
|
5
|
+
# This action stops the Proxmox virtual machine in env[:machine]
|
6
6
|
class StopVm < ProxmoxAction
|
7
7
|
|
8
8
|
def initialize app, env
|
@@ -11,14 +11,15 @@ module VagrantPlugins
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def call env
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
begin
|
15
|
+
node, vm_id = env[:machine].id.split '/'
|
16
|
+
env[:ui].info I18n.t('vagrant_proxmox.stopping_vm')
|
17
|
+
exit_status = connection(env).stop_vm vm_id
|
18
|
+
exit_status == 'OK' ? exit_status : raise(VagrantPlugins::Proxmox::Errors::ProxmoxTaskFailed, proxmox_exit_status: exit_status)
|
19
|
+
rescue StandardError => e
|
20
|
+
raise VagrantPlugins::Proxmox::Errors::VMStopError, proxmox_exit_status: e.message
|
21
|
+
end
|
20
22
|
|
21
|
-
wait_for_completion parse_task_id(response), node, env, 'vagrant_proxmox.errors.stop_vm_timeout'
|
22
23
|
env[:ui].info I18n.t('vagrant_proxmox.done')
|
23
24
|
|
24
25
|
next_action env
|
@@ -33,7 +33,7 @@ module VagrantPlugins
|
|
33
33
|
# rsync over to the guest path using the SSH info
|
34
34
|
command = [
|
35
35
|
'rsync', '--verbose', '--archive', '--compress', '--delete',
|
36
|
-
'-e', "ssh -p #{ssh_info[:port]} -i '#{ssh_info[:private_key_path]}' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null",
|
36
|
+
'-e', "ssh -p #{ssh_info[:port]} -i '#{ssh_info[:private_key_path][0]}' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null",
|
37
37
|
hostpath, "#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"]
|
38
38
|
|
39
39
|
rsync_process = Vagrant::Util::Subprocess.execute *command
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Proxmox
|
3
|
+
module Action
|
4
|
+
|
5
|
+
# This action uploads a iso file into the local storage a given node
|
6
|
+
class UploadIsoFile < ProxmoxAction
|
7
|
+
|
8
|
+
def initialize app, env
|
9
|
+
@app = app
|
10
|
+
@logger = Log4r::Logger.new 'vagrant_proxmox::action::iso_file_upload'
|
11
|
+
end
|
12
|
+
|
13
|
+
def call env
|
14
|
+
env[:result] = :ok
|
15
|
+
config = env[:machine].provider_config
|
16
|
+
if config.qemu_iso_file
|
17
|
+
env[:result] = upload_file env, config.qemu_iso_file
|
18
|
+
end
|
19
|
+
next_action env
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def upload_file env, filename
|
24
|
+
if File.exist? filename
|
25
|
+
begin
|
26
|
+
connection(env).upload_file(filename, content_type: 'iso', node: env[:proxmox_selected_node], storage: 'local')
|
27
|
+
:ok
|
28
|
+
rescue
|
29
|
+
:server_upload_error
|
30
|
+
end
|
31
|
+
else
|
32
|
+
:file_not_found
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Proxmox
|
3
|
+
module Action
|
4
|
+
|
5
|
+
# This action uploads a template file into the local storage of a given node
|
6
|
+
class UploadTemplateFile < ProxmoxAction
|
7
|
+
|
8
|
+
def initialize app, env
|
9
|
+
@app = app
|
10
|
+
@logger = Log4r::Logger.new 'vagrant_proxmox::action::template_file_upload'
|
11
|
+
end
|
12
|
+
|
13
|
+
def call env
|
14
|
+
env[:result] = :ok
|
15
|
+
config = env[:machine].provider_config
|
16
|
+
if config.openvz_template_file
|
17
|
+
env[:result] = upload_file env, config.openvz_template_file
|
18
|
+
end
|
19
|
+
next_action env
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def upload_file env, filename
|
24
|
+
if File.exist? filename
|
25
|
+
begin
|
26
|
+
connection(env).upload_file(filename, content_type: 'vztmpl', node: env[:proxmox_selected_node], storage: 'local')
|
27
|
+
:ok
|
28
|
+
rescue
|
29
|
+
:server_upload_error
|
30
|
+
end
|
31
|
+
else
|
32
|
+
:file_not_found
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -17,10 +17,20 @@ module VagrantPlugins
|
|
17
17
|
# @return [String]
|
18
18
|
attr_accessor :password
|
19
19
|
|
20
|
-
# The
|
20
|
+
# The virtual machine type, e.g. :openvz or :qemu
|
21
|
+
#
|
22
|
+
# @return [Symbol]
|
23
|
+
attr_accessor :vm_type
|
24
|
+
|
25
|
+
# The openvz os template to use for the virtual machine
|
21
26
|
#
|
22
27
|
# @return [String]
|
23
|
-
attr_accessor :
|
28
|
+
attr_accessor :openvz_os_template
|
29
|
+
|
30
|
+
# The openvz os template file to upload and use for the virtual machine
|
31
|
+
#
|
32
|
+
# @return [String]
|
33
|
+
attr_accessor :openvz_template_file
|
24
34
|
|
25
35
|
# The id range to use for the virtual machines
|
26
36
|
#
|
@@ -47,16 +57,60 @@ module VagrantPlugins
|
|
47
57
|
# @return [Integer, Proc]
|
48
58
|
attr_accessor :task_status_check_interval
|
49
59
|
|
60
|
+
# The maximum timeout for a ssh connection to a virtual machine (in seconds)
|
61
|
+
#
|
62
|
+
# @return [Integer]
|
63
|
+
attr_accessor :ssh_timeout
|
64
|
+
|
65
|
+
# The interval between two ssh reachability status retrievals (in seconds)
|
66
|
+
#
|
67
|
+
# @return [Integer, Proc]
|
68
|
+
attr_accessor :ssh_status_check_interval
|
69
|
+
|
70
|
+
# The maximum timeout for a proxmox server task if it's an upload (in seconds)
|
71
|
+
#
|
72
|
+
# @return [Integer]
|
73
|
+
attr_accessor :imgcopy_timeout
|
74
|
+
|
75
|
+
# The qemu virtual machine operating system, e.g. :l26
|
76
|
+
#
|
77
|
+
# @return [Symbol]
|
78
|
+
attr_accessor :qemu_os
|
79
|
+
|
80
|
+
# The qemu iso file to use for the virtual machine
|
81
|
+
#
|
82
|
+
# @return [String]
|
83
|
+
attr_accessor :qemu_iso
|
84
|
+
|
85
|
+
# The qemu iso file to upload and use for the virtual machine
|
86
|
+
#
|
87
|
+
# @return [String]
|
88
|
+
attr_accessor :qemu_iso_file
|
89
|
+
|
90
|
+
# The qemu disk size to use for the virtual machine, e.g. '30G'
|
91
|
+
#
|
92
|
+
# @return [String]
|
93
|
+
attr_accessor :qemu_disk_size
|
94
|
+
|
50
95
|
def initialize
|
51
96
|
@endpoint = UNSET_VALUE
|
52
97
|
@user_name = UNSET_VALUE
|
53
98
|
@password = UNSET_VALUE
|
54
|
-
@
|
99
|
+
@vm_type = UNSET_VALUE
|
100
|
+
@openvz_os_template = UNSET_VALUE
|
101
|
+
@openvz_template_file = UNSET_VALUE
|
55
102
|
@vm_id_range = 900..999
|
56
103
|
@vm_name_prefix = 'vagrant_'
|
57
104
|
@vm_memory = 512
|
58
105
|
@task_timeout = 60
|
59
106
|
@task_status_check_interval = 2
|
107
|
+
@ssh_timeout = 60
|
108
|
+
@ssh_status_check_interval = 5
|
109
|
+
@imgcopy_timeout = 120
|
110
|
+
@qemu_os = UNSET_VALUE
|
111
|
+
@qemu_iso = UNSET_VALUE
|
112
|
+
@qemu_iso_file = UNSET_VALUE
|
113
|
+
@qemu_disk_size = UNSET_VALUE
|
60
114
|
end
|
61
115
|
|
62
116
|
# This is the hook that is called to finalize the object before it is put into use.
|
@@ -64,7 +118,16 @@ module VagrantPlugins
|
|
64
118
|
@endpoint = nil if @endpoint == UNSET_VALUE
|
65
119
|
@user_name = nil if @user_name == UNSET_VALUE
|
66
120
|
@password = nil if @password == UNSET_VALUE
|
67
|
-
@
|
121
|
+
@vm_type = nil if @vm_type == UNSET_VALUE
|
122
|
+
@openvz_template_file = nil if @openvz_template_file == UNSET_VALUE
|
123
|
+
@openvz_os_template = "local:vztmpl/#{File.basename @openvz_template_file}" if @openvz_template_file
|
124
|
+
@openvz_os_template = nil if @openvz_os_template == UNSET_VALUE
|
125
|
+
@qemu_os = nil if @qemu_os == UNSET_VALUE
|
126
|
+
@qemu_iso_file = nil if @qemu_iso_file == UNSET_VALUE
|
127
|
+
@qemu_iso = "local:iso/#{File.basename @qemu_iso_file}" if @qemu_iso_file
|
128
|
+
@qemu_iso = nil if @qemu_iso == UNSET_VALUE
|
129
|
+
@qemu_disk_size = nil if @qemu_disk_size == UNSET_VALUE
|
130
|
+
@qemu_disk_size = convert_disk_size_to_gigabyte @qemu_disk_size if @qemu_disk_size
|
68
131
|
end
|
69
132
|
|
70
133
|
def validate machine
|
@@ -72,10 +135,27 @@ module VagrantPlugins
|
|
72
135
|
errors << I18n.t('vagrant_proxmox.errors.no_endpoint_specified') unless @endpoint
|
73
136
|
errors << I18n.t('vagrant_proxmox.errors.no_user_name_specified') unless @user_name
|
74
137
|
errors << I18n.t('vagrant_proxmox.errors.no_password_specified') unless @password
|
75
|
-
errors << I18n.t('vagrant_proxmox.errors.
|
138
|
+
errors << I18n.t('vagrant_proxmox.errors.no_vm_type_specified') unless @vm_type
|
139
|
+
if @vm_type == :openvz
|
140
|
+
errors << I18n.t('vagrant_proxmox.errors.no_openvz_os_template_or_openvz_template_file_specified_for_type_openvz') unless @openvz_os_template || @openvz_template_file
|
141
|
+
end
|
142
|
+
if @vm_type == :qemu
|
143
|
+
errors << I18n.t('vagrant_proxmox.errors.no_qemu_os_specified_for_vm_type_qemu') unless @qemu_os
|
144
|
+
errors << I18n.t('vagrant_proxmox.errors.no_qemu_iso_or_qemu_iso_file_specified_for_vm_type_qemu') unless @qemu_iso || @qemu_iso_file
|
145
|
+
errors << I18n.t('vagrant_proxmox.errors.no_qemu_disk_size_specified_for_vm_type_qemu') unless @qemu_disk_size
|
146
|
+
end
|
76
147
|
{'Proxmox Provider' => errors}
|
77
148
|
end
|
78
149
|
|
150
|
+
private
|
151
|
+
def convert_disk_size_to_gigabyte disk_size
|
152
|
+
case disk_size[-1]
|
153
|
+
when 'G'
|
154
|
+
disk_size[0..-2]
|
155
|
+
else
|
156
|
+
disk_size
|
157
|
+
end
|
158
|
+
end
|
79
159
|
end
|
80
160
|
end
|
81
161
|
end
|