Module: Awsborn::AwsConstants
- Included in:
- Ec2, Elb, LoadBalancer, Route53, Server
- Defined in:
- lib/awsborn/aws_constants.rb
Constant Summary collapse
- AVAILABILITY_ZONES =
%w[ us-east-1a us-east-1b us-east-1c us-east-1d us-west-1a us-west-1b us-west-1c eu-west-1a eu-west-1b eu-west-1c ap-southeast-1a ap-southeast-1b ap-northeast-1a ap-northeast-1b ]
- REGIONS =
AVAILABILITY_ZONES.map{|z| z.sub(/[a-z]$/,'') }.uniq
- INSTANCE_TYPES_32_BIT =
%w[m1.small c1.medium t1.micro]
- INSTANCE_TYPES_64_BIT =
%w[ m1.small m1.medium m1.large m1.xlarge m2.xlarge m2.2xlarge m2.4xlarge c1.medium c1.xlarge cc1.4xlarge cc2.8xlarge t1.micro]
- INSTANCE_TYPES =
(INSTANCE_TYPES_32_BIT + INSTANCE_TYPES_64_BIT).uniq
- SYMBOL_CONSTANT_MAP =
(AVAILABILITY_ZONES + INSTANCE_TYPES).inject({}) { |memo,str| memo[str.tr('-.','_').to_sym] = str; memo }
Instance Method Summary collapse
- #aws_constant(symbol) ⇒ Object
- #aws_instance_type_to_symbol(type) ⇒ Object
- #aws_zone_to_symbol(zone) ⇒ Object
- #endpoint_for_zone_and_service(zone, service) ⇒ Object
- #symbol_to_aws_instance_type(symbol) ⇒ Object
- #symbol_to_aws_zone(symbol) ⇒ Object
- #zone_to_aws_region(zone) ⇒ Object
Instance Method Details
#aws_constant(symbol) ⇒ Object
58 59 60 |
# File 'lib/awsborn/aws_constants.rb', line 58 def aws_constant (symbol) SYMBOL_CONSTANT_MAP[symbol] || raise(UnknownConstantError, "Unknown constant: #{symbol}") end |
#aws_instance_type_to_symbol(type) ⇒ Object
53 54 55 56 |
# File 'lib/awsborn/aws_constants.rb', line 53 def aws_instance_type_to_symbol (type) raise UnknownConstantError, "Unknown instance type: #{type}" unless INSTANCE_TYPES.include? type type.to_s.tr('.','_').to_sym end |
#aws_zone_to_symbol(zone) ⇒ Object
42 43 44 45 |
# File 'lib/awsborn/aws_constants.rb', line 42 def aws_zone_to_symbol (zone) raise UnknownConstantError, "Unknown availability zone: #{zone}" unless AVAILABILITY_ZONES.include? zone zone.to_s.tr('-','_').to_sym end |
#endpoint_for_zone_and_service(zone, service) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/awsborn/aws_constants.rb', line 22 def endpoint_for_zone_and_service (zone, service) region = zone_to_aws_region(zone) case service when :ec2 then "https://#{region}.ec2.amazonaws.com" when :elb then "https://#{region}.elasticloadbalancing.amazonaws.com" end end |
#symbol_to_aws_instance_type(symbol) ⇒ Object
47 48 49 50 51 |
# File 'lib/awsborn/aws_constants.rb', line 47 def symbol_to_aws_instance_type (symbol) type = symbol.to_s.tr('_','.') raise UnknownConstantError, "Unknown instance type: #{type}" unless INSTANCE_TYPES.include? type type end |
#symbol_to_aws_zone(symbol) ⇒ Object
36 37 38 39 40 |
# File 'lib/awsborn/aws_constants.rb', line 36 def symbol_to_aws_zone (symbol) zone = symbol.to_s.tr('_','-') raise UnknownConstantError, "Unknown availability zone: #{zone}" unless AVAILABILITY_ZONES.include? zone zone end |
#zone_to_aws_region(zone) ⇒ Object
30 31 32 33 34 |
# File 'lib/awsborn/aws_constants.rb', line 30 def zone_to_aws_region (zone) region = zone.to_s.sub(/[a-z]$/,'').tr('_','-') raise UnknownConstantError, "Unknown region: #{region} for zone: #{zone}" unless REGIONS.include? region region end |