Class: Awssh::Cloud

Inherits:
Object
  • Object
show all
Defined in:
lib/awssh/cloud.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, secret, region) ⇒ Cloud

Returns a new instance of Cloud.



14
15
16
17
18
# File 'lib/awssh/cloud.rb', line 14

def initialize(key, secret, region)
  @key = key
  @secret = secret
  @region = region
end

Class Method Details

.connect(key, secret, region) ⇒ Object



4
5
6
# File 'lib/awssh/cloud.rb', line 4

def connect(key, secret, region)
  @instance = new(key, secret, region)
end

.instanceObject



8
9
10
11
# File 'lib/awssh/cloud.rb', line 8

def instance
  raise "not connected?" unless @instance
  @instance
end

Instance Method Details

#serversObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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