Class: Bosh::Director::ProblemHandlers::InactiveDisk

Inherits:
Base
  • Object
show all
Defined in:
lib/bosh/director/problem_handlers/inactive_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) ⇒ InactiveDisk

Returns a new instance of InactiveDisk.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bosh/director/problem_handlers/inactive_disk.rb', line 10

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

  if @disk.active
    handler_error("Disk `#{@disk.disk_cid}' is no longer inactive")
  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

#activate_diskObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/bosh/director/problem_handlers/inactive_disk.rb', line 54

def activate_disk
  unless disk_mounted?
    handler_error("Disk is not mounted")
  end
  # Currently the director allows ONLY one persistent disk per
  # instance. We are about to activate a disk but the instance already
  # has an active disk.
  # For now let's be conservative and return an error.
  if @instance.persistent_disk
    handler_error("Instance already has an active disk")
  end
  @disk.active = true
  @disk.save
end

#delete_diskObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/bosh/director/problem_handlers/inactive_disk.rb', line 69

def delete_disk
  if disk_mounted?
    handler_error("Disk is currently in use")
  end

  if @vm
    begin
      cloud.detach_disk(@vm.cid, @disk.disk_cid)
    rescue => e
      # We are going to delete this disk anyway
      # and we know it's not in use, so we can ignore
      # detach errors here.
      @logger.warn(e)
    end
  end

  # FIXME: Currently there is no good way to know if delete_disk
  # failed because of cloud error or because disk doesn't exist
  # in vsphere_disks.
  begin
    cloud.delete_disk(@disk.disk_cid)
  rescue Bosh::Clouds::DiskNotFound, RuntimeError => e # FIXME
    @logger.warn(e)
  end

  @disk.destroy
end

#descriptionObject



32
33
34
35
36
37
# File 'lib/bosh/director/problem_handlers/inactive_disk.rb', line 32

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 inactive"
end

#disk_mounted?Boolean

Returns:

  • (Boolean)


97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/bosh/director/problem_handlers/inactive_disk.rb', line 97

def disk_mounted?
  return false if @vm.nil?

  begin
    agent_timeout_guard(@vm) do |agent|
      agent.list_disk.include?(@disk.disk_cid)
    end
  rescue RuntimeError
    # old stemcells without 'list_disk' support. We need to play
    # conservative and assume that the disk is mounted.
    true
  end
end