Class: Bosh::Director::Jobs::VmState

Inherits:
BaseJob show all
Defined in:
lib/bosh/director/jobs/vm_state.rb

Constant Summary collapse

TIMEOUT =
5

Instance Attribute Summary

Attributes inherited from BaseJob

#task_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseJob

#begin_stage, #dns_manager, #event_manager, #logger, perform, #result_file, schedule_message, #single_step_stage, #task_cancelled?, #task_checkpoint, #track_and_log, #username

Constructor Details

#initialize(deployment_id, format, state_for_missing_vms = false) ⇒ VmState

Returns a new instance of VmState.



12
13
14
15
16
# File 'lib/bosh/director/jobs/vm_state.rb', line 12

def initialize(deployment_id, format, state_for_missing_vms = false)
  @deployment_id = deployment_id
  @format = format
  @state_for_missing_vms = state_for_missing_vms
end

Class Method Details

.job_typeObject



8
9
10
# File 'lib/bosh/director/jobs/vm_state.rb', line 8

def self.job_type
  :vms
end

Instance Method Details

#performObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bosh/director/jobs/vm_state.rb', line 18

def perform
  instances = Models::Instance.filter(:deployment_id => @deployment_id)
  instances = instances.exclude(vm_cid: nil) unless @state_for_missing_vms
  ThreadPool.new(:max_threads => Config.max_threads).wrap do |pool|
    instances.each do |instance|
      pool.process do
        vm_state = process_instance(instance)
        result_file.write(vm_state.to_json + "\n")
      end
    end
  end

  # task result
  nil
end

#process_instance(instance) ⇒ Object



34
35
36
37
38
39
40
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
# File 'lib/bosh/director/jobs/vm_state.rb', line 34

def process_instance(instance)
  dns_records = []

  job_state, job_vitals, processes, ips = vm_details(instance)

  if dns_manager.dns_enabled?
    dns_records = dns_manager.find_dns_record_names_by_instance(instance)
    dns_records.sort_by! { |name| -(name.split('.').first.length) }
  end

  vm_type_name = instance.spec_p('vm_type.name')

  {
    :vm_cid => instance.vm_cid,
    :disk_cid => instance.persistent_disk_cid,
    :ips => ips,
    :dns => dns_records,
    :agent_id => instance.agent_id,
    :job_name => instance.job,
    :index => instance.index,
    :job_state => job_state,
    :state => instance.state,
    :resource_pool => vm_type_name,
    :vm_type => vm_type_name,
    :vitals => job_vitals,
    :processes => processes,
    :resurrection_paused => instance.resurrection_paused,
    :az => instance.availability_zone,
    :id => instance.uuid,
    :bootstrap => instance.bootstrap,
    :ignore => instance.ignore
  }
end