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.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sanity_checks.rb +1 -1
  3. data/lib/vagrant-proxmox.rb +1 -2
  4. data/lib/vagrant-proxmox/action.rb +133 -86
  5. data/lib/vagrant-proxmox/action/connect_proxmox.rb +10 -10
  6. data/lib/vagrant-proxmox/action/create_vm.rb +33 -28
  7. data/lib/vagrant-proxmox/action/destroy_vm.rb +10 -6
  8. data/lib/vagrant-proxmox/action/get_node_list.rb +8 -6
  9. data/lib/vagrant-proxmox/action/is_created.rb +1 -0
  10. data/lib/vagrant-proxmox/action/is_stopped.rb +1 -0
  11. data/lib/vagrant-proxmox/action/message_file_not_found.rb +21 -0
  12. data/lib/vagrant-proxmox/action/message_not_running.rb +20 -0
  13. data/lib/vagrant-proxmox/action/message_upload_server_error.rb +20 -0
  14. data/lib/vagrant-proxmox/action/proxmox_action.rb +6 -22
  15. data/lib/vagrant-proxmox/action/read_ssh_info.rb +1 -0
  16. data/lib/vagrant-proxmox/action/read_state.rb +11 -14
  17. data/lib/vagrant-proxmox/action/select_node.rb +23 -0
  18. data/lib/vagrant-proxmox/action/shutdown_vm.rb +8 -8
  19. data/lib/vagrant-proxmox/action/start_vm.rb +20 -12
  20. data/lib/vagrant-proxmox/action/stop_vm.rb +9 -8
  21. data/lib/vagrant-proxmox/action/sync_folders.rb +1 -1
  22. data/lib/vagrant-proxmox/action/upload_iso_file.rb +38 -0
  23. data/lib/vagrant-proxmox/action/upload_template_file.rb +38 -0
  24. data/lib/vagrant-proxmox/config.rb +85 -5
  25. data/lib/vagrant-proxmox/errors.rb +22 -2
  26. data/lib/vagrant-proxmox/plugin.rb +0 -14
  27. data/lib/vagrant-proxmox/proxmox/connection.rb +217 -0
  28. data/lib/vagrant-proxmox/proxmox/errors.rb +23 -0
  29. data/lib/vagrant-proxmox/version.rb +1 -1
  30. data/locales/en.yml +29 -2
  31. data/spec/actions/cleanup_after_destroy_action_spec.rb +2 -2
  32. data/spec/actions/connect_proxmox_action_spec.rb +32 -15
  33. data/spec/actions/create_vm_action_spec.rb +155 -130
  34. data/spec/actions/destroy_vm_action_spec.rb +50 -23
  35. data/spec/actions/get_node_list_action_spec.rb +25 -12
  36. data/spec/actions/is_created_action_spec.rb +8 -8
  37. data/spec/actions/is_stopped_action_spec.rb +8 -8
  38. data/spec/actions/message_already_running_action_spec.rb +2 -2
  39. data/spec/actions/message_already_stopped_action_spec.rb +2 -2
  40. data/spec/actions/message_file_not_found_spec.rb +23 -0
  41. data/spec/actions/message_not_created_action_spec.rb +2 -2
  42. data/spec/actions/message_not_running_action_spec.rb +23 -0
  43. data/spec/actions/message_upload_server_error_spec.rb +23 -0
  44. data/spec/actions/proxmox_action_shared.rb +0 -64
  45. data/spec/actions/proxmox_action_spec.rb +57 -0
  46. data/spec/actions/read_ssh_info_action_spec.rb +6 -6
  47. data/spec/actions/read_state_action_spec.rb +36 -34
  48. data/spec/actions/select_node_spec.rb +33 -0
  49. data/spec/actions/shutdown_vm_action_spec.rb +50 -22
  50. data/spec/actions/start_vm_action_spec.rb +87 -33
  51. data/spec/actions/stop_vm_action_spec.rb +50 -23
  52. data/spec/actions/sync_folders_action_spec.rb +9 -9
  53. data/spec/actions/upload_iso_file_action_spec.rb +70 -0
  54. data/spec/actions/upload_template_file_action_spec.rb +70 -0
  55. data/spec/commands/destroy_command_spec.rb +25 -25
  56. data/spec/commands/halt_command_spec.rb +17 -17
  57. data/spec/commands/provision_command_spec.rb +22 -9
  58. data/spec/commands/ssh_command_spec.rb +18 -5
  59. data/spec/commands/ssh_run_command_spec.rb +19 -6
  60. data/spec/commands/status_command_spec.rb +2 -2
  61. data/spec/commands/up_command_spec.rb +174 -34
  62. data/spec/config_spec.rb +325 -46
  63. data/spec/plugin_spec.rb +1 -8
  64. data/spec/provider_spec.rb +4 -4
  65. data/spec/proxmox/connection_spec.rb +662 -0
  66. data/spec/proxmox/rest_call_shared.rb +41 -0
  67. data/spec/sanity_checks_spec.rb +1 -1
  68. data/spec/spec_helper.rb +15 -97
  69. data/spec/spec_helpers/common_helpers.rb +111 -0
  70. data/spec/spec_helpers/time_helpers.rb +90 -0
  71. metadata +161 -45
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23fb93ead7521fd41b3728351658699cc8401c52
4
- data.tar.gz: 565cdfbaad59c6545b3c3068ded72091bcc25702
3
+ metadata.gz: 076be20bc1c88631ba0e7c3800e984cd8192e32a
4
+ data.tar.gz: 578fcb688c63d93d2d935d88267fec5f7e1866eb
5
5
  SHA512:
