Class: Bosh::Director::InstanceDeleter

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

Overview

Coordinates the safe deletion of an instance and all associates resources.

Instance Method Summary collapse

Constructor Details

#initialize(ip_provider, dns_manager, disk_manager, options = {}) ⇒ InstanceDeleter

Returns a new instance of InstanceDeleter.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/bosh/director/instance_deleter.rb', line 5

def initialize(ip_provider, dns_manager, disk_manager, options={})
  @ip_provider = ip_provider
  @dns_manager = dns_manager
  @disk_manager = disk_manager
  @cloud = Config.cloud
  @logger = Config.logger
  @blobstore = App.instance.blobstores.blobstore
  @force = options.fetch(:force, false)
  @virtual_delete_vm = options.fetch(:virtual_delete_vm, false)

end

Instance Method Details

#delete_instance_plan(instance_plan, event_log_stage) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/bosh/director/instance_deleter.rb', line 17

def delete_instance_plan(instance_plan, event_log_stage)
  instance_model = instance_plan.new? ? instance_plan.instance.model : instance_plan.existing_instance
  deployment_name = instance_model.deployment.name
  instance_name = instance_model.name
  parent_id = add_event(deployment_name, instance_name)
  event_log_stage.advance_and_track(instance_model.to_s) do
    error_ignorer.with_force_check do
      stop(instance_plan)
    end

    vm_deleter.delete_for_instance(instance_model)

    unless instance_model.compilation
      error_ignorer.with_force_check do
        @disk_manager.delete_persistent_disks(instance_model)
      end

      error_ignorer.with_force_check do
        @dns_manager.delete_dns_for_instance(instance_model)
      end

      error_ignorer.with_force_check do
        RenderedJobTemplatesCleaner.new(instance_model, @blobstore, @logger).clean_all
      end
    end

    instance_plan.network_plans.each do |network_plan|
      reservation = network_plan.reservation
      @ip_provider.release(reservation) if reservation.reserved?
    end
    instance_plan.release_all_network_plans

    instance_model.destroy
  end
rescue Exception => e
  raise e
ensure
  add_event(deployment_name, instance_name, parent_id, e) if parent_id
end

#delete_instance_plans(instance_plans, event_log_stage, options = {}) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/bosh/director/instance_deleter.rb', line 57

def delete_instance_plans(instance_plans, event_log_stage, options = {})
  max_threads = options[:max_threads] || Config.max_threads
  ThreadPool.new(:max_threads => max_threads).wrap do |pool|
    instance_plans.each do |instance_plan|
      pool.process { delete_instance_plan(instance_plan, event_log_stage) }
    end
  end
end