class Bosh::AwsCloud::Instance
Public Class Methods
new(aws_instance, registry, elb, logger)
click to toggle source
# File lib/cloud/aws/instance.rb, line 3 def initialize(aws_instance, registry, elb, logger) @aws_instance = aws_instance @registry = registry @elb = elb @logger = logger end
Public Instance Methods
associate_elastic_ip(elastic_ip)
click to toggle source
# File lib/cloud/aws/instance.rb, line 18 def associate_elastic_ip(elastic_ip) @aws_instance.associate_elastic_ip(elastic_ip) end
attach_to_load_balancers(load_balancer_ids)
click to toggle source
# File lib/cloud/aws/instance.rb, line 83 def attach_to_load_balancers(load_balancer_ids) load_balancer_ids.each do |load_balancer_id| lb = @elb.load_balancers[load_balancer_id] lb.instances.register(@aws_instance) end end
disassociate_elastic_ip()
click to toggle source
# File lib/cloud/aws/instance.rb, line 22 def disassociate_elastic_ip @aws_instance.disassociate_elastic_ip end
elastic_ip()
click to toggle source
# File lib/cloud/aws/instance.rb, line 14 def elastic_ip @aws_instance.elastic_ip end
exists?()
click to toggle source
Determines if the instance exists.
# File lib/cloud/aws/instance.rb, line 79 def exists? @aws_instance.exists? && @aws_instance.status != :terminated end
id()
click to toggle source
# File lib/cloud/aws/instance.rb, line 10 def id @aws_instance.id end
reboot()
click to toggle source
Soft reboots EC2 instance
# File lib/cloud/aws/instance.rb, line 40 def reboot # There is no trackable status change for the instance being # rebooted, so it's up to CPI client to keep track of agent # being ready after reboot. # Due to this, we can't deregister the instance from any load # balancers it might be attached to, and reattach once the # reboot is complete, so we just have to let the load balancers # take the instance out of rotation, and put it back in once it # is back up again. @aws_instance.reboot end
terminate(fast=false)
click to toggle source
# File lib/cloud/aws/instance.rb, line 52 def terminate(fast=false) begin @aws_instance.terminate rescue AWS::EC2::Errors::InvalidInstanceID::NotFound => e @logger.warn("Failed to terminate instance '#{@aws_instance.id}' because it was not found: #{e.inspect}") raise Bosh::Clouds::VMNotFound, "VM `#{@aws_instance.id}' not found" ensure @logger.info("Deleting instance settings for '#{@aws_instance.id}'") @registry.delete_settings(@aws_instance.id) end if fast TagManager.tag(@aws_instance, "Name", "to be deleted") @logger.info("Instance #{@aws_instance.id} marked to deletion") return end begin @logger.info("Deleting instance '#{@aws_instance.id}'") ResourceWait.for_instance(instance: @aws_instance, state: :terminated) rescue AWS::EC2::Errors::InvalidInstanceID::NotFound => e @logger.debug("Failed to find terminated instance '#{@aws_instance.id}' after deletion: #{e.inspect}") # It's OK, just means that instance has already been deleted end end
wait_for_running()
click to toggle source
# File lib/cloud/aws/instance.rb, line 26 def wait_for_running # If we time out, it is because the instance never gets from state running to started, # so we signal the director that it is ok to retry the operation. At the moment this # forever (until the operation is cancelled by the user). begin @logger.info("Waiting for instance to be ready...") ResourceWait.for_instance(instance: @aws_instance, state: :running) rescue Bosh::Common::RetryCountExceeded @logger.warn("Timed out waiting for instance '#{aws_instance.id}' to be running") raise Bosh::Clouds::VMCreationFailed.new(true) end end