Class: VagrantPlugins::XenServer::Action::DestroyVM

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

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ DestroyVM

Returns a new instance of DestroyVM.



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

def initialize(app, env)
  @app = app
  @logger = Log4r::Logger.new("vagrant::xenserver::actions::destroy_vm")
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vagrant-xenserver/action/destroy_vm.rb', line 13

def call(env)
  begin
    env[:xc].VM.hard_shutdown(env[:machine].id)
  rescue
  end

  vbds = env[:xc].VM.get_VBDs(env[:machine].id)
  
  vbds.each { |vbd| 
    vbd_rec = env[:xc].VBD.get_record(vbd)
    if vbd_rec['type'] == "Disk"
      env[:xc].VDI.destroy(vbd_rec['VDI'])
    end
  }

  env[:xc].VM.destroy(env[:machine].id)

  env[:machine].id = nil

  @app.call env
end