aws-rikanjo 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b9d90bdadd842bad1a1bbfbbbf486bad44bbcf9
4
- data.tar.gz: 1b07ccdb4fd125d4d8483509285ae95245cbf70d
3
+ metadata.gz: 5e39d0ba3b787883c331691932e51813b98055b2
4
+ data.tar.gz: 00d5af893daf458683e57d2574901079598e03da
5
5
  SHA512:
6
- metadata.gz: c3dd0dc3f1144e3dd023ba7402762af14cca987bab740df1d7731322b78e683c05520b24135b6a3a1df600749619e689ade1e18f61d1666ff72396fb053b2a2f
7
- data.tar.gz: 3c04911fcc11868799fc96d46d19b30b4e2c46b5797b4f4eae4e1a1ec9e52f94d185fc394539255a17e19f8000ae4d8577c19c69fe8a84ba3d9099a3dba7425c
6
+ metadata.gz: 3759203ce15dbb3f7d5e28747fba747e72ae7dc581588fa5115c2dcf302d9e5f6790ddc2e0ae0c8d2e4a137acbc590f717be95b0b19094bccf94294d6a8dd45c
7
+ data.tar.gz: aebb9320d9cbb0212ade33ac3dee3168246e21c69bb83e44f50d4d382ba27c57b46dcc0dde3571724b26350d5dcd0405ba8f14fb0edfa75c67d21da3a260308b
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile CHANGED
@@ -7,3 +7,4 @@ gem 'net/http'
7
7
  gem 'uri'
8
8
  gem 'yajl'
9
9
  gem 'date'
10
+ gem 'rspec'
data/README.md CHANGED
@@ -39,6 +39,25 @@ a.total_cost_year
39
39
  # "sweet spot price (doller)" : 696.15
