Class: VagrantPlugins::Abiquo::Actions::Destroy

Inherits:
Object
  • Object
show all
Includes:
Vagrant::Util::Retryable, Helpers::Abiquo
Defined in:
lib/vagrant_abiquo/actions/destroy.rb

Instance Method Summary collapse

Methods included from Helpers::Abiquo

#apply_state, #attach_net, #create_vapp, #create_vm, #deploy, #get_network, #get_template, #get_vapp, #get_vdc, #get_vm, #poweroff, #poweron, #reset, #update, #vapp_name

Constructor Details

#initialize(app, env) ⇒ Destroy

Returns a new instance of Destroy.



10
11
12
13
14
# File 'lib/vagrant_abiquo/actions/destroy.rb', line 10

def initialize(app, env)
  @app = app
  @machine = env[:machine]
  @logger = Log4r::Logger.new('vagrant::abiquo::destroy')
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/vagrant_abiquo/actions/destroy.rb', line 16

def call(env)
  client = env[:abiquo_client]
  env[:ui].info I18n.t('vagrant_abiquo.info.destroying', vm: @machine.name)
  vm = get_vm(client, @machine.id)
  vm.delete

  # Check when task finishes. This may take a while
  retryable(:tries => 120, :sleep => 5) do
    begin
      raise vm.label if vm.refresh
    rescue AbiquoAPIClient::NotFound
      env[:ui].info I18n.t('vagrant_abiquo.info.deleted', vm: @machine.name)
    end
  end

  vapp = vm.link(:virtualappliance).get
  vms = vapp.link(:virtualmachines).get.count
  if vms == 0
    vapp.delete
    env[:ui].info I18n.t('vagrant_abiquo.info.deleted_vapp', vapp: vapp.name)
  end

  @machine.id = nil
  @app.call(env)
end