2011-02-27 16:09:12 -05:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class RDS
|
|
|
|
|
|
|
|
class Server < Fog::Model
|
|
|
|
|
|
|
|
identity :id, :aliases => 'DBInstanceIdentifier'
|
|
|
|
attribute :engine, :aliases => 'Engine'
|
|
|
|
attribute :engine_version, :aliases => 'EngineVersion'
|
|
|
|
attribute :state, :aliases => 'DBInstanceStatus'
|
|
|
|
attribute :allocated_storage, :aliases => 'AllocatedStorage', :type => :integer
|
|
|
|
attribute :availability_zone , :aliases => 'AvailabilityZone'
|
|
|
|
attribute :flavor_id, :aliases => 'DBInstanceClass'
|
|
|
|
attribute :endpoint, :aliases => 'Endpoint'
|
|
|
|
attribute :read_replica_source, :aliases => 'ReadReplicaSourceDBInstanceIdentifier'
|
|
|
|
attribute :read_replica_identifiers, :aliases => 'ReadReplicaDBInstanceIdentifiers', :type => :array
|
|
|
|
attribute :master_username, :aliases => 'MasterUsername'
|
|
|
|
attribute :multi_az, :aliases => 'MultiAZ'
|
|
|
|
attribute :created_at, :aliases => 'InstanceCreateTime', :type => :time
|
|
|
|
attribute :last_restorable_time, :aliases => 'LatestRestorableTime', :type => :time
|
|
|
|
attribute :auto_minor_version_upgrade, :aliases => 'AutoMinorVersionUpgrade'
|
|
|
|
attribute :pending_modified_values, :aliases => 'PendingModifiedValues'
|
|
|
|
attribute :preferred_backup_window, :aliases => 'PreferredBackupWindow'
|
|
|
|
attribute :preferred_maintenance_window, :aliases => 'PreferredMaintenanceWindow'
|
|
|
|
attribute :db_name, :aliases => 'DBName'
|
2011-07-30 23:11:36 -04:00
|
|
|
attribute :db_security_groups, :aliases => 'DBSecurityGroups', :type => :array
|
2011-02-27 16:09:12 -05:00
|
|
|
attribute :db_parameter_groups, :aliases => 'DBParameterGroups'
|
|
|
|
attribute :backup_retention_period, :aliases => 'BackupRetentionPeriod', :type => :integer
|
2011-07-12 16:03:04 -04:00
|
|
|
attribute :license_model, :aliases => 'LicenseModel'
|
2011-02-27 16:09:12 -05:00
|
|
|
|
|
|
|
attr_accessor :password, :parameter_group_name, :security_group_names, :port
|
|
|
|
|
|
|
|
def create_read_replica(replica_id, options={})
|
2011-07-30 23:11:36 -04:00
|
|
|
options[:security_group_names] ||= options['DBSecurityGroups']
|
|
|
|
params = self.class.new(options).attributes_to_params
|
|
|
|
connection.create_db_instance_read_replica(replica_id, id, params)
|
2011-02-27 16:09:12 -05:00
|
|
|
connection.servers.get(replica_id)
|
|
|
|
end
|
2011-07-30 23:11:36 -04:00
|
|
|
|
2011-02-27 16:09:12 -05:00
|
|
|
def ready?
|
|
|
|
state == 'available'
|
|
|
|
end
|
2011-07-30 23:11:36 -04:00
|
|
|
|
2011-05-31 23:25:00 -04:00
|
|
|
def destroy(snapshot_identifier=nil)
|
2011-02-27 16:09:12 -05:00
|
|
|
requires :id
|
|
|
|
connection.delete_db_instance(id, snapshot_identifier, snapshot_identifier.nil?)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def reboot
|
|
|
|
connection.reboot_db_instance(id)
|
|
|
|
true
|
|
|
|
end
|
2011-07-30 23:11:36 -04:00
|
|
|
|
2011-02-27 16:09:12 -05:00
|
|
|
def snapshots
|
|
|
|
requires :id
|
|
|
|
connection.snapshots(:server => self)
|
|
|
|
end
|
2011-07-30 23:11:36 -04:00
|
|
|
|
2011-02-27 16:09:12 -05:00
|
|
|
def modify(immediately, options)
|
2011-07-30 23:11:36 -04:00
|
|
|
options[:security_group_names] ||= options['DBSecurityGroups']
|
|
|
|
params = self.class.new(options).attributes_to_params
|
|
|
|
data = connection.modify_db_instance(id, immediately, params)
|
2011-02-27 16:09:12 -05:00
|
|
|
merge_attributes(data.body['ModifyDBInstanceResult']['DBInstance'])
|
2011-07-30 23:11:36 -04:00
|
|
|
true
|
2011-02-27 16:09:12 -05:00
|
|
|
end
|
2011-07-30 23:11:36 -04:00
|
|
|
|
2011-02-27 16:09:12 -05:00
|
|
|
def save
|
|
|
|
requires :engine
|
|
|
|
requires :allocated_storage
|
|
|
|
requires :master_username
|
|
|
|
requires :password
|
2011-07-30 23:11:36 -04:00
|
|
|
|
|
|
|
self.flavor_id ||= 'db.m1.small'
|
|
|
|
|
|
|
|
data = connection.create_db_instance(id, attributes_to_params)
|
|
|
|
merge_attributes(data.body['CreateDBInstanceResult']['DBInstance'])
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
# Converts attributes to a parameter hash suitable for requests
|
|
|
|
def attributes_to_params
|
2011-02-27 16:09:12 -05:00
|
|
|
options = {
|
|
|
|
'AllocatedStorage' => allocated_storage,
|
|
|
|
'AutoMinorVersionUpgrade' => auto_minor_version_upgrade,
|
|
|
|
'BackupRetentionPeriod' => backup_retention_period,
|
|
|
|
'DBName' => db_name,
|
2011-07-30 23:11:36 -04:00
|
|
|
'DBParameterGroupName' => parameter_group_name || attributes['DBParameterGroupName'],
|
2011-02-27 16:09:12 -05:00
|
|
|
'DBSecurityGroups' => security_group_names,
|
|
|
|
'DBInstanceIdentifier' => id,
|
|
|
|
'AvailabilityZone' => availability_zone,
|
|
|
|
'DBInstanceClass' => flavor_id,
|
2011-07-30 23:11:36 -04:00
|
|
|
'Port' => port || attributes['Port'],
|
2011-02-27 16:09:12 -05:00
|
|
|
'Engine' => engine,
|
|
|
|
'EngineVersion' => engine_version,
|
|
|
|
'MasterUsername' => master_username,
|
2011-07-30 23:11:36 -04:00
|
|
|
'MasterUserPassword' => password || attributes['MasterUserPassword'],
|
2011-02-27 16:09:12 -05:00
|
|
|
'PreferredMaintenanceWindow' => preferred_maintenance_window,
|
|
|
|
'PreferredBackupWindow' => preferred_backup_window,
|
2011-07-12 16:03:04 -04:00
|
|
|
'MultiAZ' => multi_az,
|
|
|
|
'LicenseModel' => license_model
|
2011-02-27 16:09:12 -05:00
|
|
|
}
|
|
|
|
|
2011-07-30 23:11:36 -04:00
|
|
|
options.delete_if {|key, value| value.nil?}
|
2011-02-27 16:09:12 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-05-31 23:25:00 -04:00
|
|
|
end
|