Class: Bosh::Director::Jobs::DeleteVm

Inherits:
BaseJob show all
Defined in:
lib/bosh/director/jobs/delete_vm.rb

Instance Attribute Summary

Attributes inherited from BaseJob

#task_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseJob

#begin_stage, #dns_manager, #event_manager, #logger, perform, #result_file, schedule_message, #single_step_stage, #task_cancelled?, #task_checkpoint, #track_and_log, #username

Constructor Details

#initialize(vm_cid) ⇒ DeleteVm

Returns a new instance of DeleteVm.



11
12
13
14
15
16
17
# File 'lib/bosh/director/jobs/delete_vm.rb', line 11

def initialize(vm_cid)
  @vm_cid = vm_cid
  @cloud = Config.cloud
  @vm_deleter = Bosh::Director::VmDeleter.new(@cloud, logger, false, false)
  @deployment_name = nil
  @instance_name = nil
end

Class Method Details

.job_typeObject



7
8
9
# File 'lib/bosh/director/jobs/delete_vm.rb', line 7

def self.job_type
  :delete_vm
end

Instance Method Details

#performObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bosh/director/jobs/delete_vm.rb', line 19

def perform
  logger.info("deleting vm: #{@vm_cid}")
  begin
    instance = Bosh::Director::Api::InstanceLookup.new.by_filter(vm_cid: @vm_cid).first
    @deployment_name = instance.deployment.name
    @instance_name = instance.name
    parent_id = add_event
    @vm_deleter.delete_for_instance(instance, false)
  rescue InstanceNotFound
    parent_id = add_event
    @vm_deleter.delete_vm(@vm_cid)
  end
rescue Bosh::Clouds::VMNotFound
  logger.info("vm #{@vm_cid} does not exists")
rescue Exception => e
  raise e
ensure
  add_event(parent_id, e)
  return "vm #{@vm_cid} deleted" unless e
end