Class: Hugo::Aws::Rds
- Inherits:
-
Object
- Object
- Hugo::Aws::Rds
- Defined in:
- lib/hugo/aws/rds.rb
Constant Summary collapse
- ACCESS_KEY =
ENV['AMAZON_ACCESS_KEY_ID']
- SECRET_KEY =
ENV['AMAZON_SECRET_ACCESS_KEY']
- DEFAULT_SIZE =
5
- INSTANCE_CLASS =
"db.m1.small"
- ZONE =
"us-east-1c"
Instance Attribute Summary collapse
-
#aws_access_key_id ⇒ Object
Returns the value of attribute aws_access_key_id.
-
#aws_secret_access_key ⇒ Object
Returns the value of attribute aws_secret_access_key.
-
#create_time ⇒ Object
Returns the value of attribute create_time.
-
#db ⇒ Object
Returns the value of attribute db.
-
#db_security_group ⇒ Object
Returns the value of attribute db_security_group.
-
#instance_class ⇒ Object
Returns the value of attribute instance_class.
-
#password ⇒ Object
Returns the value of attribute password.
-
#server ⇒ Object
Returns the value of attribute server.
-
#size ⇒ Object
Returns the value of attribute size.
-
#status ⇒ Object
Returns the value of attribute status.
-
#uri ⇒ Object
Returns the value of attribute uri.
-
#user ⇒ Object
Returns the value of attribute user.
-
#zone ⇒ Object
Returns the value of attribute zone.
Class Method Summary collapse
- .all(aws_access_key_id, aws_secret_access_key) ⇒ Object
- .find(instance, aws_access_key_id, aws_secret_access_key) ⇒ Object
- .find_or_create(options) ⇒ Object
Instance Method Summary collapse
- #authorize_security_group(db_sec, ec2_sec, owner_id) ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #destroy_db_security_group(name) ⇒ Object
- #find_or_create_db_security_group(name, description) ⇒ Object
-
#initialize(options = {}) ⇒ Rds
constructor
A new instance of Rds.
- #save ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Rds
Returns a new instance of Rds.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/hugo/aws/rds.rb', line 17 def initialize(={}) # create instance @server = [:server] || ["DBInstanceIdentifier"] @db = [:name] #|| options["DBName"] @user = [:user] || ["MasterUsername"] @password = [:password] if [:password] @size = [:size] || ["AllocatedStorage"] || DEFAULT_SIZE @instance_class = [:instance_class] || ["DBInstanceClass"] || INSTANCE_CLASS @zone = [:zone] || ["AvailabilityZone"] || ZONE @status = ["DBInstanceStatus"] || "pending" @create_time = ["InstanceCreateTime"] || nil if ["Endpoint"] and ["Endpoint"]["Address"] @uri = ["Endpoint"]["Address"] || nil end @db_security_group = [:db_security_group] || "default" if ["DBSecurityGroups"] and ["DBSecurityGroups"]["DBSecurityGroup"] @db_security_group = ["DBSecurityGroups"]["DBSecurityGroup"]["DBSecurityGroupName"] end @aws_access_key_id = [:aws_access_key_id] || ACCESS_KEY @aws_secret_access_key = [:aws_secret_access_key] || SECRET_KEY end |
Instance Attribute Details
#aws_access_key_id ⇒ Object
Returns the value of attribute aws_access_key_id.
11 12 13 |
# File 'lib/hugo/aws/rds.rb', line 11 def aws_access_key_id @aws_access_key_id end |
#aws_secret_access_key ⇒ Object
Returns the value of attribute aws_secret_access_key.
11 12 13 |
# File 'lib/hugo/aws/rds.rb', line 11 def aws_secret_access_key @aws_secret_access_key end |
#create_time ⇒ Object
Returns the value of attribute create_time.
11 12 13 |
# File 'lib/hugo/aws/rds.rb', line 11 def create_time @create_time end |
#db ⇒ Object
Returns the value of attribute db.
11 12 13 |
# File 'lib/hugo/aws/rds.rb', line 11 def db @db end |
#db_security_group ⇒ Object
Returns the value of attribute db_security_group.
11 12 13 |
# File 'lib/hugo/aws/rds.rb', line 11 def db_security_group @db_security_group end |
#instance_class ⇒ Object
Returns the value of attribute instance_class.
11 12 13 |
# File 'lib/hugo/aws/rds.rb', line 11 def instance_class @instance_class end |
#password ⇒ Object
Returns the value of attribute password.
11 12 13 |
# File 'lib/hugo/aws/rds.rb', line 11 def password @password end |
#server ⇒ Object
Returns the value of attribute server.
11 12 13 |
# File 'lib/hugo/aws/rds.rb', line 11 def server @server end |
#size ⇒ Object
Returns the value of attribute size.
11 12 13 |
# File 'lib/hugo/aws/rds.rb', line 11 def size @size end |
#status ⇒ Object
Returns the value of attribute status.
11 12 13 |
# File 'lib/hugo/aws/rds.rb', line 11 def status @status end |
#uri ⇒ Object
Returns the value of attribute uri.
11 12 13 |
# File 'lib/hugo/aws/rds.rb', line 11 def uri @uri end |
#user ⇒ Object
Returns the value of attribute user.
11 12 13 |
# File 'lib/hugo/aws/rds.rb', line 11 def user @user end |
#zone ⇒ Object
Returns the value of attribute zone.
11 12 13 |
# File 'lib/hugo/aws/rds.rb', line 11 def zone @zone end |
Class Method Details
.all(aws_access_key_id, aws_secret_access_key) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/hugo/aws/rds.rb', line 65 def self.all(aws_access_key_id, aws_secret_access_key) @rds = AWS::RDS::Base.new(:access_key_id => aws_access_key_id, :secret_access_key => aws_secret_access_key) instances = @rds.describe_db_instances.DescribeDBInstancesResult.DBInstances.DBInstance if instances.kind_of?(Array) #instances.map { |i| self.get_from_aws(i) } instances.map { |i| self.new(i) } else #self.get_from_aws(instances) [ self.new(instances) ] end end |
.find(instance, aws_access_key_id, aws_secret_access_key) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/hugo/aws/rds.rb', line 78 def self.find(instance, aws_access_key_id, aws_secret_access_key) # find instance @rds = AWS::RDS::Base.new(:access_key_id => aws_access_key_id, :secret_access_key => aws_secret_access_key) @rds_instance = @rds.describe_db_instances(:db_instance_identifier => instance) instance_desc = @rds_instance.DescribeDBInstancesResult.DBInstances.DBInstance # initialize Hugo::Rds Object with instance hash self.new(instance_desc) rescue # AWS Can't find db instance called ???? nil end |
.find_or_create(options) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/hugo/aws/rds.rb', line 90 def self.find_or_create() rds = self.find([:server], [:aws_access_key_id], [:aws_secret_access_key]) || self.new().create rds.db = [:name] rds.password = [:password] rds end |
Instance Method Details
#authorize_security_group(db_sec, ec2_sec, owner_id) ⇒ Object
97 98 99 100 |
# File 'lib/hugo/aws/rds.rb', line 97 def (db_sec, ec2_sec, owner_id) #@rds = AWS::RDS::Base.new(:access_key_id => ACCESS_KEY, :secret_access_key => SECRET_KEY) rds.(:db_security_group_name => db_sec, :ec2_security_group_name => ec2_sec, :ec2_security_group_owner_id => owner_id) end |
#create ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/hugo/aws/rds.rb', line 41 def create rds.create_db_instance( :db_instance_identifier => self.server, :allocated_storage => self.size, :db_instance_class => self.instance_class, :engine => "MySQL5.1", :master_username => self.user, :master_user_password => self.password, :db_name => self.db, :availability_zone => self.zone #, :db_security_groups => @db_security_group ) unless self.create_time self end |
#destroy ⇒ Object
61 62 63 |
# File 'lib/hugo/aws/rds.rb', line 61 def destroy rds.delete_db_instance(:db_instance_identifier => self.server, :skip_final_snapshot => true) end |
#destroy_db_security_group(name) ⇒ Object
113 114 115 |
# File 'lib/hugo/aws/rds.rb', line 113 def destroy_db_security_group(name) rds.delete_db_security_group(:db_security_group_name => name) end |
#find_or_create_db_security_group(name, description) ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/hugo/aws/rds.rb', line 102 def find_or_create_db_security_group(name, description) #@rds = AWS::RDS::Base.new(:access_key_id => ACCESS_KEY, :secret_access_key => SECRET_KEY) begin @security_groups = rds.describe_db_security_groups(:db_security_group_name => name) rescue @security_groups = rds.create_db_security_group(:db_security_group_name => name, :db_security_group_description => description) end #puts @security_groups @security_groups end |
#save ⇒ Object
57 58 59 |
# File 'lib/hugo/aws/rds.rb', line 57 def save create end |