Class: HashiCorp::VagrantVMwareDesktop::Action::Destroy

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/vagrant-vmware-desktop/action/destroy.rb

Overview

This deletes the machine from the system.

Instance Method Summary collapse

Methods included from Common

#to_s

Constructor Details

#initialize(app, env) ⇒ Destroy

Returns a new instance of Destroy.



10
11
12
13
# File 'lib/vagrant-vmware-desktop/action/destroy.rb', line 10

def initialize(app, env)
  @app = app
  @logger = Log4r::Logger.new("hashicorp::provider::vmware::destroy")
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vagrant-vmware-desktop/action/destroy.rb', line 15

def call(env)
  if env[:machine].provider.state.id == :running
    raise Errors::DestroyInvalidState
  end

  # As long as the VM exists, we destroy it.
  if env[:machine].provider.state.id != :not_created
    env[:ui].info(I18n.t("hashicorp.vagrant_vmware_desktop.destroying"))
    env[:machine].provider.driver.delete
    env[:machine].id = nil
  end

  @app.call(env)
end