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

#delete_vm, #delete_vm_from_cloud, #delete_vm_reference, #reboot_vm, #recreate_vm, #recreate_vm_skip_post_start

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
# 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
end

Instance Method Details

#delete_disk_referenceObject



41
42
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
# File 'lib/bosh/director/problem_handlers/missing_disk.rb', line 41

def delete_disk_reference
  @disk.update(active: false)

  # If VM is present we try to unmount and detach disk from VM
  if @instance.vm_cid && cloud.has_vm?(@instance.vm_cid)
    agent_client = agent_client(@instance.credentials, @instance.agent_id)
    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(@instance.vm_cid, @disk.disk_cid) if @instance.vm_cid
    rescue Bosh::Clouds::DiskNotAttached, Bosh::Clouds::DiskNotFound
    end
  end

  DiskManager.new(cloud, @logger).orphan_disk(@disk)

end

#descriptionObject



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

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