Class: Bosh::Director::ProblemHandlers::MissingDisk

Inherits:
Base
  • Object
show all
Defined in:
lib/bosh/director/problem_handlers/missing_disk.rb

Constant Summary

Constants included from CloudcheckHelper

CloudcheckHelper::DEFAULT_AGENT_TIMEOUT

Instance Attribute Summary

Attributes inherited from Base

#data, #job

Instance Method Summary collapse

Methods inherited from Base

action, action_for, #apply_resolution, auto_resolution, #auto_resolution, #auto_resolve, #checkpoint, #cloud, create_by_type, create_from_model, get_auto_resolution, inherited, init_dsl_data, plan, plan_for, register_as, resolution, #resolution_plan, #resolutions

Methods included from CloudcheckHelper

#agent_client, #agent_timeout_guard, #cloud, #delete_vm, #delete_vm_reference, #handler_error, #instance_name, #reboot_vm, #recreate_vm

Constructor Details

#initialize(disk_id, data) ⇒ MissingDisk

Returns a new instance of MissingDisk.



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

def initialize(disk_id, data)
  super
  @disk_id = disk_id
  @data = data
  @disk = Models::PersistentDisk[@disk_id]

  if @disk.nil?
    handler_error("Disk `#{@disk_id}' is no longer in the database")
  end

  @instance = @disk.instance
  if @instance.nil?
    handler_error("Cannot find instance for disk `#{@disk.disk_cid}'")
  end

  @vm = @instance.vm
end

Instance Method Details

#delete_disk_referenceObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/bosh/director/problem_handlers/missing_disk.rb', line 43

def delete_disk_reference
  @disk.db.transaction do
    @disk.update(active: false)
  end

  # If VM is present we try to unmount and detach disk from VM
  if @vm && @vm.cid && cloud.has_vm?(@vm.cid)
    agent_client = agent_client(@vm)
    disk_list = []

    begin
      disk_list = agent_client.list_disk
      if disk_list.include?(@disk.disk_cid)
        @logger.debug('Trying to unmount disk')
        agent_client.unmount_disk(@disk.disk_cid)
      end

    rescue Bosh::Director::RpcTimeout
      # When agent is not responding it probably is failing to
      # access missing disk. We continue with sending detach_disk
      # which should update agent settings.json and it should be
      # restarted successfully.
      @logger.debug('Agent is not responding, skipping unmount')
    rescue Bosh::Director::RpcRemoteException => e
      handler_error("Cannot unmount disk, #{e.message}")
    end

    begin
      @logger.debug('Sending cpi request: detach_disk')
      cloud.detach_disk(@vm.cid, @disk.disk_cid) if @vm.cid
    rescue Bosh::Clouds::DiskNotAttached
    end
  end

  @logger.debug('Deleting disk snapshots')
  Api::SnapshotManager.delete_snapshots(@disk.snapshots)

  begin
    @logger.debug('Sending cpi request: delete_disk')
    cloud.delete_disk(@disk.disk_cid)
  rescue Bosh::Clouds::DiskNotFound
  end

  @logger.debug('Removing disk reference from database')
  @disk.destroy
end

#descriptionObject



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

def description
  job = @instance.job || "unknown job"
  index = @instance.index || "unknown index"
  disk_label = "`#{@disk.disk_cid}' (#{job}/#{index}, #{@disk.size.to_i}M)"
  "Disk #{disk_label} is missing"
end