40
40
  ```
41
41
 
42
+ ## CLI Usage
43
+
44
+ help text:
45
+
46
+ ```
47
+ $ rikanjo --help
48
+ Usage: rikanjo [options]
49
+ -r, --region=VALUE specify aws-region (us-east-1/us-west-1/us-west-2/eu-west-1/ap-southeast-1/ap-northeast-1/ap-southeast-2/sa-east-1)
50
+ -t, --instance_type=VALUE specify ec2-instance-type
51
+ -u, --ri_util=VALUE specify ri-util (light/medium/heavy)
52
+ -h, --help
53
+ ```
54
+
55
+ example:
56
+
57
+ ```
58
+ $ rikanjo -r ap-northeast-1 -t c3.large -u medium
59
+ ```
60
+
42
61
  ## Contributing
43
62
 
44
63
  1. Fork it
data/Rakefile CHANGED
@@ -1 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ require "rspec/core/rake_task"
4
+ RSpec::Core::RakeTask.new("spec")
5
+ task :default => :spec
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.3"
8
+ spec.version = "0.0.4"
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.rb CHANGED
@@ -15,6 +15,8 @@ module Aws
15
15
  @ri_util = ri_util
16
16
  @om_info = Hash.new
17
17
  @ri_info = Hash.new
18
+ @current_price_url = 'http://a0.awsstatic.com/pricing/1/ec2'
19
+ @previous_price_url = 'http://a0.awsstatic.com/pricing/1/ec2/previous-generation'
18
20
  end
19
21
 
20
22
  def om_get_hr_price
@@ -40,7 +42,7 @@ module Aws
40
42
  end
41
43
 
42
44
  # TODO: merge om and ri
43
- uri = URI.parse('http://a0.awsstatic.com/pricing/1/ec2/linux-od.min.js')
45
+ uri = URI.parse("#{price_url}/linux-od.min.js")
44
46
  Net::HTTP.start(uri.host, uri.port) do |http|
45
47
  response = http.get(uri.request_uri)
46
48
  json = response.body
@@ -97,13 +99,13 @@ module Aws
97
99
  json = nil
98
100
  reservedjson_data = nil
99
101
 
100
- uri = URI.parse("http://a0.awsstatic.com/pricing/1/ec2/linux-ri-#{ri_util}.min.js")
102
+ uri = URI.parse("#{price_url}/#{ri_price_file}")
101
103
  Net::HTTP.start(uri.host, uri.port) do |http|
102
104
  response = http.get(uri.request_uri)
103
105
  json = response.body
104
106
  end
105
107
 
106
- json = json.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({vers:0.01,",'{').gsub("\);", '').gsub(/([a-zA-Z]+):/, '"\1":')
108
+ json = json.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":')
107
109
  reservedjson_data = Yajl::Parser.parse(json)
108
110
 
109
111
  reservedjson_data["config"]["regions"].each do |r|
@@ -181,6 +183,23 @@ module Aws
181
183
  puts "\"sweet spot date (date)\" : #{sweet_spot_date}"
182
184
  puts "\"sweet spot price (doller)\" : #{@ri_info[@ri_util][:sweet_spot_price]}"
183
185
  end
186
+
187
+ def price_url
188
+ return (previous_generation_type) ? @previous_price_url : @current_price_url
189
+ end
190
+
191
+ def ri_price_file
192
+ return (previous_generation_type) ? "#{@ri_util}_linux.min.js" : "linux-ri-#{@ri_util}.min.js"
193
+ end
194
+
195
+ def previous_generation_type
196
+ case @instance_type
197
+ when /^(c1|m2|cc2\.8xlarge|cr1\.8xlarge|hi1\.4xlarge|cg1\.4xlarge)/ then true
198
+ when /^m1/ then (@instance_type == "m1.small") ? false : true
199
+ else false
200
+ end
201
+ end
202
+
184
203
  end
185
204
  end
186
205
 
@@ -1,5 +1,5 @@
1
1
  module Aws
2
2
  module Rikanjo
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -0,0 +1,64 @@
1
+ require "spec_helper"
2
+ require "aws/rikanjo"
3
+
4
+ describe 'AWS::Rikanjo' do
5
+
6
+ it "is previous instance type" do
7
+ %w{ m1.medium c1.medium m2.xlarge cc2.8xlarge cr1.8xlarge hi1.4xlarge cg1.4xlarge }.each do |t|
8
+ a = Aws::RiKanjoo.new(
9
+ region = 'ap-northeast-1',
10
+ instance_type = t,
11
+ ri_util = 'light',
12
+ )
13
+ expect(a.previous_generation_type).to eq true
14
+ end
15
+ end
16
+
17
+ it "is current instance type" do
18
+ %w{ t1.micro m1.small m3.medium c3.medium r3.xlarge i2.xlarge }.each do |t|
19
+ a = Aws::RiKanjoo.new(
20
+ region = 'ap-northeast-1',
21
+ instance_type = t,
22
+ ri_util = 'light',
23
+ )
24
+ expect(a.previous_generation_type).to eq false
25
+ end
26
+ end
27
+
28
+ it "build previous price url" do
29
+ a = Aws::RiKanjoo.new(
30
+ region = 'ap-northeast-1',
31
+ instance_type = 'm1.medium',
32
+ ri_util = 'light',
33
+ )
34
+ expect(a.price_url).to eq "http://a0.awsstatic.com/pricing/1/ec2/previous-generation"
35
+ end
36
+
37
+ it "build current price url" do
38
+ a = Aws::RiKanjoo.new(
39
+ region = 'ap-northeast-1',
40
+ instance_type = 'm3.medium',
41
+ ri_util = 'light',
42
+ )
43
+ expect(a.price_url).to eq "http://a0.awsstatic.com/pricing/1/ec2"
44
+ end
45
+
46
+ it "build previous ri price file" do
47
+ a = Aws::RiKanjoo.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
+ end
54
+
55
+ it "build current ri price file" do
56
+ a = Aws::RiKanjoo.new(
57
+ region = 'ap-northeast-1',
58
+ instance_type = 'm3.medium',
59
+ ri_util = 'heavy',
60
+ )
61
+ expect(a.ri_price_file).to eq "linux-ri-heavy.min.js"
62
+ end
63
+
64
+ end
@@ -0,0 +1,8 @@
1
+ require 'rspec'
2
+
3
+ Dir["./support/**/*.rb"].each do |f|
4
+ require f
5
+ end
6
+
7
+ RSpec.configure do |config|
8
+ end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-rikanjo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - kenjiskywalker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-30 00:00:00.000000000 Z
11
+ date: 2014-05-05 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
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: AWS RI Cost Calc Tool
@@ -46,7 +46,8 @@ executables:
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
- - .gitignore
49
+ - ".gitignore"
50
+ - ".rspec"
50
51
  - Gemfile
51
52
  - LICENSE.txt
52
53
  - README.md
@@ -55,6 +56,8 @@ files:
55
56
  - bin/rikanjo
56
57
  - lib/aws/rikanjo.rb
57
58
  - lib/aws/rikanjo/version.rb
59
+ - spec/lib/rikanjo_spec.rb
60
+ - spec/spec_helper.rb
58
61
  homepage: https://github.com/kenjiskywalker/aws-rikanjo
59
62
  licenses:
60
63
  - MIT
@@ -65,18 +68,20 @@ require_paths:
65
68
  - lib
66
69
  required_ruby_version: !ruby/object:Gem::Requirement
67
70
  requirements:
68
- - - '>='
71
+ - - ">="
69
72
  - !ruby/object:Gem::Version
70
73
  version: '0'
71
74
  required_rubygems_version: !ruby/object:Gem::Requirement
72
75
  requirements:
73
- - - '>='
76
+ - - ">="
74
77
  - !ruby/object:Gem::Version
75
78
  version: '0'
76
79
  requirements: []
77
80
  rubyforge_project:
78
- rubygems_version: 2.1.11
81
+ rubygems_version: 2.2.2
79
82
  signing_key:
80
83
  specification_version: 4
81
84
  summary: calc 1 year cost. check sweet spot
82
- test_files: []
85
+ test_files:
86
+ - spec/lib/rikanjo_spec.rb
87
+ - spec/spec_helper.rb