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.



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

def initialize(key, secret, region)
  @key = key
  @secret = secret
  @region = region
  @fog = Fog::Compute.new(provider: 'AWS', aws_access_key_id: @key, aws_secret_access_key: @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



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

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
# File 'lib/awssh/cloud.rb', line 20

def servers
  puts "requesting servers..."
  list = @fog.servers.all({'instance-state-name' => 'running'})
  list.inject([]) do |a, e|
    a << {
      id: e.id,
      name: e.tags['Name']||e.id,
      tags: e.tags.inject({}) {|h, e| (k,v) = e; h[k.downcase] = (v ? v.downcase : ""); h},
      private: e.private_ip_address,
      public: e.public_ip_address,
    }
  end
end