class Awssh::Cloud

Public Class Methods

connect(key, secret, region) click to toggle source
# File lib/awssh/cloud.rb, line 4
def connect(key, secret, region)
  @instance = new(key, secret, region)
end
instance() click to toggle source
# File lib/awssh/cloud.rb, line 8
def instance
  raise "not connected?" unless @instance
  @instance
end
new(key, secret, region) click to toggle source
# File lib/awssh/cloud.rb, line 14
def initialize(key, secret, region)
  @key = key
  @secret = secret
  @region = region
end

Public Instance Methods

servers() click to toggle source
# File lib/awssh/cloud.rb, line 20
def servers
  puts "requesting servers..."
  Aws.config.update({region: @region, credentials: Aws::Credentials.new(@key, @secret)})
  aws = Aws::EC2::Resource.new
  aws.instances(filters:[{name: 'instance-state-name', values: ['running']}]).inject([]) do |a, instance|
    tags = tags(instance)
    a << {
        id: instance.id,
        name: tags['name'] || instance.id,
        tags: tags,
        private: instance.private_ip_address,
        public: instance.public_ip_address,
    }
  end
end

Private Instance Methods

tags(instance) click to toggle source
# File lib/awssh/cloud.rb, line 38
def tags(instance)
  instance.tags.inject({}) {|h, e| h[e.key.downcase]=e.value.downcase; h}
end