Class: Bosh::Director::ProblemHandlers::InactiveDisk
- Inherits:
-
Base
- Object
- Base
- Bosh::Director::ProblemHandlers::InactiveDisk
show all
- Defined in:
- lib/bosh/director/problem_handlers/inactive_disk.rb
Constant Summary
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
#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
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_disk ⇒ Object
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
if @instance.persistent_disk
handler_error("Instance already has an active disk")
end
@disk.active = true
@disk.save
end
|
#delete_disk ⇒ Object
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
@logger.warn(e)
end
end
begin
cloud.delete_disk(@disk.disk_cid)
rescue Bosh::Clouds::DiskNotFound, RuntimeError => e
@logger.warn(e)
end
@disk.destroy
end
|
#description ⇒ Object
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
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
true
end
end
|