Class: Awshark::Rds::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/awshark/rds/manager.rb

Instance Method Summary collapse

Instance Method Details

#check_reservationsObject



49
50
51
# File 'lib/awshark/rds/manager.rb', line 49

def check_reservations
  CheckReservations.new(instances: instances, reservations: reservations).check
end

#instancesObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/awshark/rds/manager.rb', line 8

def instances
  return @instances if defined?(@instances)

  @instances = []
  response = client.describe_db_instances

  response[:db_instances].each do |instance|
    @instances << OpenStruct.new(
      name: instance[:db_instance_identifier],
      type: instance[:db_instance_class],
      state: instance[:db_instance_status],
      multi_az: instance[:multi_az],
      engine: instance[:engine],
      engine_version: instance[:engine_version],
      encrypted: instance[:storage_encrypted],
      storage_type: instance[:storage_type]
    )
  end

  @instances
end

#reservationsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/awshark/rds/manager.rb', line 30

def reservations
  return @reservations if defined?(@reservations)

  response = client.describe_reserved_db_instances

  @reservations = response[:reserved_db_instances].map do |instance|
    OpenStruct.new(
      count: instance[:db_instance_count],
      type: instance[:db_instance_class],
      multi_az: instance[:multi_az],
      state: instance[:state],
      offering_type: instance[:offering_type]
    )
  end
  @reservations.select! { |ri| ri[:state] == 'active' }

  @reservations
end