6
- metadata.gz: e57908d99222f860c2fc63adea89708947a25237bfa6c72a21c9037961d3d4f291a41bac8580bbbb0f6be69199e28bd5c634ae01355c41b4a7f230665912c11a
7
- data.tar.gz: 0120b509b00a936d85307e0ccefaf116b4fb9ac3d00f05d5360a884558031010a6b0bdb4c48588011001afcad959c980abbc34371ee4ba54d5ac0424f2a79b44
6
+ metadata.gz: 2d4aa5a81acc653d69477121d2912d0af8e3a2742f02fc85b8502788953859f148950d63f43866e5b59c0f6c0cf72d733cdba129ab76326bf5604cb5ce1cc5a9
7
+ data.tar.gz: c5f44f9e1675596a33ea8990ef44c3fccec2ecf902f9481c778b88f675c46feaf10a513d331abacee3a765f440b04af835297978d63d801c7117c9b1b68d07bb
data/lib/sanity_checks.rb CHANGED
@@ -6,6 +6,6 @@ end
6
6
 
7
7
  # This is a sanity check to make sure no one is attempting to install
8
8
  # this into an early Vagrant version.
9
- if Vagrant::VERSION < '1.2.0'
9
+ if Vagrant::VERSION < '1.4.0'
10
10
  raise 'The Vagrant Proxmox plugin is only compatible with Vagrant 1.2+'
11
11
  end
@@ -1,12 +1,11 @@
1
1
  require 'pathname'
2
2
  require 'log4r'
3
- require 'rest-client'
4
- require 'retryable'
5
3
  require 'active_support/core_ext/object/try'
6
4
 
7
5
  require 'sanity_checks'
8
6
  require 'vagrant-proxmox/plugin'
9
7
  require 'vagrant-proxmox/errors'
8
+ require 'vagrant-proxmox/proxmox/connection'
10
9
 
11
10
 
12
11
  module VagrantPlugins
@@ -32,128 +32,175 @@ module VagrantPlugins
32
32
  end
33
33
  else
34
34
  b1.use GetNodeList
35
+ b1.use SelectNode
35
36
  b1.use Provision
36
- b1.use CreateVm
37
- b1.use StartVm
38
- b1.use SyncFolders
37
+ if env1[:machine].provider_config.vm_type == :openvz
38
+ b1.use Call, UploadTemplateFile do |env2, b2|
39
+ if env2[:result] == :ok
40
+ b2.use CreateVm
41
+ b2.use StartVm
42
+ b2.use SyncFolders
43
+ elsif env2[:result] == :file_not_found
44
+ b2.use MessageFileNotFound
45
+ elsif env2[:result] == :server_upload_error
46
+ b2.use MessageUploadServerError
47
+ end
48
+ end
49
+ elsif env1[:machine].provider_config.vm_type == :qemu
50
+ b1.use Call, UploadIsoFile do |env2, b2|
51
+ if env2[:result] == :ok
52
+ b2.use CreateVm
53
+ b2.use StartVm
54
+ b2.use SyncFolders
55
+ elsif env2[:result] == :file_not_found
56
+ b2.use MessageFileNotFound
57
+ elsif env2[:result] == :server_upload_error
58
+ b2.use MessageUploadServerError
59
+ end
60
+ end
61
+ end
39
62
  end
