Sha256: f98f1ebde342199f5e8ad8648ccf50f524e486f2bbcc8d22aeb1472750a22d4a

Contents?: true

Size: 1.98 KB

Versions: 13

Compression:

Stored size: 1.98 KB

Contents

module PoolParty  
  module Remote
    class Ec2RemoteInstance < RemoteInstance
      include Dslify
      
      attr_reader :my_cloud, :uniquely_identifiable_by, :found_at

      
      # A new instance will be created from the passed in hash.  
      # This hash of passed in values will be converted to methods on this instance.
      # The parent clouds describe_instances list will be searched for the first one matching any of this instance's provided unique identifiers.
      # If an instance is found, this instance's properties will be set to the properties provided
      # If the found instance has properties of the same key as the provided options, the found instance's values will override the passed in options
      def initialize(opts={}, prnt=Ec2.new)
        @uniquely_identifiable_by = [:ip, :name, :dns_name, :instance_id]
        @original_options = opts
        @my_cloud = prnt
        super(opts, prnt)
        find_myself(@uniquely_identifiable_by && opts.keys) if prnt.respond_to?(:describe_instances)
      end
   
      # Search the clouds describe_instances list for the first match on one of this nodes unique identifiers
      def find_myself(unique_identifiers = @original_options.keys)
        description_hash = @my_cloud.describe_instances.detect do|node|
          unique_identifiers.detect{|identifier_key| node[identifier_key] == options[identifier_key]
            }
        end
        return nil if description_hash.blank?
        @found_at = Time.now
        self.set_vars_from_options(description_hash)
        self
      end
      
      # Is this instance running?
      def running?
        !(status =~ /running/).nil?
      end
      # Is this instance pending?
      def pending?
        !(status =~ /pending/).nil?
      end
      # Is this instance terminating?
      def terminating?
        !(status =~ /shutting/).nil?
      end
      # Has this instance been terminated?
      def terminated?
        !(status =~ /terminated/).nil?
      end
      
    end
  end
end

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
auser-poolparty-1.1.1 lib/poolparty/net/remoter_bases/ec2/ec2_remote_instance.rb
auser-poolparty-1.1.3 lib/poolparty/net/remoter_bases/ec2/ec2_remote_instance.rb
auser-poolparty-1.1.4 lib/poolparty/net/remoter_bases/ec2/ec2_remote_instance.rb
auser-poolparty-1.1.5 lib/poolparty/net/remoter_bases/ec2/ec2_remote_instance.rb
auser-poolparty-1.1.6 lib/poolparty/net/remoter_bases/ec2/ec2_remote_instance.rb
auser-poolparty-1.1.7 lib/poolparty/net/remoter_bases/ec2/ec2_remote_instance.rb
auser-poolparty-1.2.0 lib/poolparty/net/remoter_bases/ec2/ec2_remote_instance.rb
auser-poolparty-1.2.1 lib/poolparty/net/remoter_bases/ec2/ec2_remote_instance.rb
auser-poolparty-1.2.2 lib/poolparty/net/remoter_bases/ec2/ec2_remote_instance.rb
fairchild-poolparty-1.1.3 lib/poolparty/net/remoter_bases/ec2/ec2_remote_instance.rb
fairchild-poolparty-1.1.4 lib/poolparty/net/remoter_bases/ec2/ec2_remote_instance.rb
fairchild-poolparty-1.1.5 lib/poolparty/net/remoter_bases/ec2/ec2_remote_instance.rb
poolparty-1.2.2 lib/poolparty/net/remoter_bases/ec2/ec2_remote_instance.rb