Class: Bosh::Director::ProblemHandlers::OutOfSyncVm

Inherits:
Base
  • Object
show all
Defined in:
lib/bosh/director/problem_handlers/out_of_sync_vm.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(vm_id, data) ⇒ OutOfSyncVm

Returns a new instance of OutOfSyncVm.



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

def initialize(vm_id, data)
  super
  @vm = Models::Vm[vm_id]
  @data = data

  if @vm.nil?
    handler_error("VM `#{vm_id}' is no longer in the database")
  end

  @deployment = @vm.deployment
  @instance = @vm.instance

  if @deployment.nil?
    handler_error("VM `#{@vm.cid}' doesn't belong to any deployment")
  end

end

Instance Method Details

#descriptionObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/bosh/director/problem_handlers/out_of_sync_vm.rb', line 28

def description
  actual_deployment = @data["deployment"] || "unknown deployment"
  actual_job = @data["job"] || "unknown job"
  actual_index = @data["index"] || "unknown index"

  expected = "#{@deployment.name}: #{instance_name(@vm)}"
  actual = "#{actual_deployment}: #{actual_job}/#{actual_index}"

  "VM `#{@vm.cid}' is out of sync: expected `#{expected}', got `#{actual}'"
end

#validateObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/bosh/director/problem_handlers/out_of_sync_vm.rb', line 49

def validate
  state = agent_timeout_guard(@vm) { |agent | agent.get_state }
  return if state["deployment"] != @deployment.name

  # VM is no longer out of sync if no instance is referencing it,
  # as this situation can actually be handled by regular deployment
  if @instance.nil? ||
      state["job"] && state["job"]["name"] == @instance.job &&
      state["index"] == @instance.index
    handler_error("VM is now back in sync")
  end
end