40
63
  end
41
64
  end
42
65
  end
43
66
 
44
- def self.action_provision
45
- Vagrant::Action::Builder.new.tap do |b|
46
- b.use ConfigValidate
47
- b.use Call, IsCreated do |env, b2|
48
- if env[:result]
49
- b2.use Provision
50
- b2.use SyncFolders
51
- else
52
- b2.use MessageNotCreated
67
+ def self.action_provision
68
+ Vagrant::Action::Builder.new.tap do |b|
69
+ b.use ConfigValidate
70
+ b.use Call, IsCreated do |env1, b1|
71
+ if env1[:result]
72
+ b1.use Call, IsStopped do |env2, b2|
73
+ if env2[:result]
74
+ b2.use MessageNotRunning
75
+ else
76
+ b2.use Provision
77
+ b2.use SyncFolders
78
+ end
53
79
  end
80
+ else
81
+ b1.use MessageNotCreated
54
82
  end
55
83
  end
56
84
  end
85
+ end
57
86
 
58
- def self.action_halt
59
- Vagrant::Action::Builder.new.tap do |b|
60
- b.use ConfigValidate
61
- b.use Call, IsCreated do |env1, b1|
62
- if env1[:result]
63
- b1.use Call, IsStopped do |env2, b2|
64
- if env2[:result]
65
- b2.use MessageAlreadyStopped
66
- else
67
- b2.use ConnectProxmox
68
- b2.use ShutdownVm
69
- end
87
+ def self.action_halt
88
+ Vagrant::Action::Builder.new.tap do |b|
89
+ b.use ConfigValidate
90
+ b.use Call, IsCreated do |env1, b1|
91
+ if env1[:result]
92
+ b1.use Call, IsStopped do |env2, b2|
93
+ if env2[:result]
94
+ b2.use MessageAlreadyStopped
95
+ else
96
+ b2.use ConnectProxmox
97
+ b2.use ShutdownVm
70
98
  end
71
- else
72
- b1.use MessageNotCreated
73
99
  end
100
+ else
101
+ b1.use MessageNotCreated
74
102
  end
75
103
  end
76
104
  end
105
+ end
77
106
 
78
- # This action is called to destroy the remote machine.
79
- def self.action_destroy
80
- Vagrant::Action::Builder.new.tap do |b|
81
- b.use ConfigValidate
82
- b.use ConnectProxmox
83
- b.use Call, IsCreated do |env1, b1|
84
- if env1[:result]
85
- b1.use Call, ::Vagrant::Action::Builtin::DestroyConfirm do |env2, b2|
86
- if env2[:result]
87
- b2.use Call, IsStopped do |env3, b3|
88
- b3.use ShutdownVm unless env3[:result]
89
- b3.use DestroyVm
90
- b3.use ::Vagrant::Action::Builtin::ProvisionerCleanup
91
- b3.use CleanupAfterDestroy
92
- end
93
- else
94
- b2.use ::VagrantPlugins::ProviderVirtualBox::Action::MessageWillNotDestroy
107
+ # This action is called to destroy the remote machine.
108
+ def self.action_destroy
109
+ Vagrant::Action::Builder.new.tap do |b|
110
+ b.use ConfigValidate
111
+ b.use ConnectProxmox
112
+ b.use Call, IsCreated do |env1, b1|
113
+ if env1[:result]
114
+ b1.use Call, ::Vagrant::Action::Builtin::DestroyConfirm do |env2, b2|
115
+ if env2[:result]
116
+ b2.use Call, IsStopped do |env3, b3|
117
+ b3.use ShutdownVm unless env3[:result]
118
+ b3.use DestroyVm
119
+ b3.use ::Vagrant::Action::Builtin::ProvisionerCleanup
120
+ b3.use CleanupAfterDestroy
95
121
  end
122
+ else
123
+ b2.use ::VagrantPlugins::ProviderVirtualBox::Action::MessageWillNotDestroy
96
124
  end
97
- else
98
- b1.use MessageNotCreated
99
125
  end
126
+ else
127
+ b1.use MessageNotCreated
100
128
  end
101
129
  end
102
130
  end
131
+ end
103
132
 
104
- def self.action_read_ssh_info
105
- Vagrant::Action::Builder.new.tap do |b|
106
- b.use ConfigValidate
107
- b.use ConnectProxmox
108
- b.use ReadSSHInfo
109
- end
133
+ def self.action_read_ssh_info
134
+ Vagrant::Action::Builder.new.tap do |b|
135
+ b.use ConfigValidate
136
+ b.use ConnectProxmox
137
+ b.use ReadSSHInfo
110
138
  end
