Class: Aws::RiKanjoo::Rds
- Inherits:
-
Object
- Object
- Aws::RiKanjoo::Rds
- Defined in:
- lib/aws/rikanjo/rds.rb
Instance Attribute Summary collapse
-
#instance_type ⇒ Object
readonly
Returns the value of attribute instance_type.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
-
#ri_util ⇒ Object
readonly
Returns the value of attribute ri_util.
Instance Method Summary collapse
- #convert_region(region) ⇒ Object
-
#initialize(region, instance_type, ri_util, multiaz) ⇒ Rds
constructor
A new instance of Rds.
- #om_price_file ⇒ Object
- #om_price_from_contents(contents) ⇒ Object
- #parse_contents(data) ⇒ Object
- #previous_generation_type ⇒ Object
- #price_url ⇒ Object
- #ri_price_file ⇒ Object
- #ri_price_from_contents(contents) ⇒ Object
Constructor Details
#initialize(region, instance_type, ri_util, multiaz) ⇒ Rds
Returns a new instance of Rds.
6 7 8 9 10 11 12 13 14 |
# File 'lib/aws/rikanjo/rds.rb', line 6 def initialize(region, instance_type, ri_util, multiaz) @region = region @instance_type = "db.#{instance_type}" @ri_util = ri_util @rdbms = 'mysql' @current_price_url = "http://a0.awsstatic.com/pricing/1/rds/#{@rdbms}" @previous_price_url = "http://a0.awsstatic.com/pricing/1/rds/#{@rdbms}/previous-generation" @multiaz = multiaz end |
Instance Attribute Details
#instance_type ⇒ Object (readonly)
Returns the value of attribute instance_type.
4 5 6 |
# File 'lib/aws/rikanjo/rds.rb', line 4 def instance_type @instance_type end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
4 5 6 |
# File 'lib/aws/rikanjo/rds.rb', line 4 def region @region end |
#ri_util ⇒ Object (readonly)
Returns the value of attribute ri_util.
4 5 6 |
# File 'lib/aws/rikanjo/rds.rb', line 4 def ri_util @ri_util end |
Instance Method Details
#convert_region(region) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/aws/rikanjo/rds.rb', line 105 def convert_region(region) # not same om region case region when 'us-east-1' then 'us-east' when 'us-west-1' then 'us-west' when 'us-west-2' then 'us-west-2' when 'eu-west-1' then 'eu-ireland' when 'ap-southeast-1' then 'apac-sin' when 'ap-northeast-1' then 'apac-tokyo' when 'ap-southeast-2' then 'apac-syd' when 'sa-east-1' then 'sa-east-1' end end |
#om_price_file ⇒ Object
84 85 86 |
# File 'lib/aws/rikanjo/rds.rb', line 84 def om_price_file return (@multiaz) ? "pricing-multiAZ-deployments.min.js" : "pricing-standard-deployments.min.js" end |
#om_price_from_contents(contents) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/aws/rikanjo/rds.rb', line 16 def om_price_from_contents(contents) region = convert_region(@region) # parse json = parse_contents(contents) # select 'region' and 'instance_type' json['config']['regions'].each do |r| # r = {"region"=>"us-east", "instanceTypes"=>[{"type"=>"generalCurrentGen", ... next unless r['region'] == region r['types'].each do |type| # type = {"type"=>"generalCurrentGen", "sizes"=>[{"size"=>"m3.medium", "vCPU"=>"1" ... type['tiers'].each do |i| next unless i['name'] == @instance_type return { hr_price: i['prices']['USD'] } end end end abort("[rds][#{region}][#{@instance_type}] Not found om-price?") end |
#parse_contents(data) ⇒ Object
100 101 102 103 |
# File 'lib/aws/rikanjo/rds.rb', line 100 def parse_contents(data) data = data.gsub("/*\n * This file is intended for use only on aws.amazon.com. We do not guarantee its availability or accuracy.\n *\n * Copyright 2014 Amazon.com, Inc. or its affiliates. All rights reserved.\n */\ncallback({",'{').gsub("\);", '').gsub(/([a-zA-Z]+):/, '"\1":') return Yajl::Parser.parse(data) end |
#previous_generation_type ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/aws/rikanjo/rds.rb', line 92 def previous_generation_type case @instance_type when /^db.(c1|m2|cc2\.8xlarge|cr1\.8xlarge|hi1\.4xlarge|cg1\.4xlarge)/ then true when /^db.m1/ then (@instance_type == 'db.m1.small') ? false : true else false end end |
#price_url ⇒ Object
80 81 82 |
# File 'lib/aws/rikanjo/rds.rb', line 80 def price_url return (self.previous_generation_type) ? @previous_price_url : @current_price_url end |
#ri_price_file ⇒ Object
88 89 90 |
# File 'lib/aws/rikanjo/rds.rb', line 88 def ri_price_file return "pricing-#{@ri_util}-utilization-reserved-instances.min.js" end |
#ri_price_from_contents(contents) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/aws/rikanjo/rds.rb', line 39 def ri_price_from_contents(contents) region = convert_region(@region) mtype = (@multiaz) ? 'Multi-AZ' : 'Single-AZ' # parse json = parse_contents(contents) ri_info = nil json['config']['regions'].each do |r| next unless r['region'] == region r['instanceTypes'].each do |type| next unless type['type'] =~ /#{mtype}/ type['tiers'].each do |i| next unless i['size'] == @instance_type ri_info = ri_info ||= {} i['valueColumns'].each do |y| # beauty y['name'].gsub!(/^year/, 'yr') y['prices']['USD'].gsub!(/,/, '') case y['name'] when 'yrTerm1' ri_info[@ri_util] = { upfront: y['prices']['USD'] } when 'yrTerm1Hourly' ri_info[@ri_util].store(:hr_price, y['prices']['USD']) end end end end end abort("[rds][#{region}][#{@instance_type}] Not found ri-price?") unless ri_info return ri_info end |