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

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

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

Instance Method Details

#activate_diskObject



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

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



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/bosh/director/problem_handlers/inactive_disk.rb', line 68

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

  if @instance.vm_cid
    begin
      cloud.detach_disk(@instance.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

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

#descriptionObject



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

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

#disk_mounted?Boolean

Returns:

  • (Boolean)


87
88
89
90
91
92
# File 'lib/bosh/director/problem_handlers/inactive_disk.rb', line 87

def disk_mounted?
  return false unless @instance.vm_cid
  agent_timeout_guard(@instance.vm_cid, @instance.credentials, @instance.agent_id) do |agent|
    agent.list_disk.include?(@disk.disk_cid)
  end
end