Class: PrettyAws::RdsInstance
- Inherits:
-
Object
- Object
- PrettyAws::RdsInstance
- Defined in:
- lib/pretty_aws/rds_instance.rb
Constant Summary collapse
- INSTANCE_CLASSES =
[ 'db.m1.small', 'db.m1.large', 'db.m1.xlarge', 'db.m2.2xlarge', 'db.m2.4xlarge' ]
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
- .all ⇒ Object
- .create(params = {}) ⇒ Object
- .delete(name) ⇒ Object
- .find(name) ⇒ Object
- .wait_until(name, state) ⇒ Object
Instance Method Summary collapse
- #[](name) ⇒ Object
- #address ⇒ Object
- #backup_period ⇒ Object
- #backup_window ⇒ Object
- #cpu_size ⇒ Object
- #created_at ⇒ Object
- #engine ⇒ Object
- #has_key?(name) ⇒ Boolean
-
#initialize(params) ⇒ RdsInstance
constructor
A new instance of RdsInstance.
- #mod_window ⇒ Object
- #name ⇒ Object
- #restorable_at ⇒ Object
- #security_groups ⇒ Object
- #status ⇒ Object
- #storage ⇒ Object
- #username ⇒ Object
- #zone ⇒ Object
Constructor Details
#initialize(params) ⇒ RdsInstance
Returns a new instance of RdsInstance.
60 61 62 |
# File 'lib/pretty_aws/rds_instance.rb', line 60 def initialize(params) @params=params end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
58 59 60 |
# File 'lib/pretty_aws/rds_instance.rb', line 58 def params @params end |
Class Method Details
.all ⇒ Object
16 17 18 |
# File 'lib/pretty_aws/rds_instance.rb', line 16 def self.all Base.rds.describe_db_instances.collect { |params| new(params) } end |
.create(params = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/pretty_aws/rds_instance.rb', line 40 def self.create(params={}) required_params = [ :name, :instance_class, :storage, :username, :password ] required_params.each { |key| raise "#{key} required" unless params.has_key?(key) } Base.rds.create_db_instance( params[:name], params[:instance_class], params[:storage], params[:username], params[:password], :availability_zone => 'us-east-1a' ) RdsInstance.wait_until(params[:name], 'available') end |
.delete(name) ⇒ Object
54 55 56 |
# File 'lib/pretty_aws/rds_instance.rb', line 54 def self.delete(name) Base.rds.delete_db_instance(name) end |
.find(name) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/pretty_aws/rds_instance.rb', line 8 def self.find(name) params = Base.rds.describe_db_instances.detect { |params| params[:db_instance_identifier]==name } if params.nil? raise PrettyAws::NotFound end new(params) end |
.wait_until(name, state) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/pretty_aws/rds_instance.rb', line 20 def self.wait_until(name, state) $stdout.printf("%-8s %-25s", "-----|"," waiting for #{name} to be #{state} ") while true begin item = find(name) rescue item = {:db_instance_status => nil} end if item[:db_instance_status]==state $stdout.puts("done") $stdout.flush return true else $stdout.print('.') $stdout.flush sleep(3) end end end |
Instance Method Details
#[](name) ⇒ Object
128 129 130 |
# File 'lib/pretty_aws/rds_instance.rb', line 128 def [](name) @params[name] end |
#address ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/pretty_aws/rds_instance.rb', line 72 def address if @params.has_key?(:endpoint) and @params[:endpoint].is_a?(Hash) and @params[:endpoint].has_key?(:address) @address = @params[:endpoint][:address] else @address = nil end @address end |
#backup_period ⇒ Object
116 117 118 |
# File 'lib/pretty_aws/rds_instance.rb', line 116 def backup_period @params[:backup_retention_period] end |
#backup_window ⇒ Object
120 121 122 |
# File 'lib/pretty_aws/rds_instance.rb', line 120 def backup_window @params[:preferred_backup_window] end |
#cpu_size ⇒ Object
81 82 83 |
# File 'lib/pretty_aws/rds_instance.rb', line 81 def cpu_size @params[:db_instance_class] end |
#created_at ⇒ Object
108 109 110 |
# File 'lib/pretty_aws/rds_instance.rb', line 108 def created_at @params[:instance_create_time] end |
#engine ⇒ Object
97 98 99 |
# File 'lib/pretty_aws/rds_instance.rb', line 97 def engine @params[:engine] end |
#has_key?(name) ⇒ Boolean
132 133 134 |
# File 'lib/pretty_aws/rds_instance.rb', line 132 def has_key?(name) @params.has_key?(name) end |
#mod_window ⇒ Object
124 125 126 |
# File 'lib/pretty_aws/rds_instance.rb', line 124 def mod_window @params[:preferred_maintenance_window] end |
#name ⇒ Object
64 65 66 |
# File 'lib/pretty_aws/rds_instance.rb', line 64 def name @params[:db_instance_identifier] end |
#restorable_at ⇒ Object
112 113 114 |
# File 'lib/pretty_aws/rds_instance.rb', line 112 def restorable_at @params[:latest_restorable_time] end |
#security_groups ⇒ Object
101 102 103 104 105 106 |
# File 'lib/pretty_aws/rds_instance.rb', line 101 def security_groups security_groups = [ ] item[:db_security_groups].each do |group| p('', '', group[:db_security_group_name], group[:status]) end end |
#status ⇒ Object
68 69 70 |
# File 'lib/pretty_aws/rds_instance.rb', line 68 def status @params[:db_instance_status] end |
#storage ⇒ Object
85 86 87 |
# File 'lib/pretty_aws/rds_instance.rb', line 85 def storage @params[:allocated_storage] end |
#username ⇒ Object
93 94 95 |
# File 'lib/pretty_aws/rds_instance.rb', line 93 def username @params[:master_username] end |
#zone ⇒ Object
89 90 91 |
# File 'lib/pretty_aws/rds_instance.rb', line 89 def zone @params[:availability_zone] end |