Class: AWSCosts::EC2

Inherits:
Object
  • Object
show all
Defined in:
lib/awscosts/ec2.rb

Constant Summary collapse

TYPES =
{ windows: 'mswin', linux: 'linux', windows_with_sql: 'mswinSQL',
windows_with_sql_web: 'mswinSQLWeb', rhel: 'rhel', sles: 'sles' }
REGION_MAPPING =
{
  'us-east-1' => "us-east",
  'us-west-1' => "us-west",
  'us-west-2' => "us-west-2",
  'eu-west-1' => "eu-ireland",
  'eu-central-1' => "eu-central-1",
  'ap-southeast-1' => "apac-sin",
  'ap-southeast-2' =>"apac-syd",
  'ap-northeast-1' =>"apac-tokyo",
  'sa-east-1' => "sa-east-1"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(region) ⇒ EC2

Returns a new instance of EC2.



27
28
29
# File 'lib/awscosts/ec2.rb', line 27

def initialize region
  @region = region
end

Instance Attribute Details

#regionObject (readonly)

Returns the value of attribute region.



10
11
12
# File 'lib/awscosts/ec2.rb', line 10

def region
  @region
end

Instance Method Details

#ebsObject



47
48
49
# File 'lib/awscosts/ec2.rb', line 47

def ebs
  AWSCosts::EBS.fetch(REGION_MAPPING[self.region.name])
end

#ebs_optimizedObject



51
52
53
# File 'lib/awscosts/ec2.rb', line 51

def ebs_optimized
  AWSCosts::EBSOptimized.fetch(REGION_MAPPING[self.region.name])
end

#elastic_ipsObject



55
56
57
# File 'lib/awscosts/ec2.rb', line 55

def elastic_ips
  AWSCosts::ElasticIPs.fetch(REGION_MAPPING[self.region.name])
end

#elbObject



43
44
45
# File 'lib/awscosts/ec2.rb', line 43

def elb
  AWSCosts::ELB.fetch(REGION_MAPPING[self.region.name])
end

#on_demand(type) ⇒ Object

Raises:

  • (ArgumentError)


31
32
33
34
# File 'lib/awscosts/ec2.rb', line 31

def on_demand(type)
  raise ArgumentError.new("Unknown platform: #{type}") if TYPES[type].nil?
  AWSCosts::EC2OnDemand.fetch(TYPES[type], self.region.name)
end

#reserved(type, utilisation = :light) ⇒ Object

Raises:

  • (ArgumentError)


36
37
38
39
40
41
# File 'lib/awscosts/ec2.rb', line 36

def reserved(type, utilisation = :light)
  r = self.region.name
  r = 'us-east' if r == 'us-east-1'
  raise ArgumentError.new("Unknown platform: #{type}") if TYPES[type].nil?
  AWSCosts::EC2ReservedInstances.fetch(TYPES[type], utilisation, r)
end