Sha256: c57b92f6448ee5a9b44140523cd8fe6b64e1c9e7b87ef7e251553545db880d09

Contents?: true

Size: 1002 Bytes

Versions: 8

Compression:

Stored size: 1002 Bytes

Contents

require 'fog'

module Mulder
  class Connection

    attr_reader :config

    def initialize(config)
      @config = config
    end

    def group_by_id_regexp(id_regexp)
      autoscaler.groups.find_all do |group|
        group.id =~ id_regexp
      end.last
    end

    def instances_by_group(group)
      group.instances.collect do |instance|
        compute_instance = server_by_instance_id(instance.id)
        Mulder::Instance.new(compute_instance)
      end
    rescue
      []
    end

    def server_by_instance_id(instance_id)
      compute.servers.get(instance_id)
    end

    def autoscaler
      @autoscaler ||= ::Fog::AWS::AutoScaling.new(
        :aws_access_key_id => @config.aws_access_key_id,
        :aws_secret_access_key => @config.aws_secret_access_key
      )
    end

    def compute
      @compute ||= ::Fog::Compute::AWS.new(
        :aws_access_key_id => @config.aws_access_key_id,
        :aws_secret_access_key => @config.aws_secret_access_key
      )
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mulder-0.4.0 lib/mulder/connection.rb
mulder-0.3.2 lib/mulder/connection.rb
mulder-0.3.1 lib/mulder/connection.rb
mulder-0.3.0 lib/mulder/connection.rb
mulder-0.2.1 lib/mulder/connection.rb
mulder-0.2.0 lib/mulder/connection.rb
mulder-0.1.0 lib/mulder/connection.rb
mulder-0.0.5 lib/mulder/connection.rb