Class: Bosh::Director::Jobs::VmState
- Defined in:
- lib/bosh/director/jobs/vm_state.rb
Constant Summary collapse
- TIMEOUT =
5
Instance Attribute Summary
Attributes inherited from BaseJob
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(deployment_id, format) ⇒ VmState
constructor
A new instance of VmState.
- #perform ⇒ Object
- #process_instance(instance) ⇒ Object
Methods inherited from BaseJob
#begin_stage, #dns_manager, #event_log, #logger, perform, #result_file, schedule_message, #single_step_stage, #task_cancelled?, #task_checkpoint, #track_and_log
Constructor Details
#initialize(deployment_id, format) ⇒ VmState
Returns a new instance of VmState.
12 13 14 15 |
# File 'lib/bosh/director/jobs/vm_state.rb', line 12 def initialize(deployment_id, format) @deployment_id = deployment_id @format = format end |
Class Method Details
.job_type ⇒ Object
8 9 10 |
# File 'lib/bosh/director/jobs/vm_state.rb', line 8 def self.job_type :vms end |
Instance Method Details
#perform ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bosh/director/jobs/vm_state.rb', line 17 def perform instances = Models::Instance.filter(:deployment_id => @deployment_id).exclude(vm_cid: nil) 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
32 33 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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/bosh/director/jobs/vm_state.rb', line 32 def process_instance(instance) ips = [] dns_records = [] job_state = nil job_vitals = nil processes = [] begin agent = AgentClient.with_vm_credentials_and_agent_id(instance.credentials, instance.agent_id, :timeout => TIMEOUT) agent_state = agent.get_state(@format) agent_state['networks'].each_value do |network| ips << network['ip'] end job_state = agent_state['job_state'] if agent_state['vitals'] job_vitals = agent_state['vitals'] end processes = agent_state['processes'] if agent_state['processes'] rescue Bosh::Director::RpcTimeout job_state = 'unresponsive agent' end 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 && instance.spec['vm_type'] ? instance.spec['vm_type']['name'] : nil { :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, :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 } end |