Class: VagrantPlugins::Proxmox::Action::StopVm

Inherits:
ProxmoxAction show all
Defined in:
lib/vagrant-proxmox/action/stop_vm.rb

Overview

This action stops a Proxmox virtual machine.

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ StopVm

Returns a new instance of StopVm.



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

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

Instance Method Details

#call(env) ⇒ Object



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

def call env
	endpoint = env[:machine].provider_config.endpoint
	node, vm_id = env[:machine].id.split '/'
	env[:ui].info I18n.t('vagrant_proxmox.stopping_vm')
	response = RestClient.post "#{endpoint}/nodes/#{node}/openvz/#{vm_id}/status/stop", nil,
														 {CSRFPreventionToken: env[:proxmox_csrf_prevention_token],
														  cookies: {PVEAuthCookie: env[:proxmox_ticket]}}

	wait_for_completion parse_task_id(response), node, env, 'vagrant_proxmox.errors.stop_vm_timeout'
	env[:ui].info I18n.t('vagrant_proxmox.done')

	next_action env
end