Class: Bosh::Director::VmDeleter

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/vm_deleter.rb

Instance Method Summary collapse

Constructor Details

#initialize(cloud, logger, force = false, enable_virtual_delete_vm = false) ⇒ VmDeleter

Returns a new instance of VmDeleter.



3
4
5
6
7
8
# File 'lib/bosh/director/vm_deleter.rb', line 3

def initialize(cloud, logger, force=false, enable_virtual_delete_vm=false)
  @cloud = cloud
  @logger = logger
  @error_ignorer = ErrorIgnorer.new(force, @logger)
  @enable_virtual_delete_vm = enable_virtual_delete_vm
end

Instance Method Details

#delete_for_instance(instance, store_event = true) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bosh/director/vm_deleter.rb', line 10

def delete_for_instance(instance, store_event=true)
  if instance.vm_cid
    begin
      vm_cid = instance.vm_cid
      instance_name = "#{instance.job}/#{instance.uuid}"
      parent_id = add_event(instance.deployment.name, instance_name, vm_cid) if store_event
      delete_vm(instance.vm_cid)
      instance.update(vm_cid: nil, agent_id: nil, trusted_certs_sha1: nil, credentials: nil)
    rescue Exception => e
      raise e
    ensure
      add_event(instance.deployment.name, instance_name, vm_cid, parent_id, e) if store_event
    end
  end
end

#delete_vm(vm_cid) ⇒ Object



26
27
28
29
30
31
# File 'lib/bosh/director/vm_deleter.rb', line 26

def delete_vm(vm_cid)
  @logger.info('Deleting VM')
  @error_ignorer.with_force_check do
    @cloud.delete_vm(vm_cid) unless @enable_virtual_delete_vm
  end
end