139
+ end
111
140
 
112
- def self.action_ssh
113
- Vagrant::Action::Builder.new.tap do |b|
114
- b.use ConfigValidate
115
- b.use Call, IsCreated do |env, b2|
116
- if env[:result]
117
- b2.use SSHExec
118
- else
119
- b2.use MessageNotCreated
141
+ def self.action_ssh
142
+ Vagrant::Action::Builder.new.tap do |b|
143
+ b.use ConfigValidate
144
+ b.use Call, IsCreated do |env1, b1|
145
+ if env1[:result]
146
+ b1.use Call, IsStopped do |env2, b2|
147
+ if env2[:result]
148
+ b2.use MessageNotRunning
149
+ else
150
+ b2.use SSHExec
151
+ end
120
152
  end
153
+ else
154
+ b1.use MessageNotCreated
121
155
  end
122
156
  end
123
157
  end
158
+ end
124
159
 
125
- def self.action_ssh_run
126
- Vagrant::Action::Builder.new.tap do |b|
127
- b.use ConfigValidate
128
- b.use Call, IsCreated do |env, b2|
129
- if env[:result]
130
- b2.use SSHRun
131
- else
132
- b2.use MessageNotCreated
160
+ def self.action_ssh_run
161
+ Vagrant::Action::Builder.new.tap do |b|
162
+ b.use ConfigValidate
163
+ b.use Call, IsCreated do |env1, b1|
164
+ if env1[:result]
165
+ b1.use Call, IsStopped do |env2, b2|
166
+ if env2[:result]
167
+ b2.use MessageNotRunning
168
+ else
169
+ b2.use SSHRun
170
+ end
133
171
  end
172
+ else
173
+ b1.use MessageNotCreated
134
174
  end
135
175
  end
136
176
  end
177
+ end
137
178
 
138
- action_root = Pathname.new(File.expand_path '../action', __FILE__)
139
- autoload :ProxmoxAction, action_root.join('proxmox_action')
140
- autoload :ConnectProxmox, action_root.join('connect_proxmox')
141
- autoload :GetNodeList, action_root.join('get_node_list')
142
- autoload :ReadState, action_root.join('read_state')
143
- autoload :IsCreated, action_root.join('is_created')
144
- autoload :IsStopped, action_root.join('is_stopped')
145
- autoload :MessageAlreadyRunning, action_root.join('message_already_running')
146
- autoload :MessageAlreadyStopped, action_root.join('message_already_stopped')
147
- autoload :MessageNotCreated, action_root.join('message_not_created')
148
- autoload :CreateVm, action_root.join('create_vm')
149
- autoload :StartVm, action_root.join('start_vm')
150
- autoload :StopVm, action_root.join('stop_vm')
151
- autoload :ShutdownVm, action_root.join('shutdown_vm')
152
- autoload :DestroyVm, action_root.join('destroy_vm')
153
- autoload :CleanupAfterDestroy, action_root.join('cleanup_after_destroy')
154
- autoload :ReadSSHInfo, action_root.join('read_ssh_info')
155
- autoload :SyncFolders, action_root.join('sync_folders')
179
+ action_root = Pathname.new(File.expand_path '../action', __FILE__)
180
+ autoload :ProxmoxAction, action_root.join('proxmox_action')
181
+ autoload :ConnectProxmox, action_root.join('connect_proxmox')
182
+ autoload :GetNodeList, action_root.join('get_node_list')
183
+ autoload :SelectNode, action_root.join('select_node')
184
+ autoload :ReadState, action_root.join('read_state')
185
+ autoload :IsCreated, action_root.join('is_created')
186
+ autoload :IsStopped, action_root.join('is_stopped')
187
+ autoload :MessageAlreadyRunning, action_root.join('message_already_running')
188
+ autoload :MessageAlreadyStopped, action_root.join('message_already_stopped')
189
+ autoload :MessageNotCreated, action_root.join('message_not_created')
190
+ autoload :MessageNotRunning, action_root.join('message_not_running')
191
+ autoload :MessageFileNotFound, action_root.join('message_file_not_found')
192
+ autoload :MessageUploadServerError, action_root.join('message_upload_server_error')
193
+ autoload :CreateVm, action_root.join('create_vm')
194
+ autoload :StartVm, action_root.join('start_vm')
195
+ autoload :StopVm, action_root.join('stop_vm')
196
+ autoload :ShutdownVm, action_root.join('shutdown_vm')
197
+ autoload :DestroyVm, action_root.join('destroy_vm')
198
+ autoload :CleanupAfterDestroy, action_root.join('cleanup_after_destroy')
199
+ autoload :ReadSSHInfo, action_root.join('read_ssh_info')
200
+ autoload :SyncFolders, action_root.join('sync_folders')
201
+ autoload :UploadTemplateFile, action_root.join('upload_template_file')
202
+ autoload :UploadIsoFile, action_root.join('upload_iso_file')
156
203
 
