Class: Cloud

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

Overview

require ‘opensrs’

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#account_nameObject (readonly)

Returns the value of attribute account_name.



5
6
7
# File 'lib/dew/cloud.rb', line 5

def 
  @account_name
end

#profile_nameObject (readonly)

Returns the value of attribute profile_name.



5
6
7
# File 'lib/dew/cloud.rb', line 5

def profile_name
  @profile_name
end

#regionObject (readonly)

Returns the value of attribute region.



5
6
7
# File 'lib/dew/cloud.rb', line 5

def region
  @region
end

Class Method Details

.connect(region, account_name, profile_name = nil) ⇒ Object



9
10
11
12
# File 'lib/dew/cloud.rb', line 9

def connect region, , profile_name = nil
  @connection = new(region, , profile_name)
  Inform.info("Connected to AWS in %{region} using account %{account_name}", :region => region, :account_name => )
end

.method_missing(method, *args) ⇒ Object



14
15
16
# File 'lib/dew/cloud.rb', line 14

def method_missing method, *args
  @connection.send(method, *args)
end

Instance Method Details

#accountObject



20
21
22
# File 'lib/dew/cloud.rb', line 20

def 
  @account ||= Account.read()
end

#computeObject



24
25
26
# File 'lib/dew/cloud.rb', line 24

def compute
  @compute ||= Fog::Compute.new(fog_credentials.merge({:provider => 'AWS'}))
end

#dnsObject



74
75
76
# File 'lib/dew/cloud.rb', line 74

def dns
  # @dns ||= OpenSRS::Server.new(account.opensrs_credentials)
end

#elbObject



40
41
42
# File 'lib/dew/cloud.rb', line 40

def elb
  @elb ||= Fog::AWS::ELB.new(fog_credentials)
end

#has_dns?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/dew/cloud.rb', line 70

def has_dns?
  .has_dns?
end

#keyfile_path(key_name) ⇒ Object



65
66
67
68
# File 'lib/dew/cloud.rb', line 65

def keyfile_path(key_name)
   = File.join(ENV['HOME'], '.dew','accounts')
  File.join(, 'keys', , region, "#{key_name}.pem")
end

#keypair_exists?(keypair) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/dew/cloud.rb', line 36

def keypair_exists? keypair
  !!compute.key_pairs.get(keypair)
end

#profileObject



59
60
61
62
63
# File 'lib/dew/cloud.rb', line 59

def profile
  if profile_name
    @profile ||= Profile.read(profile_name)
  end
end

#rdsObject



44
45
46
# File 'lib/dew/cloud.rb', line 44

def rds
  @rds ||= Fog::AWS::RDS.new(fog_credentials)
end

#rds_authorized_ec2_owner_idsObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/dew/cloud.rb', line 48

def rds_authorized_ec2_owner_ids
  # XXX - Does this belong in Fog::AWS::RDS ?
  @rds_authorized_ec2_owner_ids ||= rds.security_groups.detect { |security_group|
    security_group.id == 'default'
  }.ec2_security_groups.select { |ec2_security_group|
    ec2_security_group["EC2SecurityGroupName"] == "default" && ec2_security_group["Status"] == "authorized"
  }.collect { |h|
    h["EC2SecurityGroupOwnerId"]
  }
end

#security_groupsObject



28
29
30
# File 'lib/dew/cloud.rb', line 28

def security_groups
  @security_groups ||= compute.security_groups.inject({}) { |h, g| h[g.name] = g; h }
end

#valid_serversObject



32
33
34
# File 'lib/dew/cloud.rb', line 32

def valid_servers
  @valid_servers ||= Cloud.compute.servers.select{ |s| %w{running pending}.include?(s.state) }
end