module AwsPricing::Helper::InstanceType
Constants
- METAL
- METAL_TO_NF_TABLE
- NF_TO_SIZE_TABLE
- SIZE_TO_NF_TABLE
NB: 'metal' is not in this table (since it's family specific), see api_name_to_nf
- VPC_ONLY_INSTANCE_FAMILIES
Public Class Methods
all_instances()
click to toggle source
# File lib/amazon-pricing/helpers/instance-type.rb 171 def self.all_instances 172 @all_instances ||= begin 173 [previous_generation_instances, current_generation_instances].inject({}) do |instances, family| 174 instances.merge(family) 175 end 176 end 177 end
api_name_to_nf(name)
click to toggle source
# File lib/amazon-pricing/helpers/instance-type.rb 187 def self.api_name_to_nf(name) 188 type = name.split('.').last 189 if (type == METAL) 190 # See if our metal instance has a hard-coded nf value 191 if !metal_to_nf[name].nil? 192 return metal_to_nf[name] 193 end 194 # try to get largest size supported for family: presumes METAL is *not* in size_to_nf hash 195 # assumes family_members are sorted by size 196 sizes = family_members(name) 197 # Return nil if we have a bogus instance type 198 if sizes.nil? 199 return nil 200 end 201 type = sizes[-1].split('.').last # 'metal' defaults to largest size 202 if sizes[-1].split('.').last == METAL 203 if sizes.size == 1 # We have an instance family with only metals but no NF associated; raise an error 204 return nil 205 end 206 type = sizes[-2].split('.').last # 'metal' already largest, so 2nd largest 207 end 208 end 209 full_type = type.gsub(/xl$/, 'xlarge') 210 size_to_nf[full_type] 211 end
burstable_instances()
click to toggle source
# File lib/amazon-pricing/helpers/instance-type.rb 117 def self.burstable_instances 118 instance_types['BurstableInstances'] 119 end
compute_optimized_instances()
click to toggle source
# File lib/amazon-pricing/helpers/instance-type.rb 121 def self.compute_optimized_instances 122 instance_types['ComputeOptimized'] 123 end
current_generation_instances()
click to toggle source
# File lib/amazon-pricing/helpers/instance-type.rb 156 def self.current_generation_instances 157 [ 158 general_purpose_instances['CurrentGen'], 159 burstable_instances['CurrentGen'], 160 compute_optimized_instances['CurrentGen'], 161 compute_optimized_instances['CurrentGen'], 162 memory_optimized_instances['CurrentGen'], 163 memory_optimized_instances['CurrentGen'], 164 storage_optimized_instances['CurrentGen'], 165 gpu_instances['CurrentGen'] 166 ].inject({}) do |instances, family| 167 instances.merge(family) 168 end 169 end
family(api_name)
click to toggle source
# File lib/amazon-pricing/helpers/instance-type.rb 179 def self.family(api_name) 180 all_instances.select { |family, instances| instances.include?(api_name) }.keys.first 181 end
family_members(api_name)
click to toggle source
# File lib/amazon-pricing/helpers/instance-type.rb 183 def self.family_members(api_name) 184 all_instances.select { |family, instances| instances.include?(api_name) }.values.first 185 end
general_purpose_instances()
click to toggle source
# File lib/amazon-pricing/helpers/instance-type.rb 113 def self.general_purpose_instances 114 instance_types['GeneralPurpose'] 115 end
gpu_instances()
click to toggle source
# File lib/amazon-pricing/helpers/instance-type.rb 133 def self.gpu_instances 134 instance_types['GPUInstances'] 135 end
instance_types()
click to toggle source
Important: Members of a family must be kept in 'size' order (small, medium, large, etc.) AWS Docs: docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html
# File lib/amazon-pricing/helpers/instance-type.rb 109 def self.instance_types 110 @@INSTANCE_TYPES_BY_CLASSIFICATION 111 end
memory_optimized_instances()
click to toggle source
# File lib/amazon-pricing/helpers/instance-type.rb 125 def self.memory_optimized_instances 126 instance_types['MemoryOptimized'] 127 end
metal_to_nf()
click to toggle source
# File lib/amazon-pricing/helpers/instance-type.rb 237 def self.metal_to_nf 238 METAL_TO_NF_TABLE 239 end
micro_instances()
click to toggle source
# File lib/amazon-pricing/helpers/instance-type.rb 137 def self.micro_instances 138 instance_types['MicroInstances'] 139 end
previous_generation_instances()
click to toggle source
# File lib/amazon-pricing/helpers/instance-type.rb 141 def self.previous_generation_instances 142 [ 143 general_purpose_instances['PreviousGen'], 144 compute_optimized_instances['PreviousGen'], 145 compute_optimized_instances['PreviousGen'], 146 memory_optimized_instances['PreviousGen'], 147 memory_optimized_instances['PreviousGen'], 148 storage_optimized_instances['PreviousGen'], 149 gpu_instances['PreviousGen'], 150 micro_instances['PreviousGen'] 151 ].inject({}) do |instances, family| 152 instances.merge(family) 153 end 154 end
size_to_nf()
click to toggle source
# File lib/amazon-pricing/helpers/instance-type.rb 233 def self.size_to_nf 234 SIZE_TO_NF_TABLE 235 end
storage_optimized_instances()
click to toggle source
# File lib/amazon-pricing/helpers/instance-type.rb 129 def self.storage_optimized_instances 130 instance_types['StorageOptimized'] 131 end
Public Instance Methods
next_smaller_type(name)
click to toggle source
note: the next smaller type may not be supported for a given family
so this returns the next logical/possible smaller type, but not necessarily the next valid type
# File lib/amazon-pricing/helpers/instance-type.rb 216 def next_smaller_type(name) 217 fam,type = name.split('.') 218 orig_nf = size_to_nf[type] 219 return nil unless orig_nf 220 # paranoia: assumes size_to_nf may not be sorted, which we need to step down 221 sorted_size_to_nf = {} 222 size_to_nf.sort_by(&:last).each do |(size,nf)| 223 sorted_size_to_nf[size] = nf 224 end 225 size_keys = sorted_size_to_nf.keys 226 idx = size_keys.index(type) 227 idx = idx - 1 if (idx > 0) # don't go smaller, than smallest 228 nf = sorted_size_to_nf[new_type = size_keys.at(idx)] 229 230 ["#{fam}.#{new_type}" , nf] 231 end