Class: CloudCostTracker::Billing::Compute::AWS::ServerBillingPolicy

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

Overview

The default billing policy for Amazon EC2 server instances

Constant Summary collapse

CENTS_PER_HOUR =

The YAML pricing data is read from config/billing

YAML.load(File.read File.join(
CONSTANTS_DIR, 'compute-aws-servers', 'us-east-on_demand.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



24
# File 'lib/cloud_cost_tracker/billing/compute/aws/servers.rb', line 24

def billing_type ; "EC2 Instance runtime" end

#get_cost_for_duration(ec2_server, duration) ⇒ Object

Returns the storage cost for a given EC2 server over some duration (in seconds)



13
14
15
16
17
# File 'lib/cloud_cost_tracker/billing/compute/aws/servers.rb', line 13

def get_cost_for_duration(ec2_server, duration)
  return 0.0 if ec2_server.state =~ /(stopped|terminated)/
  hourly_cost = CENTS_PER_HOUR[platform_for(ec2_server)][ec2_server.flavor_id]
  (hourly_cost * duration) / SECONDS_PER_HOUR
end

#platform_for(resource) ⇒ Object

Returns either ‘windows’ or ‘unix’, based on this instance’s platform



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

def platform_for(resource)
  ('windows' == resource.platform) ? 'windows' : 'unix'
end