Sha256: 7ca1e70dacfa63672c2044846092d314a1ee9509874ea7c933b5b8d2a2a1ce92

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

class Aerosol::Instance
  include Aerosol::AWSModel

  aws_attribute :availability_zone => 'AvailabilityZone',
                :health_status     => 'HealthStatus',
                :id                => 'InstanceId',
                :lifecycle_state   => 'LifecycleState'
  aws_class_attribute :launch_configuration, Aerosol::LaunchConfiguration
  primary_key :id

  def live?
    describe_again
    instance_state_name == 'running'
  end

  def instance_state_name
    description['instanceState']['name']
  end

  def public_hostname
    description['dnsName']
  end

  def private_ip_address
    description['privateIpAddress']
  end

  def ami
    description['imageId']
  end

  def description
    @description ||= describe!
  end

  def self.request_all
    Aerosol::AWS.auto_scaling
                .describe_auto_scaling_instances
                .body
                .[]('DescribeAutoScalingInstancesResult')
                .[]('AutoScalingInstances')
  end

private
  def describe!
    ensure_present! :id
    result = Aerosol::AWS.compute.describe_instances('instance-id' => id).body
    result['reservationSet'].first['instancesSet'].first rescue nil
  end

  def describe_again
    @description = nil
    description
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aerosol-0.5.1 lib/aerosol/instance.rb