157
- end
158
204
  end
159
205
  end
206
+ end
@@ -2,9 +2,8 @@ module VagrantPlugins
2
2
  module Proxmox
3
3
  module Action
4
4
 
5
- # This action connects to the Proxmox server and stores the access ticket
6
- # and csrf prevention token in env[:proxmox_ticket] and
7
- # env[:proxmox_csrf_prevention_token].
5
+ # This action connects to the Proxmox server and stores the
6
+ # connection in env[:proxmox_connection]
8
7
  class ConnectProxmox < ProxmoxAction
9
8
 
10
9
  def initialize app, env
@@ -13,13 +12,15 @@ module VagrantPlugins
13
12
  end
14
13
 
15
14
  def call env
16
- config = env[:machine].provider_config
17
- response = RestClient.post "#{config.endpoint}/access/ticket",
18
- username: config.user_name, password: config.password
19
15
  begin
20
- json_response = JSON.parse response.to_s, symbolize_names: true
21
- env[:proxmox_ticket] = json_response[:data][:ticket]
22
- env[:proxmox_csrf_prevention_token] = json_response[:data][:CSRFPreventionToken]
16
+ config = env[:machine].provider_config
17
+ connection = Connection.new config.endpoint,
18
+ vm_id_range: config.vm_id_range,
19
+ task_timeout: config.task_timeout,
20
+ task_status_check_interval: config.task_status_check_interval,
21
+ imgcopy_timeout: config.imgcopy_timeout
22
+ connection.login username: config.user_name, password: config.password
23
+ env[:proxmox_connection] = connection
23
24
  rescue => e
24
25
  raise Errors::CommunicationError, error_msg: e.message
25
26
  end
@@ -27,7 +28,6 @@ module VagrantPlugins
27
28
  end
28
29
 
29
30
  end
30
-
31
31
  end
32
32
  end
33
33
  end
@@ -14,29 +14,18 @@ module VagrantPlugins
14
14
  def call env
15
15
  env[:ui].info I18n.t('vagrant_proxmox.creating_vm')
16
16
  config = env[:machine].provider_config
17
- node = env[:proxmox_nodes].sample[:node]
17
+
18
+ node = env[:proxmox_selected_node]
18
19
  vm_id = nil
19
20
 
20
21
  begin
21
- retryable(tries: config.task_timeout,
22
- sleep: config.task_status_check_interval) do
23
- vm_id = get_free_vm_id env
24
- params = {vmid: vm_id,
25
- ostemplate: config.os_template,
26
- hostname: env[:machine].config.vm.hostname || env[:machine].name.to_s,
27
- password: 'vagrant',
28
- memory: config.vm_memory,
29
- description: "#{config.vm_name_prefix}#{env[:machine].name}"}
30
- get_machine_ip_address(env).try { |ip_address| params[:ip_address] = ip_address }
31
-
32
- response = RestClient.post "#{config.endpoint}/nodes/#{node}/openvz", params,
33
- {CSRFPreventionToken: env[:proxmox_csrf_prevention_token],
34
- cookies: {PVEAuthCookie: env[:proxmox_ticket]}}
35
- exit_status = wait_for_completion parse_task_id(response), node, env, 'vagrant_proxmox.errors.create_vm_timeout'
36
- exit_status == 'OK' ? exit_status : raise(VagrantPlugins::Proxmox::Errors::ProxmoxTaskFailed, proxmox_exit_status: exit_status)
37
- end
22
+ vm_id = connection(env).get_free_vm_id
23
+ params = create_params_openvz(config, env, vm_id) if config.vm_type == :openvz
24
+ params = create_params_qemu(config, env, vm_id) if config.vm_type == :qemu
25
+ exit_status = connection(env).create_vm node: node, vm_type: config.vm_type, params: params
26
+ exit_status == 'OK' ? exit_status : raise(VagrantPlugins::Proxmox::Errors::ProxmoxTaskFailed, proxmox_exit_status: exit_status)
38
27
  rescue StandardError => e
