Class: CloudCostTracker::Coding::AccountCodingPolicy
- Inherits:
-
Object
- Object
- CloudCostTracker::Coding::AccountCodingPolicy
- Defined in:
- lib/cloud_cost_tracker/coding/account_coding_policy.rb
Overview
Implements the generic logic for attaching billing codes to all resources in a single account. Initializes the necessary ResourceCodingPolicy objects, sorts the resources by policy, and calls #code once on each resource’s policy, to compute the billing codes as pairs of Strings.
Direct Known Subclasses
Compute::AWS::AccountCodingPolicy, RDS::AWS::AccountCodingPolicy
Instance Method Summary collapse
-
#attach_account_codes(resource) ⇒ Object
Defines an acount-wide coding strategy for coding each resource.
-
#code(resources) ⇒ Object
Defines the default method for coding all resources.
-
#initialize(resources, options = {}) ⇒ AccountCodingPolicy
constructor
Creates an object that implements a coding policy that attaches no billing codes.
-
#priority_classes ⇒ Array <Class>
Defines the order in which resource collections are coded.
-
#setup(resources) ⇒ Object
An initializer called by the framework once per bill coding cycle.
Constructor Details
#initialize(resources, options = {}) ⇒ AccountCodingPolicy
Creates an object that implements a coding policy that attaches no billing codes
15 16 17 18 |
# File 'lib/cloud_cost_tracker/coding/account_coding_policy.rb', line 15 def initialize(resources, ={}) @log = [:logger] || FogTracker.default_logger setup_resource_coding_agents(resources) end |
Instance Method Details
#attach_account_codes(resource) ⇒ Object
Defines an acount-wide coding strategy for coding each resource. Override this method if you need to write logic for attaching billing codes to all resources in an account, regardless of collection / type.
34 |
# File 'lib/cloud_cost_tracker/coding/account_coding_policy.rb', line 34 def attach_account_codes(resource) ; end |
#code(resources) ⇒ Object
Defines the default method for coding all resources. Attaches Billing Codes (String pairs) to resources, as @billing_codes. Resources whose class is in #priority_classes are coded first.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cloud_cost_tracker/coding/account_coding_policy.rb', line 39 def code(resources) return if resources.empty? account = resources.first.tracker_account @log.info "Coding account #{account[:name]}" resources.each {|resource| attach_account_codes(resource)} classes_to_code = priority_classes + (@agents.keys - priority_classes) classes_to_code.delete_if {|res_class| @agents[res_class] == nil} classes_to_code.each do |fog_model_class| @log.info "Coding #{fog_model_class} in account #{account[:name]}" collection = resources.select {|r| r.class == fog_model_class} collection.each do |resource| @agents[fog_model_class].each do |agent| @log.debug "Coding #{resource.tracker_description}" agent.code(resource) end end end end |
#priority_classes ⇒ Array <Class>
Defines the order in which resource collections are coded. Override this method if you need to code the resource collections in a particular order. Return an Array of the Fog::Model subclasses.
29 |
# File 'lib/cloud_cost_tracker/coding/account_coding_policy.rb', line 29 def priority_classes ; Array.new end |
#setup(resources) ⇒ Object
An initializer called by the framework once per bill coding cycle. Override this method if you need to perform high-latency operations, like network transactions, that should not be performed per-resource.
23 |
# File 'lib/cloud_cost_tracker/coding/account_coding_policy.rb', line 23 def setup(resources) ; end |