Class: AwsInstanceList::RDS

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(region: 'eu-west-1') ⇒ RDS

Returns a new instance of RDS.



10
11
12
13
14
15
16
17
18
# File 'lib/aws_instance_list/rds.rb', line 10

def initialize region: 'eu-west-1'

  @region=region

  @client=Aws::RDS::Client.new region: region

  @db_instances = []

end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



8
9
10
# File 'lib/aws_instance_list/rds.rb', line 8

def client
  @client
end

#regionObject

Returns the value of attribute region.



8
9
10
# File 'lib/aws_instance_list/rds.rb', line 8

def region
  @region
end

Instance Method Details

#db_descriptions(options = {}) ⇒ Object



20
21
22
# File 'lib/aws_instance_list/rds.rb', line 20

def db_descriptions options={}
  client.describe_db_instances(options)
end

#db_instances(options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/aws_instance_list/rds.rb', line 24

def db_instances options={}
  descriptions=db_descriptions(options)
  @db_instances+=descriptions.db_instances
  if descriptions.marker
    options[:marker]=descriptions.marker
    db_instances(options)
  else
    @db_instances
  end
end

#db_list(options: {}, fields: nil) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/aws_instance_list/rds.rb', line 35

def db_list options: {}, fields: nil

  fields||=load_db_fields

  db_instances(options).map do |i|
    fields.map { |f| i.send(f) } << free_storage_space(i.db_instance_identifier) << region
  end
end

#demodulizeObject



60
61
62
# File 'lib/aws_instance_list/rds.rb', line 60

def demodulize
  self.class.name.split('::').last
end

#free_storage_space(db_instance_identifier) ⇒ Object



64
65
66
67
# File 'lib/aws_instance_list/rds.rb', line 64

def free_storage_space db_instance_identifier
  metric = AwsInstanceList::Metric.new region: region
  metric.free_storage_space db_instance_identifier
end

#load_db_fieldsObject



44
45
46
# File 'lib/aws_instance_list/rds.rb', line 44

def load_db_fields
  yaml['db']['fields']
end

#yamlObject



48
49
50
# File 'lib/aws_instance_list/rds.rb', line 48

def yaml
  @yaml||=yaml_default.merge(yaml_file)[demodulize]
end

#yaml_defaultObject



52
53
54
# File 'lib/aws_instance_list/rds.rb', line 52

def yaml_default
  YAML.load_file AwsInstanceList::DEFAULT_SETTINGS
end

#yaml_fileObject



56
57
58
# File 'lib/aws_instance_list/rds.rb', line 56

def yaml_file
  ENV.has_key?('AWS_INSTANCE_LIST_YAML') ? YAML.load_file(ENV['AWS_INSTANCE_LIST_YAML']) : {}
end