Class: CloudCostTracker::Coding::AWS::RDS::ServerCodingPolicy
- Inherits:
-
ResourceCodingPolicy
- Object
- ResourceCodingPolicy
- CloudCostTracker::Coding::AWS::RDS::ServerCodingPolicy
- Defined in:
- lib/cloud_cost_tracker/coding/rds/servers.rb
Overview
Implements the logic for attaching billing codes to RDS instances
Instance Method Summary collapse
-
#code(rds_server) ⇒ Object
Copies all billing codes from this server’s Groups.
-
#code_from_parameter_group(rds_server) ⇒ Object
Copies all billing codes from this server’s Parameter Group.
-
#code_from_security_group(rds_server) ⇒ Object
Copies all billing codes from this server’s Security Group.
-
#setup(resources) ⇒ Object
Indexes the security and parameter groups, so that BillingCodes can be pulled from them quickly when code() is called.
Methods inherited from ResourceCodingPolicy
Constructor Details
This class inherits a constructor from CloudCostTracker::Coding::ResourceCodingPolicy
Instance Method Details
#code(rds_server) ⇒ Object
Copies all billing codes from this server’s Groups
22 23 24 25 |
# File 'lib/cloud_cost_tracker/coding/rds/servers.rb', line 22 def code(rds_server) code_from_security_group(rds_server) code_from_parameter_group(rds_server) end |
#code_from_parameter_group(rds_server) ⇒ Object
Copies all billing codes from this server’s Parameter Group
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cloud_cost_tracker/coding/rds/servers.rb', line 42 def code_from_parameter_group(rds_server) if rds_server.db_parameter_groups server_groups = rds_server.db_parameter_groups.map do |group| @acc_param_groups[group['DBParameterGroupName']] end server_groups.each do |group| group.billing_codes.each do |billing_code| rds_server.code(billing_code[0], billing_code[1]) end end end end |
#code_from_security_group(rds_server) ⇒ Object
Copies all billing codes from this server’s Security Group
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/cloud_cost_tracker/coding/rds/servers.rb', line 28 def code_from_security_group(rds_server) if rds_server.db_security_groups server_groups = rds_server.db_security_groups.map do |group| @acc_sec_groups[group['DBSecurityGroupName']] end server_groups.each do |group| group.billing_codes.each do |billing_code| rds_server.code(billing_code[0], billing_code[1]) end end end end |
#setup(resources) ⇒ Object
Indexes the security and parameter groups, so that BillingCodes can be pulled from them quickly when code() is called
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/cloud_cost_tracker/coding/rds/servers.rb', line 10 def setup(resources) @acc_sec_groups = Hash.new # Index the security groups resources.first.account_resources('security_groups').each do |group| @acc_sec_groups[group.identity] = group end @acc_param_groups = Hash.new # Index the parameter groups resources.first.account_resources('parameter_groups').each do |group| @acc_param_groups[group.identity] = group end end |