Class: PrettyAws::RdsInstance

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#paramsObject (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

.allObject



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

#addressObject



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_periodObject



116
117
118
# File 'lib/pretty_aws/rds_instance.rb', line 116

def backup_period
  @params[:backup_retention_period]
end

#backup_windowObject



120
121
122
# File 'lib/pretty_aws/rds_instance.rb', line 120

def backup_window
  @params[:preferred_backup_window]
end

#cpu_sizeObject



81
82
83
# File 'lib/pretty_aws/rds_instance.rb', line 81

def cpu_size
  @params[:db_instance_class]
end

#created_atObject



108
109
110
# File 'lib/pretty_aws/rds_instance.rb', line 108

def created_at
  @params[:instance_create_time]
end

#engineObject



97
98
99
# File 'lib/pretty_aws/rds_instance.rb', line 97

def engine
  @params[:engine]
end

#has_key?(name) ⇒ Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/pretty_aws/rds_instance.rb', line 132

def has_key?(name)
  @params.has_key?(name)
end

#mod_windowObject



124
125
126
# File 'lib/pretty_aws/rds_instance.rb', line 124

def mod_window
  @params[:preferred_maintenance_window]
end

#nameObject



64
65
66
# File 'lib/pretty_aws/rds_instance.rb', line 64

def name
  @params[:db_instance_identifier]
end

#restorable_atObject



112
113
114
# File 'lib/pretty_aws/rds_instance.rb', line 112

def restorable_at
  @params[:latest_restorable_time]
end

#security_groupsObject



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

#statusObject



68
69
70
# File 'lib/pretty_aws/rds_instance.rb', line 68

def status
  @params[:db_instance_status]
end

#storageObject



85
86
87
# File 'lib/pretty_aws/rds_instance.rb', line 85

def storage
  @params[:allocated_storage]
end

#usernameObject



93
94
95
# File 'lib/pretty_aws/rds_instance.rb', line 93

def username
  @params[:master_username]
end

#zoneObject



89
90
91
# File 'lib/pretty_aws/rds_instance.rb', line 89

def zone
  @params[:availability_zone]
end