Class: VagrantPlugins::Proxmox::Action::DestroyVm

Inherits:
ProxmoxAction
  • Object
show all
Defined in:
lib/vagrant-proxmox/action/destroy_vm.rb

Overview

This action destroys the virtual machine env

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ DestroyVm

Returns a new instance of DestroyVm.



8
9
10
11
# File 'lib/vagrant-proxmox/action/destroy_vm.rb', line 8

def initialize app, env
	@app = app
	@logger = Log4r::Logger.new 'vagrant_proxmox::action::destroy_vm'
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vagrant-proxmox/action/destroy_vm.rb', line 13

def call env
	env[:ui].info I18n.t('vagrant_proxmox.destroying_vm')

	begin
		node, vm_id = env[:machine].id.split '/'
		exit_status = connection(env).delete_vm vm_id
		exit_status == 'OK' ? exit_status : raise(VagrantPlugins::Proxmox::Errors::ProxmoxTaskFailed, proxmox_exit_status: exit_status)
	rescue StandardError => e
		raise VagrantPlugins::Proxmox::Errors::VMDestroyError, proxmox_exit_status: e.message
	end

	env[:ui].info I18n.t('vagrant_proxmox.done')

	next_action env
end