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_vm(vm) ⇒ Object
Methods inherited from BaseJob
#begin_stage, #event_log, #logger, perform, #result_file, #single_step_stage, #task_cancelled?, #task_checkpoint, #track_and_log
Constructor Details
#initialize(deployment_id, format) ⇒ VmState
Returns a new instance of VmState.
15 16 17 18 |
# File 'lib/bosh/director/jobs/vm_state.rb', line 15 def initialize(deployment_id, format) @deployment_id = deployment_id @format = format end |
Class Method Details
.job_type ⇒ Object
10 11 12 |
# File 'lib/bosh/director/jobs/vm_state.rb', line 10 def self.job_type :vms end |
Instance Method Details
#perform ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bosh/director/jobs/vm_state.rb', line 20 def perform @domain = Models::Dns::Domain.find(name: Config.dns_domain_name, type: "NATIVE") if Config.dns_enabled? vms = Models::Vm.filter(:deployment_id => @deployment_id) ThreadPool.new(:max_threads => Config.max_threads).wrap do |pool| vms.each do |vm| pool.process do vm_state = process_vm(vm) result_file.write(vm_state.to_json + "\n") end end end # task result nil end |
#process_vm(vm) ⇒ Object
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 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/bosh/director/jobs/vm_state.rb', line 37 def process_vm(vm) ips = [] dns_records = [] job_name = nil job_state = nil resource_pool = nil job_vitals = nil job_index = nil processes = [] begin agent = AgentClient.with_vm(vm, :timeout => TIMEOUT) agent_state = agent.get_state(@format) agent_state["networks"].each_value do |network| ips << network["ip"] end job_index = get_index(agent_state) job_name = agent_state["job"]["name"] if agent_state["job"] job_state = agent_state["job_state"] if agent_state["resource_pool"] resource_pool = agent_state["resource_pool"]["name"] end 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 @domain ips.each do |ip| records = Models::Dns::Record.filter(domain_id: @domain.id, type: "A", content: ip) dns_records << records.collect { |record| record.name } unless records.empty? end end { :vm_cid => vm.cid, :disk_cid => vm.instance ? vm.instance.persistent_disk_cid : nil, :ips => ips, :dns => dns_records.flatten, :agent_id => vm.agent_id, :job_name => job_name, :index => job_index, :job_state => job_state, :resource_pool => resource_pool, :vitals => job_vitals, :processes => processes, :resurrection_paused => vm.instance ? vm.instance.resurrection_paused : nil, } end |