aws-rikanjo 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/aws-rikanjo.gemspec +1 -1
- data/lib/aws/rikanjo/mode/ec2.rb +13 -2
- data/lib/aws/rikanjo/mode/rds.rb +8 -1
- data/lib/aws/rikanjo/version.rb +1 -1
- data/spec/lib/rikanjo_ec2_spec.rb +112 -47
- data/spec/lib/rikanjo_rds_spec.rb +121 -34
- data/spec/spec_helper.rb +22 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5befef7edf0fddafadcdc3beaa309c6d0f71df8
|
4
|
+
data.tar.gz: fa83ff4aed6413b0585a65da199529ae84627585
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4c6e04838a15bd76a5c08ebeabddbd35a8734c29826e2475483faff98bd1f89feae8b06b570fd0c53c53dbdccae3224c2cad436091b4d596b92c19c01a0bf70
|
7
|
+
data.tar.gz: c98edc88c7502955c1fee87ce792b2b9411a883b4a5c8bb58fa66f3057ae12574e6190222d0cfd1fbbfa819e56b5830d2212c079606fd2da19194360e826bbf4
|
data/aws-rikanjo.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'aws/rikanjo/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "aws-rikanjo"
|
8
|
-
spec.version = "0.0.
|
8
|
+
spec.version = "0.0.8"
|
9
9
|
spec.authors = ["kenjiskywalker"]
|
10
10
|
spec.email = ["git@kenjiskywalker.org"]
|
11
11
|
spec.description = %q{AWS RI Cost Calc Tool}
|
data/lib/aws/rikanjo/mode/ec2.rb
CHANGED
@@ -34,22 +34,26 @@ module Aws
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
abort("[ec2][#{region}][#{@instance_type}] Not found om-price?")
|
37
39
|
end
|
38
40
|
|
39
41
|
def ri_price_from_contents contents
|
40
|
-
region = @region
|
42
|
+
region = self.clean_region(@region)
|
41
43
|
|
42
44
|
# parse
|
43
45
|
json = self.parse_contents(contents)
|
44
46
|
|
45
|
-
ri_info =
|
47
|
+
ri_info = nil
|
46
48
|
|
47
49
|
json["config"]["regions"].each do |r|
|
48
50
|
next unless r["region"] == region
|
51
|
+
|
49
52
|
r["instanceTypes"].each do |type|
|
50
53
|
type["sizes"].each do |i|
|
51
54
|
next unless i["size"] == @instance_type
|
52
55
|
|
56
|
+
ri_info = ri_info || {}
|
53
57
|
i["valueColumns"].each do |y|
|
54
58
|
case y["name"]
|
55
59
|
when "yrTerm1"
|
@@ -62,6 +66,8 @@ module Aws
|
|
62
66
|
end
|
63
67
|
end
|
64
68
|
|
69
|
+
abort("[ec2][#{region}][#{@instance_type}] Not found ri-price?") unless ri_info
|
70
|
+
|
65
71
|
return ri_info
|
66
72
|
end
|
67
73
|
|
@@ -95,6 +101,7 @@ module Aws
|
|
95
101
|
case region
|
96
102
|
when "us-east-1" then "us-east"
|
97
103
|
when "us-west-1" then "us-west"
|
104
|
+
when "us-west-2" then "us-west-2"
|
98
105
|
when "eu-west-1" then "eu-ireland"
|
99
106
|
when "ap-southeast-1" then "apac-sin"
|
100
107
|
when "ap-northeast-1" then "apac-tokyo"
|
@@ -103,6 +110,10 @@ module Aws
|
|
103
110
|
end
|
104
111
|
end
|
105
112
|
|
113
|
+
def clean_region region
|
114
|
+
return region.gsub(/^us-east-1$/, 'us-east')
|
115
|
+
end
|
116
|
+
|
106
117
|
end
|
107
118
|
end
|
108
119
|
end
|
data/lib/aws/rikanjo/mode/rds.rb
CHANGED
@@ -32,6 +32,8 @@ module Aws
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
35
|
+
|
36
|
+
abort("[rds][#{region}][#{@instance_type}] Not found om-price?")
|
35
37
|
end
|
36
38
|
|
37
39
|
def ri_price_from_contents contents
|
@@ -41,7 +43,7 @@ module Aws
|
|
41
43
|
# parse
|
42
44
|
json = self.parse_contents(contents)
|
43
45
|
|
44
|
-
ri_info =
|
46
|
+
ri_info = nil
|
45
47
|
|
46
48
|
json["config"]["regions"].each do |r|
|
47
49
|
next unless r["region"] == region
|
@@ -55,6 +57,7 @@ module Aws
|
|
55
57
|
type["tiers"].each do |i|
|
56
58
|
next unless i["size"] == @instance_type
|
57
59
|
|
60
|
+
ri_info = ri_info || {}
|
58
61
|
i["valueColumns"].each do |y|
|
59
62
|
# beauty
|
60
63
|
y["name"].gsub!(/^year/, 'yr')
|
@@ -72,6 +75,8 @@ module Aws
|
|
72
75
|
end
|
73
76
|
end
|
74
77
|
|
78
|
+
abort("[rds][#{region}][#{@instance_type}] Not found ri-price?") unless ri_info
|
79
|
+
|
75
80
|
return ri_info
|
76
81
|
end
|
77
82
|
|
@@ -97,6 +102,7 @@ module Aws
|
|
97
102
|
case region
|
98
103
|
when "us-east-1" then "us-east"
|
99
104
|
when "us-west-1" then "us-west"
|
105
|
+
when "us-west-2" then "us-west-2"
|
100
106
|
when "eu-west-1" then "eu-ireland"
|
101
107
|
when "ap-southeast-1" then "apac-sin"
|
102
108
|
when "ap-northeast-1" then "apac-tokyo"
|
@@ -104,6 +110,7 @@ module Aws
|
|
104
110
|
when "sa-east-1" then "sa-east-1"
|
105
111
|
end
|
106
112
|
end
|
113
|
+
|
107
114
|
end
|
108
115
|
end
|
109
116
|
end
|
data/lib/aws/rikanjo/version.rb
CHANGED
@@ -1,64 +1,129 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
require "aws/rikanjo/mode/ec2"
|
3
3
|
|
4
|
+
include RikanjoSpecHelper
|
5
|
+
|
4
6
|
describe 'AWS::Rikanjo::Mode::Ec2' do
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
describe 'previous type' do
|
9
|
+
it "is previous instance type" do
|
10
|
+
%w{ m1.medium c1.medium m2.xlarge cc2.8xlarge cr1.8xlarge hi1.4xlarge cg1.4xlarge }.each do |t|
|
11
|
+
a = Aws::RiKanjoo::Mode::Ec2.new(
|
12
|
+
region = 'ap-northeast-1',
|
13
|
+
instance_type = t,
|
14
|
+
ri_util = 'light',
|
15
|
+
)
|
16
|
+
expect(a.previous_generation_type).to eq true
|
17
|
+
end
|
14
18
|
end
|
15
|
-
end
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
it "is current instance type" do
|
21
|
+
%w{ t1.micro m1.small m3.medium c3.medium r3.xlarge i2.xlarge }.each do |t|
|
22
|
+
a = Aws::RiKanjoo::Mode::Ec2.new(
|
23
|
+
region = 'ap-northeast-1',
|
24
|
+
instance_type = t,
|
25
|
+
ri_util = 'light',
|
26
|
+
)
|
27
|
+
expect(a.previous_generation_type).to eq false
|
28
|
+
end
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
describe 'url' do
|
33
|
+
it "build previous price url" do
|
34
|
+
a = Aws::RiKanjoo::Mode::Ec2.new(
|
35
|
+
region = 'ap-northeast-1',
|
36
|
+
instance_type = 'm1.medium',
|
37
|
+
ri_util = 'light',
|
38
|
+
)
|
39
|
+
expect(a.price_url).to eq "http://a0.awsstatic.com/pricing/1/ec2/previous-generation"
|
40
|
+
end
|
36
41
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
it "build current price url" do
|
43
|
+
a = Aws::RiKanjoo::Mode::Ec2.new(
|
44
|
+
region = 'ap-northeast-1',
|
45
|
+
instance_type = 'm3.medium',
|
46
|
+
ri_util = 'light',
|
47
|
+
)
|
48
|
+
expect(a.price_url).to eq "http://a0.awsstatic.com/pricing/1/ec2"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "build previous ri price file" do
|
52
|
+
a = Aws::RiKanjoo::Mode::Ec2.new(
|
53
|
+
region = 'ap-northeast-1',
|
54
|
+
instance_type = 'm1.medium',
|
55
|
+
ri_util = 'light',
|
56
|
+
)
|
57
|
+
expect(a.ri_price_file).to eq "light_linux.min.js"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "build current ri price file" do
|
61
|
+
a = Aws::RiKanjoo::Mode::Ec2.new(
|
62
|
+
region = 'ap-northeast-1',
|
63
|
+
instance_type = 'm3.medium',
|
64
|
+
ri_util = 'heavy',
|
65
|
+
)
|
66
|
+
expect(a.ri_price_file).to eq "linux-ri-heavy.min.js"
|
67
|
+
end
|
45
68
|
|
46
|
-
it "build previous ri price file" do
|
47
|
-
a = Aws::RiKanjoo::Mode::Ec2.new(
|
48
|
-
region = 'ap-northeast-1',
|
49
|
-
instance_type = 'm1.medium',
|
50
|
-
ri_util = 'light',
|
51
|
-
)
|
52
|
-
expect(a.ri_price_file).to eq "light_linux.min.js"
|
53
69
|
end
|
54
70
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
71
|
+
describe 'contents validation' do
|
72
|
+
|
73
|
+
before :all do
|
74
|
+
# rikanjo (current)
|
75
|
+
a1 = Aws::RiKanjoo::Mode::Ec2.new(
|
76
|
+
region = 'ap-northeast-1',
|
77
|
+
instance_type = 'm3.medium',
|
78
|
+
ri_util = 'medium',
|
79
|
+
)
|
80
|
+
# rikanjo (previous)
|
81
|
+
a2 = Aws::RiKanjoo::Mode::Ec2.new(
|
82
|
+
region = 'ap-northeast-1',
|
83
|
+
instance_type = 'm1.medium',
|
84
|
+
ri_util = 'medium',
|
85
|
+
)
|
86
|
+
@c_om_current_price = get_sleep("#{a1.price_url}/#{a1.om_price_file}")
|
87
|
+
@c_ri_current_medium_price = get_sleep("#{a1.price_url}/#{a1.ri_price_file}")
|
88
|
+
@c_om_previous_price = get_sleep("#{a2.price_url}/#{a2.om_price_file}")
|
89
|
+
@c_ri_previous_medium_price = get_sleep("#{a2.price_url}/#{a2.ri_price_file}")
|
90
|
+
end
|
91
|
+
|
92
|
+
it "is able to get the price" do
|
93
|
+
regions.each do |region|
|
94
|
+
a = Aws::RiKanjoo::Mode::Ec2.new(
|
95
|
+
region = region,
|
96
|
+
instance_type = 'm3.large',
|
97
|
+
ri_util = 'medium',
|
98
|
+
)
|
99
|
+
# om
|
100
|
+
om_info = a.om_price_from_contents(@c_om_current_price)
|
101
|
+
expect(om_info[:hr_price]).not_to be_nil
|
102
|
+
# ri
|
103
|
+
ri_info = a.ri_price_from_contents(@c_ri_current_medium_price)
|
104
|
+
expect(ri_info["medium"][:upfront]).not_to be_nil
|
105
|
+
expect(ri_info["medium"][:hr_price]).not_to be_nil
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
it "an exception is raised when there are no instance-type" do
|
110
|
+
regions.each do |region|
|
111
|
+
a = Aws::RiKanjoo::Mode::Ec2.new(
|
112
|
+
region = region,
|
113
|
+
instance_type = 'm3.large.not.exists',
|
114
|
+
ri_util = 'medium',
|
115
|
+
)
|
116
|
+
# raise om
|
117
|
+
expect do
|
118
|
+
om_info = a.om_price_from_contents(@c_om_current_price)
|
119
|
+
end.to raise_error(SystemExit)
|
120
|
+
# raise ri
|
121
|
+
expect do
|
122
|
+
ri_info = a.ri_price_from_contents(@c_ri_current_medium_price)
|
123
|
+
end.to raise_error(SystemExit)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
62
127
|
end
|
63
128
|
|
64
129
|
end
|
@@ -1,46 +1,133 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
require "aws/rikanjo/mode/rds"
|
3
3
|
|
4
|
+
include RikanjoSpecHelper
|
5
|
+
|
4
6
|
describe 'AWS::Rikanjo::Mode::Rds' do
|
5
7
|
|
6
|
-
|
7
|
-
a = Aws::RiKanjoo::Mode::Rds.new(
|
8
|
-
region = 'ap-northeast-1',
|
9
|
-
instance_type = 'm3.large',
|
10
|
-
ri_util = 'light',
|
11
|
-
multiaz = false,
|
12
|
-
)
|
13
|
-
expect(a.price_url).to eq "https://a0.awsstatic.com/pricing/1/rds/mysql"
|
14
|
-
end
|
8
|
+
describe 'url' do
|
15
9
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
10
|
+
it "build current price url" do
|
11
|
+
a = Aws::RiKanjoo::Mode::Rds.new(
|
12
|
+
region = 'ap-northeast-1',
|
13
|
+
instance_type = 'm3.large',
|
14
|
+
ri_util = 'light',
|
15
|
+
multiaz = false,
|
16
|
+
)
|
17
|
+
expect(a.price_url).to eq "https://a0.awsstatic.com/pricing/1/rds/mysql"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "build current om price file" do
|
21
|
+
a = Aws::RiKanjoo::Mode::Rds.new(
|
22
|
+
region = 'ap-northeast-1',
|
23
|
+
instance_type = 'm2.xlarge',
|
24
|
+
ri_util = 'medium',
|
25
|
+
multiaz = false,
|
26
|
+
)
|
27
|
+
expect(a.om_price_file).to eq "pricing-standard-deployments.min.js"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "build current om price file(multiaz)" do
|
31
|
+
a = Aws::RiKanjoo::Mode::Rds.new(
|
32
|
+
region = 'ap-northeast-1',
|
33
|
+
instance_type = 'm2.xlarge',
|
34
|
+
ri_util = 'medium',
|
35
|
+
multiaz = true,
|
36
|
+
)
|
37
|
+
expect(a.om_price_file).to eq "pricing-multiAZ-deployments.min.js"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "build current ri price file" do
|
41
|
+
a = Aws::RiKanjoo::Mode::Rds.new(
|
42
|
+
region = 'ap-northeast-1',
|
43
|
+
instance_type = 'm2.xlarge',
|
44
|
+
ri_util = 'medium',
|
45
|
+
multiaz = true,
|
46
|
+
)
|
47
|
+
expect(a.ri_price_file).to eq "pricing-medium-utilization-reserved-instances.min.js"
|
48
|
+
end
|
25
49
|
|
26
|
-
it "build current om price file(multiaz)" do
|
27
|
-
a = Aws::RiKanjoo::Mode::Rds.new(
|
28
|
-
region = 'ap-northeast-1',
|
29
|
-
instance_type = 'm2.xlarge',
|
30
|
-
ri_util = 'medium',
|
31
|
-
multiaz = true,
|
32
|
-
)
|
33
|
-
expect(a.om_price_file).to eq "pricing-multiAZ-deployments.min.js"
|
34
50
|
end
|
35
51
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
52
|
+
|
53
|
+
describe 'contents validation' do
|
54
|
+
|
55
|
+
before :all do
|
56
|
+
# rikanjo (single-az)
|
57
|
+
a1 = Aws::RiKanjoo::Mode::Rds.new(
|
58
|
+
region = 'ap-northeast-1',
|
59
|
+
instance_type = 'm3.medium',
|
60
|
+
ri_util = 'medium',
|
61
|
+
multiaz = false,
|
62
|
+
)
|
63
|
+
# rikanjo (multi-az)
|
64
|
+
a2 = Aws::RiKanjoo::Mode::Rds.new(
|
65
|
+
region = 'ap-northeast-1',
|
66
|
+
instance_type = 'm3.medium',
|
67
|
+
ri_util = 'medium',
|
68
|
+
multiaz = true,
|
69
|
+
)
|
70
|
+
@c_om_singleaz_price = get_sleep("#{a1.price_url}/#{a1.om_price_file}")
|
71
|
+
@c_ri_medium_price = get_sleep("#{a1.price_url}/#{a1.ri_price_file}")
|
72
|
+
@c_om_multiaz_price = get_sleep("#{a2.price_url}/#{a2.om_price_file}")
|
73
|
+
end
|
74
|
+
|
75
|
+
it "is able to get the price(singleaz)" do
|
76
|
+
regions.each do |region|
|
77
|
+
a = Aws::RiKanjoo::Mode::Rds.new(
|
78
|
+
region = region,
|
79
|
+
instance_type = 'm3.large',
|
80
|
+
ri_util = 'medium',
|
81
|
+
multiaz = false,
|
82
|
+
)
|
83
|
+
# om
|
84
|
+
om_info = a.om_price_from_contents(@c_om_singleaz_price)
|
85
|
+
expect(om_info[:hr_price]).not_to be_nil
|
86
|
+
|
87
|
+
# ri
|
88
|
+
ri_info = a.ri_price_from_contents(@c_ri_medium_price)
|
89
|
+
expect(ri_info["medium"][:upfront]).not_to be_nil
|
90
|
+
expect(ri_info["medium"][:hr_price]).not_to be_nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it "is able to get the price(multiaz)" do
|
95
|
+
regions.each do |region|
|
96
|
+
a = Aws::RiKanjoo::Mode::Rds.new(
|
97
|
+
region = region,
|
98
|
+
instance_type = 'm3.large',
|
99
|
+
ri_util = 'medium',
|
100
|
+
multiaz = true,
|
101
|
+
)
|
102
|
+
# om
|
103
|
+
om_info = a.om_price_from_contents(@c_om_multiaz_price)
|
104
|
+
expect(om_info[:hr_price]).not_to be_nil
|
105
|
+
|
106
|
+
# ri
|
107
|
+
ri_info = a.ri_price_from_contents(@c_ri_medium_price)
|
108
|
+
expect(ri_info["medium"][:upfront]).not_to be_nil
|
109
|
+
expect(ri_info["medium"][:hr_price]).not_to be_nil
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
it "an exception is raised when there are no instance-type" do
|
114
|
+
regions.each do |region|
|
115
|
+
a = Aws::RiKanjoo::Mode::Rds.new(
|
116
|
+
region = region,
|
117
|
+
instance_type = 'm3.large.not.exists',
|
118
|
+
ri_util = 'medium',
|
119
|
+
multiaz = false,
|
120
|
+
)
|
121
|
+
# raise om
|
122
|
+
expect do
|
123
|
+
om_info = a.om_price_from_contents(@c_om_singleaz_price)
|
124
|
+
end.to raise_error(SystemExit)
|
125
|
+
# raise ri
|
126
|
+
expect do
|
127
|
+
ri_info = a.ri_price_from_contents(@c_ri_medium_price)
|
128
|
+
end.to raise_error(SystemExit)
|
129
|
+
end
|
130
|
+
end
|
44
131
|
end
|
45
132
|
|
46
133
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -6,3 +6,25 @@ end
|
|
6
6
|
|
7
7
|
RSpec.configure do |config|
|
8
8
|
end
|
9
|
+
|
10
|
+
module RikanjoSpecHelper
|
11
|
+
def regions
|
12
|
+
return %w{
|
13
|
+
eu-west-1
|
14
|
+
sa-east-1
|
15
|
+
us-east-1
|
16
|
+
ap-northeast-1
|
17
|
+
us-west-2
|
18
|
+
us-west-1
|
19
|
+
ap-southeast-1
|
20
|
+
ap-southeast-2
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_sleep url
|
25
|
+
contents = Net::HTTP.get(URI.parse(url))
|
26
|
+
sleep 1
|
27
|
+
return contents
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kenjiskywalker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|