39
- raise VagrantPlugins::Proxmox::Errors::VMCreationError, proxmox_exit_status: e.message
28
+ raise VagrantPlugins::Proxmox::Errors::VMCreateError, proxmox_exit_status: e.message
40
29
  end
41
30
 
42
31
  env[:machine].id = "#{node}/#{vm_id}"
@@ -46,18 +35,34 @@ module VagrantPlugins
46
35
  end
47
36
 
48
37
  private
49
- def get_free_vm_id env
50
- response = RestClient.get "#{env[:machine].provider_config.endpoint}/cluster/resources?type=vm", {cookies: {PVEAuthCookie: env[:proxmox_ticket]}}
51
- json_response = JSON.parse response.to_s, symbolize_names: true
52
-
53
- allowed_vm_ids = env[:machine].provider_config.vm_id_range.to_set
54
- used_vm_ids = json_response[:data].map { |vm| vm[:vmid] }
55
- free_vm_ids = (allowed_vm_ids - used_vm_ids).sort
56
- free_vm_ids.empty? ? raise(VagrantPlugins::Proxmox::Errors::NoVmIdAvailable) : free_vm_ids.first
38
+ def create_params_qemu(config, env, vm_id)
39
+ network = 'e1000,bridge=vmbr0'
40
+ network = "e1000=#{get_machine_macaddress(env)},bridge=vmbr0" if get_machine_macaddress(env)
41
+ {vmid: vm_id,
42
+ name: env[:machine].config.vm.hostname || env[:machine].name.to_s,
43
+ ostype: config.qemu_os,
44
+ ide2: "#{config.qemu_iso},media=cdrom",
45
+ sata0: "raid:#{config.qemu_disk_size},format=qcow2",
46
+ sockets: 1,
47
+ cores: 1,
48
+ memory: config.vm_memory,
49
+ net0: network,
50
+ description: "#{config.vm_name_prefix}#{env[:machine].name}"}
57
51
  end
58
52
 
53
+ private
54
+ def create_params_openvz(config, env, vm_id)
55
+ {vmid: vm_id,
56
+ ostemplate: config.openvz_os_template,
57
+ hostname: env[:machine].config.vm.hostname || env[:machine].name.to_s,
58
+ password: 'vagrant',
59
+ memory: config.vm_memory,
60
+ description: "#{config.vm_name_prefix}#{env[:machine].name}"}
61
+ .tap do |params|
62
+ params[:ip_address] = get_machine_ip_address(env) if get_machine_ip_address(env)
63
+ end
64
+ end
59
65
  end
60
-
61
66
  end
62
67
  end
63
68
  end
@@ -2,21 +2,25 @@ module VagrantPlugins
2
2
  module Proxmox
3
3
  module Action
4
4
 
5
+ # This action destroys the virtual machine env[:machine]
5
6
  class DestroyVm < ProxmoxAction
6
7
 
7
8
  def initialize app, env
8
9
  @app = app
10
+ @logger = Log4r::Logger.new 'vagrant_proxmox::action::destroy_vm'
9
11
  end
10
12
 
11
13
  def call env
12
14
  env[:ui].info I18n.t('vagrant_proxmox.destroying_vm')
13
- node, vm_id = env[:machine].id.split '/'
14
- endpoint = env[:machine].provider_config.endpoint
15
- response = RestClient.delete "#{endpoint}/nodes/#{node}/openvz/#{vm_id}",
16
- {CSRFPreventionToken: env[:proxmox_csrf_prevention_token],
17
- cookies: {PVEAuthCookie: env[:proxmox_ticket]}}
18
15
 
19
- wait_for_completion parse_task_id(response), node, env, 'vagrant_proxmox.errors.destroy_vm_timeout'
16
+ begin
17
+ node, vm_id = env[:machine].id.split '/'
18
+ exit_status = connection(env).delete_vm vm_id
19
+ exit_status == 'OK' ? exit_status : raise(VagrantPlugins::Proxmox::Errors::ProxmoxTaskFailed, proxmox_exit_status: exit_status)
20
+ rescue StandardError => e
21
+ raise VagrantPlugins::Proxmox::Errors::VMDestroyError, proxmox_exit_status: e.message
22
+ end
23
+
20
24
  env[:ui].info I18n.t('vagrant_proxmox.done')
21
25
 
22
26
  next_action env