Module: Bosh::Director::CloudcheckHelper
- Included in:
- ProblemHandlers::Base
- Defined in:
- lib/bosh/director/cloudcheck_helper.rb
Constant Summary collapse
- DEFAULT_AGENT_TIMEOUT =
This timeout has been made pretty short mainly to avoid long cloudchecks, however 10 seconds should still be pretty generous interval for agent to respond.
10
Instance Method Summary collapse
- #delete_vm(instance) ⇒ Object
- #delete_vm_reference(instance) ⇒ Object
- #reboot_vm(instance) ⇒ Object
- #recreate_vm(instance_model) ⇒ Object
Instance Method Details
#delete_vm(instance) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/bosh/director/cloudcheck_helper.rb', line 27 def delete_vm(instance) # Paranoia: don't blindly delete VMs with persistent disk disk_list = agent_timeout_guard(instance.vm_cid, instance.credentials, instance.agent_id) { |agent| agent.list_disk } if disk_list.size != 0 handler_error('VM has persistent disk attached') end vm_deleter.delete_for_instance(instance) end |
#delete_vm_reference(instance) ⇒ Object
37 38 39 |
# File 'lib/bosh/director/cloudcheck_helper.rb', line 37 def delete_vm_reference(instance) instance.update(vm_cid: nil, agent_id: nil, trusted_certs_sha1: nil, credentials: nil) end |
#reboot_vm(instance) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/bosh/director/cloudcheck_helper.rb', line 16 def reboot_vm(instance) cloud.reboot_vm(instance.vm_cid) begin agent_client(instance.credentials, instance.agent_id).wait_until_ready rescue Bosh::Director::RpcTimeout handler_error('Agent still unresponsive after reboot') rescue Bosh::Director::TaskCancelled handler_error('Task was cancelled') end end |
#recreate_vm(instance_model) ⇒ Object
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 91 92 93 94 95 96 |
# File 'lib/bosh/director/cloudcheck_helper.rb', line 41 def recreate_vm(instance_model) @logger.debug("Recreating Vm: #{instance_model})") existing_vm_env = instance_model.vm_env validate_spec(instance_model.spec) validate_env(instance_model.vm_env) begin vm_deleter.delete_for_instance(instance_model) rescue Bosh::Clouds::VMNotFound # One situation where this handler is actually useful is when # VM has already been deleted but something failed after that # and it is still referenced in DB. In that case it makes sense # to ignore "VM not found" errors in `delete_vm` and let the method # proceed creating a new VM. Other errors are not forgiven. @logger.warn("VM '#{instance_model.vm_cid}' might have already been deleted from the cloud") end instance_plan_to_create = create_instance_plan(instance_model, existing_vm_env) vm_creator.create_for_instance_plan( instance_plan_to_create, Array(instance_model.persistent_disk_cid) ) dns_manager = DnsManagerProvider.create dns_names_to_ip = {} apply_spec = instance_plan_to_create.existing_instance.spec apply_spec['networks'].each do |network_name, network| index_dns_name = dns_manager.dns_record_name(instance_model.index, instance_model.job, network_name, instance_model.deployment.name) dns_names_to_ip[index_dns_name] = network['ip'] id_dns_name = dns_manager.dns_record_name(instance_model.uuid, instance_model.job, network_name, instance_model.deployment.name) dns_names_to_ip[id_dns_name] = network['ip'] end @logger.debug("Updating DNS record for instance: #{instance_model.inspect}; to: #{dns_names_to_ip.inspect}") dns_manager.update_dns_record_for_instance(instance_model, dns_names_to_ip) dns_manager.flush_dns_cache InstanceUpdater::InstanceState.with_instance_update(instance_model) do cleaner = RenderedJobTemplatesCleaner.new(instance_model, App.instance.blobstores.blobstore, @logger) # for backwards compatibility with instances that don't have update config update_config = apply_spec['update'].nil? ? nil : DeploymentPlan::UpdateConfig.new(apply_spec['update']) InstanceUpdater::StateApplier.new( instance_plan_to_create, agent_client(instance_model.credentials, instance_model.agent_id), cleaner, @logger, {} ).apply(update_config) end end |