Class: CloudCostTracker::Billing::Compute::AWS::SnapshotBillingPolicy

Inherits:
ResourceBillingPolicy show all
Defined in:
lib/cloud_cost_tracker/billing/compute/aws/snapshots.rb

Overview

The default billing policy for Amazon EBS Snapshots

*NOT REALLY WORKING* - AWS does not report the size of snapshots, so there’s no way to accurately verify the cost! :(

Constant Summary collapse

CENTS_PER_GB_PER_MONTH =

The YAML pricing data is read from config/billing

YAML.load(File.read File.join(
CONSTANTS_DIR, 'compute-aws-snapshots.yml'))

Constants included from CloudCostTracker

VERSION

Instance Method Summary collapse

Methods inherited from ResourceBillingPolicy

#initialize, #setup, #write_billing_record_for

Methods included from CloudCostTracker

account_coding_class, connect_to_database, create_billing_agents, create_coding_agents, env, read_accounts

Constructor Details

This class inherits a constructor from CloudCostTracker::Billing::ResourceBillingPolicy

Instance Method Details

#billing_typeObject



37
# File 'lib/cloud_cost_tracker/billing/compute/aws/snapshots.rb', line 37

def billing_type ; "EBS snapshot storage" end

#get_cost_for_duration(snapshot, duration) ⇒ Object

Returns the storage cost for a given EBS Snapshot over some duration (in seconds) TODO - Make an estimate based on lineage and volume size This code is only accurate if the snapshot is the first for its volume



18
19
20
21
22
# File 'lib/cloud_cost_tracker/billing/compute/aws/snapshots.rb', line 18

def get_cost_for_duration(snapshot, duration)
  return 0.0  # TEMPORARILY DISABLED UNTIL WORKAROUND IS FOUND
  CENTS_PER_GB_PER_MONTH[zone(snapshot)] * snapshot.volume_size *
  duration / SECONDS_PER_MONTH
end

#zone(resource) ⇒ Object

Follows the snapshot’s volume and returns its region, and chops the availability zone letter from the region



26
27
28
29
30
31
32
33
34
35
# File 'lib/cloud_cost_tracker/billing/compute/aws/snapshots.rb', line 26

def zone(resource)
  volume = resource.('volumes').find do |v|
    v.identity == resource.volume_id
  end
  if volume && volume.availability_zone
    volume.availability_zone.chop
  else
    "us-east-1"
  end
end