Class: AwsPricing::InstanceType
- Inherits:
-
Object
- Object
- AwsPricing::InstanceType
- Defined in:
- lib/amazon-pricing/definitions/instance-type.rb
Overview
InstanceType is a specific type of instance in a region with a defined price per hour. The price will vary by platform (Linux, Windows).
e.g. m1.large instance in US-East region will cost $0.34/hour for Linux and $0.48/hour for Windows.
Direct Known Subclasses
Ec2DedicatedHostType, Ec2InstanceType, ElastiCacheNodeType, RdsInstanceType
Instance Attribute Summary collapse
-
#api_name ⇒ Object
Returns the value of attribute api_name.
-
#compute_units ⇒ Object
Returns the value of attribute compute_units.
-
#disk_in_gb ⇒ Object
Returns the value of attribute disk_in_gb.
-
#disk_type ⇒ Object
Returns the value of attribute disk_type.
-
#memory_in_mb ⇒ Object
Returns the value of attribute memory_in_mb.
-
#name ⇒ Object
Returns the value of attribute name.
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#virtual_cores ⇒ Object
Returns the value of attribute virtual_cores.
Class Method Summary collapse
-
.disk_bytes_per_sec_capacity(api_name) ⇒ Object
Returns the bytes/s capacity if defined,
nilotherwise. -
.disk_ops_per_sec_capacity(api_name) ⇒ Object
Returns the ops/s capacity if defined,
nilotherwise. - .get_descriptive_cache_name(api_name) ⇒ Object
- .get_descriptive_name(api_name) ⇒ Object
- .populate_lookups ⇒ Object
- .service_type(category) ⇒ Object
Instance Method Summary collapse
- #category_types ⇒ Object
-
#disk_in_mb ⇒ Object
Keep this in for backwards compatibility within current major version of gem.
-
#get_breakeven_month(category_types, type_of_instance, term, is_multi_az = false, isByol = false) ⇒ Object
type_of_instance = :ondemand, :light, :medium, :heavy term = :year_1, :year_3, nil.
- #get_category_type(name, multi_az = false, byol = false) ⇒ Object
-
#initialize(region, api_name, name) ⇒ InstanceType
constructor
A new instance of InstanceType.
- #memory_in_gb ⇒ Object
-
#prepay(category_type, type_of_instance, term = nil, is_multi_az = false, isByol = false) ⇒ Object
type_of_instance = :ondemand, :light, :medium, :heavy term = :year_1, :year_3, nil.
-
#price_per_hour(category_type, type_of_instance, term = nil, is_multi_az = false, isByol = false) ⇒ Object
type_of_instance = :ondemand, :light, :medium, :heavy term = :year_1, :year_3, nil.
Constructor Details
#initialize(region, api_name, name) ⇒ InstanceType
Returns a new instance of InstanceType.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/amazon-pricing/definitions/instance-type.rb', line 25 def initialize(region, api_name, name) @category_types = {} @region = region @name = name @api_name = api_name @disk_in_gb = InstanceType.get_disk(api_name) @platform = InstanceType.get_platform(api_name) @disk_type = InstanceType.get_disk_type(api_name) @memory_in_mb = InstanceType.get_memory(api_name) @compute_units = InstanceType.get_compute_units(api_name) @virtual_cores = InstanceType.get_virtual_cores(api_name) end |
Instance Attribute Details
#api_name ⇒ Object
Returns the value of attribute api_name.
23 24 25 |
# File 'lib/amazon-pricing/definitions/instance-type.rb', line 23 def api_name @api_name end |
#compute_units ⇒ Object
Returns the value of attribute compute_units.
23 24 25 |
# File 'lib/amazon-pricing/definitions/instance-type.rb', line 23 def compute_units @compute_units end |
#disk_in_gb ⇒ Object
Returns the value of attribute disk_in_gb.
23 24 25 |
# File 'lib/amazon-pricing/definitions/instance-type.rb', line 23 def disk_in_gb @disk_in_gb end |
#disk_type ⇒ Object
Returns the value of attribute disk_type.
23 24 25 |
# File 'lib/amazon-pricing/definitions/instance-type.rb', line 23 def disk_type @disk_type end |
#memory_in_mb ⇒ Object
Returns the value of attribute memory_in_mb.
23 24 25 |
# File 'lib/amazon-pricing/definitions/instance-type.rb', line 23 def memory_in_mb @memory_in_mb end |
#name ⇒ Object
Returns the value of attribute name.
23 24 25 |
# File 'lib/amazon-pricing/definitions/instance-type.rb', line 23 def name @name end |
#platform ⇒ Object
Returns the value of attribute platform.
23 24 25 |
# File 'lib/amazon-pricing/definitions/instance-type.rb', line 23 def platform @platform end |
#virtual_cores ⇒ Object
Returns the value of attribute virtual_cores.
23 24 25 |
# File 'lib/amazon-pricing/definitions/instance-type.rb', line 23 def virtual_cores @virtual_cores end |
Class Method Details
.disk_bytes_per_sec_capacity(api_name) ⇒ Object
Returns the bytes/s capacity if defined, nil otherwise
121 122 123 124 125 |
# File 'lib/amazon-pricing/definitions/instance-type.rb', line 121 def self.disk_bytes_per_sec_capacity(api_name) if PER_SEC_CAPACITIES[api_name] PER_SEC_CAPACITIES[api_name][0] * 1024 * 1024 end end |
.disk_ops_per_sec_capacity(api_name) ⇒ Object
Returns the ops/s capacity if defined, nil otherwise
128 129 130 131 132 |
# File 'lib/amazon-pricing/definitions/instance-type.rb', line 128 def self.disk_ops_per_sec_capacity(api_name) if PER_SEC_CAPACITIES[api_name] PER_SEC_CAPACITIES[api_name][1] end end |
.get_descriptive_cache_name(api_name) ⇒ Object
138 139 140 |
# File 'lib/amazon-pricing/definitions/instance-type.rb', line 138 def self.get_descriptive_cache_name(api_name) @@Cache_Name_Lookup[api_name] end |
.get_descriptive_name(api_name) ⇒ Object
134 135 136 |
# File 'lib/amazon-pricing/definitions/instance-type.rb', line 134 def self.get_descriptive_name(api_name) @@Name_Lookup[api_name] end |
.populate_lookups ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/amazon-pricing/definitions/instance-type.rb', line 96 def self.populate_lookups # We use Linux on-demand to populate the lookup tables with the basic lookup information ["http://a0.awsstatic.com/pricing/1/ec2/linux-od.min.js", "http://a0.awsstatic.com/pricing/1/ec2/previous-generation/linux-od.min.js"].each do |url| res = AwsPricing::PriceList.fetch_url(url) res['config']['regions'].each do |reg| reg['instanceTypes'].each do |type| items = type['sizes'] items = [type] if items.nil? items.each do |size| begin api_name = size["size"] @@Memory_Lookup[api_name] = size["memoryGiB"].to_f * 1000 @@Compute_Units_Lookup[api_name] = size["ECU"].to_f @@Virtual_Cores_Lookup[api_name] = size["vCPU"].to_i rescue UnknownTypeError $stderr.puts "[populate_lookups] WARNING: encountered #{$!.}" end end end end end end |
.service_type(category) ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/amazon-pricing/definitions/instance-type.rb', line 86 def self.service_type(category) case category when 'os'; 'ec2' when 'db'; 'rds' when 'cache'; 'elasticache' else '' end end |
Instance Method Details
#category_types ⇒ Object
49 50 51 |
# File 'lib/amazon-pricing/definitions/instance-type.rb', line 49 def category_types @category_types.values end |
#disk_in_mb ⇒ Object
Keep this in for backwards compatibility within current major version of gem
41 42 43 |
# File 'lib/amazon-pricing/definitions/instance-type.rb', line 41 def disk_in_mb @disk_in_gb.nil? ? 0 : @disk_in_gb * 1000 end |
#get_breakeven_month(category_types, type_of_instance, term, is_multi_az = false, isByol = false) ⇒ Object
type_of_instance = :ondemand, :light, :medium, :heavy term = :year_1, :year_3, nil
81 82 83 84 |
# File 'lib/amazon-pricing/definitions/instance-type.rb', line 81 def get_breakeven_month(category_types, type_of_instance, term, is_multi_az = false, isByol = false) cat = get_category_type(category_types, is_multi_az, isByol) cat.get_breakeven_month(type_of_instance, term) unless cat.nil? end |
#get_category_type(name, multi_az = false, byol = false) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/amazon-pricing/definitions/instance-type.rb', line 53 def get_category_type(name, multi_az = false, byol = false) if multi_az == true and byol == true db = @category_types["#{name}_byol_multiaz"] elsif multi_az == true and byol == false db = @category_types["#{name}_multiaz"] elsif multi_az == false and byol == true db = @category_types["#{name}_byol"] else db = @category_types[name] end end |
#memory_in_gb ⇒ Object
45 46 47 |
# File 'lib/amazon-pricing/definitions/instance-type.rb', line 45 def memory_in_gb @memory_in_mb / 1000 end |
#prepay(category_type, type_of_instance, term = nil, is_multi_az = false, isByol = false) ⇒ Object
type_of_instance = :ondemand, :light, :medium, :heavy term = :year_1, :year_3, nil
74 75 76 77 |
# File 'lib/amazon-pricing/definitions/instance-type.rb', line 74 def prepay(category_type, type_of_instance, term = nil, is_multi_az = false, isByol = false) cat = get_category_type(category_type, is_multi_az, isByol) cat.prepay(type_of_instance, term) unless cat.nil? end |
#price_per_hour(category_type, type_of_instance, term = nil, is_multi_az = false, isByol = false) ⇒ Object
type_of_instance = :ondemand, :light, :medium, :heavy term = :year_1, :year_3, nil
67 68 69 70 |
# File 'lib/amazon-pricing/definitions/instance-type.rb', line 67 def price_per_hour(category_type, type_of_instance, term = nil, is_multi_az = false, isByol = false) cat = get_category_type(category_type, is_multi_az, isByol) cat.price_per_hour(type_of_instance, term) unless cat.nil? end |