Class: VagrantPlugins::VCenter::Action::Destroy

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-vcenter/action/destroy.rb

Overview

This class destroy the VM created by the Vagrant provider.

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Destroy

Returns a new instance of Destroy.



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

def initialize(app, env)
  @app = app
  @logger = Log4r::Logger.new('vagrant_vcenter::action::destroy')
end

Instance Method Details

#call(env) ⇒ Object



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

def call(env)
  config = env[:machine].provider_config
  # FIXME: Raise a correct exception
  dc = config.vcenter_cnx.serviceInstance.find_datacenter(
       config.datacenter_name) or abort 'datacenter not found'
  root_vm_folder = dc.vmFolder
  vm = root_vm_folder.findByUuid(env[:machine].id)

  # Poweron VM
  env[:ui].info('Destroying VM...')
  vm.Destroy_Task.wait_for_completion
  env[:machine].id = nil
end