aws-rikanjo 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.hound.yml +6 -0
- data/.travis.yml +8 -0
- data/Gemfile +0 -6
- data/README.md +18 -15
- data/aws-rikanjo.gemspec +12 -9
- data/bin/rikanjo +3 -75
- data/lib/aws/rikanjo.rb +6 -126
- data/lib/aws/rikanjo/base.rb +40 -0
- data/lib/aws/rikanjo/calc.rb +103 -0
- data/lib/aws/rikanjo/cli.rb +113 -0
- data/lib/aws/rikanjo/ec2.rb +117 -0
- data/lib/aws/rikanjo/rds.rb +120 -0
- data/lib/aws/rikanjo/version.rb +1 -1
- data/spec/lib/rikanjo_ec2_spec.rb +12 -12
- data/spec/lib/rikanjo_rds_spec.rb +22 -12
- metadata +60 -13
- data/lib/aws/rikanjo/mode/ec2.rb +0 -120
- data/lib/aws/rikanjo/mode/rds.rb +0 -117
@@ -1,24 +1,34 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
require "aws/rikanjo/
|
2
|
+
require "aws/rikanjo/rds"
|
3
3
|
|
4
4
|
include RikanjoSpecHelper
|
5
5
|
|
6
|
-
describe 'AWS::Rikanjo::
|
6
|
+
describe 'AWS::Rikanjo::Rds' do
|
7
7
|
|
8
8
|
describe 'url' do
|
9
9
|
|
10
|
+
it "build previous price url" do
|
11
|
+
a = Aws::RiKanjoo::Rds.new(
|
12
|
+
region = 'ap-northeast-1',
|
13
|
+
instance_type = 'm1.large',
|
14
|
+
ri_util = 'light',
|
15
|
+
multiaz = false,
|
16
|
+
)
|
17
|
+
expect(a.price_url).to eq "http://a0.awsstatic.com/pricing/1/rds/mysql/previous-generation"
|
18
|
+
end
|
19
|
+
|
10
20
|
it "build current price url" do
|
11
|
-
a = Aws::RiKanjoo::
|
21
|
+
a = Aws::RiKanjoo::Rds.new(
|
12
22
|
region = 'ap-northeast-1',
|
13
23
|
instance_type = 'm3.large',
|
14
24
|
ri_util = 'light',
|
15
25
|
multiaz = false,
|
16
26
|
)
|
17
|
-
expect(a.price_url).to eq "
|
27
|
+
expect(a.price_url).to eq "http://a0.awsstatic.com/pricing/1/rds/mysql"
|
18
28
|
end
|
19
29
|
|
20
30
|
it "build current om price file" do
|
21
|
-
a = Aws::RiKanjoo::
|
31
|
+
a = Aws::RiKanjoo::Rds.new(
|
22
32
|
region = 'ap-northeast-1',
|
23
33
|
instance_type = 'm2.xlarge',
|
24
34
|
ri_util = 'medium',
|
@@ -28,7 +38,7 @@ describe 'AWS::Rikanjo::Mode::Rds' do
|
|
28
38
|
end
|
29
39
|
|
30
40
|
it "build current om price file(multiaz)" do
|
31
|
-
a = Aws::RiKanjoo::
|
41
|
+
a = Aws::RiKanjoo::Rds.new(
|
32
42
|
region = 'ap-northeast-1',
|
33
43
|
instance_type = 'm2.xlarge',
|
34
44
|
ri_util = 'medium',
|
@@ -38,7 +48,7 @@ describe 'AWS::Rikanjo::Mode::Rds' do
|
|
38
48
|
end
|
39
49
|
|
40
50
|
it "build current ri price file" do
|
41
|
-
a = Aws::RiKanjoo::
|
51
|
+
a = Aws::RiKanjoo::Rds.new(
|
42
52
|
region = 'ap-northeast-1',
|
43
53
|
instance_type = 'm2.xlarge',
|
44
54
|
ri_util = 'medium',
|
@@ -54,14 +64,14 @@ describe 'AWS::Rikanjo::Mode::Rds' do
|
|
54
64
|
|
55
65
|
before :all do
|
56
66
|
# rikanjo (single-az)
|
57
|
-
a1 = Aws::RiKanjoo::
|
67
|
+
a1 = Aws::RiKanjoo::Rds.new(
|
58
68
|
region = 'ap-northeast-1',
|
59
69
|
instance_type = 'm3.medium',
|
60
70
|
ri_util = 'medium',
|
61
71
|
multiaz = false,
|
62
72
|
)
|
63
73
|
# rikanjo (multi-az)
|
64
|
-
a2 = Aws::RiKanjoo::
|
74
|
+
a2 = Aws::RiKanjoo::Rds.new(
|
65
75
|
region = 'ap-northeast-1',
|
66
76
|
instance_type = 'm3.medium',
|
67
77
|
ri_util = 'medium',
|
@@ -74,7 +84,7 @@ describe 'AWS::Rikanjo::Mode::Rds' do
|
|
74
84
|
|
75
85
|
it "is able to get the price(singleaz)" do
|
76
86
|
regions.each do |region|
|
77
|
-
a = Aws::RiKanjoo::
|
87
|
+
a = Aws::RiKanjoo::Rds.new(
|
78
88
|
region = region,
|
79
89
|
instance_type = 'm3.large',
|
80
90
|
ri_util = 'medium',
|
@@ -93,7 +103,7 @@ describe 'AWS::Rikanjo::Mode::Rds' do
|
|
93
103
|
|
94
104
|
it "is able to get the price(multiaz)" do
|
95
105
|
regions.each do |region|
|
96
|
-
a = Aws::RiKanjoo::
|
106
|
+
a = Aws::RiKanjoo::Rds.new(
|
97
107
|
region = region,
|
98
108
|
instance_type = 'm3.large',
|
99
109
|
ri_util = 'medium',
|
@@ -112,7 +122,7 @@ describe 'AWS::Rikanjo::Mode::Rds' do
|
|
112
122
|
|
113
123
|
it "an exception is raised when there are no instance-type" do
|
114
124
|
regions.each do |region|
|
115
|
-
a = Aws::RiKanjoo::
|
125
|
+
a = Aws::RiKanjoo::Rds.new(
|
116
126
|
region = region,
|
117
127
|
instance_type = 'm3.large.not.exists',
|
118
128
|
ri_util = 'medium',
|
metadata
CHANGED
@@ -1,41 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws-rikanjo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kenjiskywalker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yajl-ruby
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
39
81
|
- !ruby/object:Gem::Version
|
40
82
|
version: '0'
|
41
83
|
description: AWS RI Cost Calc Tool
|
@@ -46,8 +88,10 @@ executables:
|
|
46
88
|
extensions: []
|
47
89
|
extra_rdoc_files: []
|
48
90
|
files:
|
49
|
-
-
|
50
|
-
-
|
91
|
+
- .gitignore
|
92
|
+
- .hound.yml
|
93
|
+
- .rspec
|
94
|
+
- .travis.yml
|
51
95
|
- Gemfile
|
52
96
|
- LICENSE.txt
|
53
97
|
- README.md
|
@@ -55,8 +99,11 @@ files:
|
|
55
99
|
- aws-rikanjo.gemspec
|
56
100
|
- bin/rikanjo
|
57
101
|
- lib/aws/rikanjo.rb
|
58
|
-
- lib/aws/rikanjo/
|
59
|
-
- lib/aws/rikanjo/
|
102
|
+
- lib/aws/rikanjo/base.rb
|
103
|
+
- lib/aws/rikanjo/calc.rb
|
104
|
+
- lib/aws/rikanjo/cli.rb
|
105
|
+
- lib/aws/rikanjo/ec2.rb
|
106
|
+
- lib/aws/rikanjo/rds.rb
|
60
107
|
- lib/aws/rikanjo/version.rb
|
61
108
|
- spec/lib/rikanjo_ec2_spec.rb
|
62
109
|
- spec/lib/rikanjo_rds_spec.rb
|
@@ -72,17 +119,17 @@ require_paths:
|
|
72
119
|
- lib
|
73
120
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
121
|
requirements:
|
75
|
-
- -
|
122
|
+
- - '>='
|
76
123
|
- !ruby/object:Gem::Version
|
77
124
|
version: '0'
|
78
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
126
|
requirements:
|
80
|
-
- -
|
127
|
+
- - '>='
|
81
128
|
- !ruby/object:Gem::Version
|
82
129
|
version: '0'
|
83
130
|
requirements: []
|
84
131
|
rubyforge_project:
|
85
|
-
rubygems_version: 2.
|
132
|
+
rubygems_version: 2.0.14
|
86
133
|
signing_key:
|
87
134
|
specification_version: 4
|
88
135
|
summary: calc 1 year cost. check sweet spot
|
data/lib/aws/rikanjo/mode/ec2.rb
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
require 'yajl'
|
2
|
-
|
3
|
-
module Aws
|
4
|
-
class RiKanjoo
|
5
|
-
class Mode
|
6
|
-
class Ec2
|
7
|
-
attr_reader :region, :instance_type, :ri_util
|
8
|
-
|
9
|
-
def initialize(region, instance_type, ri_util)
|
10
|
-
@region = region
|
11
|
-
@instance_type = instance_type
|
12
|
-
@ri_util = ri_util
|
13
|
-
@os = 'linux'
|
14
|
-
@current_price_url = 'http://a0.awsstatic.com/pricing/1/ec2'
|
15
|
-
@previous_price_url = 'http://a0.awsstatic.com/pricing/1/ec2/previous-generation'
|
16
|
-
end
|
17
|
-
|
18
|
-
def om_price_from_contents contents
|
19
|
-
region = self.convert_region(@region)
|
20
|
-
|
21
|
-
# parse
|
22
|
-
json = self.parse_contents(contents)
|
23
|
-
|
24
|
-
# select 'region' and 'instance_type'
|
25
|
-
json["config"]["regions"].each do |r|
|
26
|
-
# r = {"region"=>"us-east", "instanceTypes"=>[{"type"=>"generalCurrentGen", ...
|
27
|
-
next unless r["region"] == region
|
28
|
-
r["instanceTypes"].each do |type|
|
29
|
-
# type = {"type"=>"generalCurrentGen", "sizes"=>[{"size"=>"m3.medium", "vCPU"=>"1" ...
|
30
|
-
type["sizes"].each do |i|
|
31
|
-
next unless i["size"] == @instance_type
|
32
|
-
|
33
|
-
return {:hr_price => i["valueColumns"][0]["prices"]["USD"]}
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
abort("[ec2][#{region}][#{@instance_type}] Not found om-price?")
|
39
|
-
end
|
40
|
-
|
41
|
-
def ri_price_from_contents contents
|
42
|
-
region = self.clean_region(@region)
|
43
|
-
|
44
|
-
# parse
|
45
|
-
json = self.parse_contents(contents)
|
46
|
-
|
47
|
-
ri_info = nil
|
48
|
-
|
49
|
-
json["config"]["regions"].each do |r|
|
50
|
-
next unless r["region"] == region
|
51
|
-
|
52
|
-
r["instanceTypes"].each do |type|
|
53
|
-
type["sizes"].each do |i|
|
54
|
-
next unless i["size"] == @instance_type
|
55
|
-
|
56
|
-
ri_info = ri_info || {}
|
57
|
-
i["valueColumns"].each do |y|
|
58
|
-
case y["name"]
|
59
|
-
when "yrTerm1"
|
60
|
-
ri_info[@ri_util] = {:upfront => y["prices"]["USD"]}
|
61
|
-
when "yrTerm1Hourly"
|
62
|
-
ri_info[@ri_util].store(:hr_price, y["prices"]["USD"])
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
abort("[ec2][#{region}][#{@instance_type}] Not found ri-price?") unless ri_info
|
70
|
-
|
71
|
-
return ri_info
|
72
|
-
end
|
73
|
-
|
74
|
-
def price_url
|
75
|
-
return (self.previous_generation_type) ? @previous_price_url : @current_price_url
|
76
|
-
end
|
77
|
-
|
78
|
-
def om_price_file
|
79
|
-
return "#{@os}-od.min.js"
|
80
|
-
end
|
81
|
-
|
82
|
-
def ri_price_file
|
83
|
-
return (self.previous_generation_type) ? "#{@ri_util}_#{@os}.min.js" : "#{@os}-ri-#{@ri_util}.min.js"
|
84
|
-
end
|
85
|
-
|
86
|
-
def previous_generation_type
|
87
|
-
case @instance_type
|
88
|
-
when /^(c1|m2|cc2\.8xlarge|cr1\.8xlarge|hi1\.4xlarge|cg1\.4xlarge)/ then true
|
89
|
-
when /^m1/ then (@instance_type == "m1.small") ? false : true
|
90
|
-
else false
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def parse_contents data
|
95
|
-
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":')
|
96
|
-
return Yajl::Parser.parse(data)
|
97
|
-
end
|
98
|
-
|
99
|
-
def convert_region region
|
100
|
-
# not same om region
|
101
|
-
case region
|
102
|
-
when "us-east-1" then "us-east"
|
103
|
-
when "us-west-1" then "us-west"
|
104
|
-
when "us-west-2" then "us-west-2"
|
105
|
-
when "eu-west-1" then "eu-ireland"
|
106
|
-
when "ap-southeast-1" then "apac-sin"
|
107
|
-
when "ap-northeast-1" then "apac-tokyo"
|
108
|
-
when "ap-southeast-2" then "apac-syd"
|
109
|
-
when "sa-east-1" then "sa-east-1"
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def clean_region region
|
114
|
-
return region.gsub(/^us-east-1$/, 'us-east')
|
115
|
-
end
|
116
|
-
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
data/lib/aws/rikanjo/mode/rds.rb
DELETED
@@ -1,117 +0,0 @@
|
|
1
|
-
module Aws
|
2
|
-
class RiKanjoo
|
3
|
-
class Mode
|
4
|
-
class Rds
|
5
|
-
attr_reader :region, :instance_type, :ri_util
|
6
|
-
|
7
|
-
def initialize(region, instance_type, ri_util, multiaz)
|
8
|
-
@region = region
|
9
|
-
@instance_type = "db.#{instance_type}"
|
10
|
-
@ri_util = ri_util
|
11
|
-
@rdbms = 'mysql'
|
12
|
-
@price_url = "https://a0.awsstatic.com/pricing/1/rds/#{@rdbms}"
|
13
|
-
@multiaz = multiaz
|
14
|
-
end
|
15
|
-
|
16
|
-
def om_price_from_contents contents
|
17
|
-
region = self.convert_region(@region)
|
18
|
-
|
19
|
-
# parse
|
20
|
-
json = self.parse_contents(contents)
|
21
|
-
|
22
|
-
# select 'region' and 'instance_type'
|
23
|
-
json["config"]["regions"].each do |r|
|
24
|
-
# r = {"region"=>"us-east", "instanceTypes"=>[{"type"=>"generalCurrentGen", ...
|
25
|
-
next unless r["region"] == region
|
26
|
-
r["types"].each do |type|
|
27
|
-
# type = {"type"=>"generalCurrentGen", "sizes"=>[{"size"=>"m3.medium", "vCPU"=>"1" ...
|
28
|
-
type["tiers"].each do |i|
|
29
|
-
next unless i["name"] == @instance_type
|
30
|
-
|
31
|
-
return {:hr_price => i["prices"]["USD"]}
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
abort("[rds][#{region}][#{@instance_type}] Not found om-price?")
|
37
|
-
end
|
38
|
-
|
39
|
-
def ri_price_from_contents contents
|
40
|
-
region = self.convert_region(@region)
|
41
|
-
mtype = (@multiaz) ? 'multiAZdeployRes' : 'stdDeployRes'
|
42
|
-
|
43
|
-
# parse
|
44
|
-
json = self.parse_contents(contents)
|
45
|
-
|
46
|
-
ri_info = nil
|
47
|
-
|
48
|
-
json["config"]["regions"].each do |r|
|
49
|
-
next unless r["region"] == region
|
50
|
-
|
51
|
-
r["instanceTypes"].each do |type|
|
52
|
-
# beauty
|
53
|
-
type["type"].gsub!(/Single-AZ Deployment \(Reserved\)/, 'stdDeployRes')
|
54
|
-
|
55
|
-
next unless type["type"] == mtype
|
56
|
-
|
57
|
-
type["tiers"].each do |i|
|
58
|
-
next unless i["size"] == @instance_type
|
59
|
-
|
60
|
-
ri_info = ri_info || {}
|
61
|
-
i["valueColumns"].each do |y|
|
62
|
-
# beauty
|
63
|
-
y["name"].gsub!(/^year/, 'yr')
|
64
|
-
y["prices"]["USD"].gsub!(/,/, '')
|
65
|
-
|
66
|
-
case y["name"]
|
67
|
-
when "yrTerm1"
|
68
|
-
ri_info[@ri_util] = {:upfront => y["prices"]["USD"]}
|
69
|
-
when "yrTerm1Hourly"
|
70
|
-
ri_info[@ri_util].store(:hr_price, y["prices"]["USD"])
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
abort("[rds][#{region}][#{@instance_type}] Not found ri-price?") unless ri_info
|
79
|
-
|
80
|
-
return ri_info
|
81
|
-
end
|
82
|
-
|
83
|
-
def price_url
|
84
|
-
@price_url
|
85
|
-
end
|
86
|
-
|
87
|
-
def om_price_file
|
88
|
-
return (@multiaz) ? "pricing-multiAZ-deployments.min.js" : "pricing-standard-deployments.min.js"
|
89
|
-
end
|
90
|
-
|
91
|
-
def ri_price_file
|
92
|
-
return "pricing-#{@ri_util}-utilization-reserved-instances.min.js"
|
93
|
-
end
|
94
|
-
|
95
|
-
def parse_contents data
|
96
|
-
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":')
|
97
|
-
return Yajl::Parser.parse(data)
|
98
|
-
end
|
99
|
-
|
100
|
-
def convert_region region
|
101
|
-
# not same om region
|
102
|
-
case region
|
103
|
-
when "us-east-1" then "us-east"
|
104
|
-
when "us-west-1" then "us-west"
|
105
|
-
when "us-west-2" then "us-west-2"
|
106
|
-
when "eu-west-1" then "eu-ireland"
|
107
|
-
when "ap-southeast-1" then "apac-sin"
|
108
|
-
when "ap-northeast-1" then "apac-tokyo"
|
109
|
-
when "ap-southeast-2" then "apac-syd"
|
110
|
-
when "sa-east-1" then "sa-east-1"
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|