ec2_pricing 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f565f497458d0376f0cc175ea6077e9df5e1cece
4
+ data.tar.gz: e6b09c759d48a93476591d23d1fcbc3a706aa2c2
5
+ SHA512:
6
+ metadata.gz: 7d43c5a93e580071b0680f1a9a855b7b6528b0b9c975a2d60cd1239a38c383c65f0fe4362d8da3970efab5a50803633df96fc24d88994f4c77b354275b50d4c4
7
+ data.tar.gz: fa5b5ac96da9468acc6a21684ad70b102ce33a4dd2219653a52196e7ac55701df11bc7c553960390558d27571c38e8daeb63aa2229a1348c60f107b3d0642d27
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ec2_pricing.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2014 Dave Lane
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # ec2_pricing
2
+
3
+ This gem provides a simple way to retrieve upfront and hourly costs for Amazon EC2 On Demand and Reserved Instances.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ec2_pricing'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ec2_pricing
18
+
19
+ ## Usage
20
+
21
+ For either type of instance, simply specify the region, instance type, and price type you'd like to see.
22
+
23
+ ### On Demand Pricing
24
+ instances = Ec2Pricing::Instances.on_demand
25
+ instances['us-east']['m3.medium']['hourly'] # hourly cost for an m3.medium On Demand Instance in US-East
26
+
27
+ ### Reserved Instance Pricing
28
+ instances = Ec2Pricing::Instances.reserved
29
+ instances['us-east']['m3.medium']['1yr']['upfront'] # upfront cost with a 1-year commitment
30
+ instances['us-east']['m3.medium']['1yr']['hourly'] # hourly cost with a 1-year commitment
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it ( https://github.com/NotDaveLane/ec2_pricing/fork )
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs = [File.expand_path("lib"), "test"]
6
+ t.test_files = FileList["test/**/*_test.rb"]
7
+ end
8
+
9
+ desc "Run tests"
10
+ task :default => :test
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ec2_pricing/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ec2_pricing"
8
+ spec.version = Ec2Pricing::VERSION
9
+ spec.authors = ["Dave Lane"]
10
+ spec.email = ["dclane@gmail.com"]
11
+ spec.summary = "Provides pricing information for Amazon EC2 instances."
12
+ spec.description = "Retrieves up-to-date pricing information for all types of Amazon EC2 instances."
13
+ spec.homepage = "https://github.com/NotDaveLane/ec2_pricing"
14
+ spec.license = "Apache 2.0"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,5 @@
1
+ require "ec2_pricing/instances"
2
+ require "ec2_pricing/version"
3
+
4
+ module Ec2Pricing
5
+ end
@@ -0,0 +1,61 @@
1
+ require 'json'
2
+ require 'open-uri'
3
+
4
+ module Ec2Pricing
5
+ class Instances
6
+
7
+ def self.on_demand
8
+ instances('http://aws-assets-pricing-prod.s3.amazonaws.com/pricing/ec2/linux-od.js')
9
+ end
10
+
11
+ def self.reserved
12
+ instances('http://aws-assets-pricing-prod.s3.amazonaws.com/pricing/ec2/linux-ri-heavy.js')
13
+ end
14
+
15
+
16
+ private
17
+
18
+ def self.instances(callback_url)
19
+ json = URI.parse(callback_url).read
20
+ json = json.sub('callback(', '').sub(')', '')
21
+ hash = JSON.parse(json)
22
+
23
+ instances = {}
24
+ for region in hash['config']['regions']
25
+ region_name = region['region']
26
+ instances[region_name] ||= {}
27
+
28
+ for instanceType in region['instanceTypes']
29
+
30
+ for size in instanceType['sizes']
31
+ instance_size = size['size']
32
+ instances[region_name][instance_size] ||= {}
33
+
34
+ for valueColumn in size['valueColumns']
35
+ # on-demand pricing has valueColumn names of 'linux' instead of a term length.
36
+ if valueColumn['name'] == 'linux'
37
+ instances[region_name][instance_size]['hourly'] = valueColumn['prices']['USD']
38
+ next
39
+ end
40
+
41
+ # change 'yrTerm1' to '1yr'
42
+ term = valueColumn['name'].sub('yrTerm', '') + 'yr'
43
+ price = valueColumn['prices']['USD']
44
+ rate = 'upfront'
45
+
46
+ # after the above name change, change 'yrTerm1Hourly to '1yr'
47
+ if term.include?('Hourly') || valueColumn['rate'].equal?('perhr')
48
+ term = term.sub('Hourly', '')
49
+ rate = 'hourly'
50
+ end
51
+
52
+ instances[region_name][instance_size][term] ||= {}
53
+ instances[region_name][instance_size][term][rate] = price
54
+ end
55
+ end
56
+ end
57
+ end
58
+ instances
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module Ec2Pricing
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,31 @@
1
+ require 'test/unit'
2
+ require 'ec2_pricing'
3
+
4
+ class PricingTest < Test::Unit::TestCase
5
+ def test_on_demand_instances_exist_with_hourly_costs
6
+ on_demand_instances = Ec2Pricing::Instances.on_demand
7
+
8
+ assert_not_nil on_demand_instances['us-east']['m3.xlarge']['hourly']
9
+ assert_not_nil on_demand_instances['us-west-2']['m3.medium']['hourly']
10
+
11
+ hourly_cost = on_demand_instances['us-west-2']['m3.medium']['hourly']
12
+ assert_equal hourly_cost.to_f, hourly_cost.to_f.to_s.to_f, 'hourly_cost #{hourly_cost} is not a float value.'
13
+
14
+ puts "Favorite Hourly: $#{'%.3f' % on_demand_instances['us-east']['m1.medium']['hourly']}"
15
+ end
16
+
17
+ def test_reserved_instances_exist_with_upfront_and_hourly_costs
18
+ reserved_instances = Ec2Pricing::Instances.reserved
19
+
20
+ assert_not_nil reserved_instances['us-east']['m3.xlarge']['1yr']['upfront']
21
+ assert_not_nil reserved_instances['us-east']['m3.xlarge']['1yr']['hourly']
22
+ assert_not_nil reserved_instances['us-west-1']['m3.2xlarge']['1yr']['upfront']
23
+ assert_not_nil reserved_instances['us-west-1']['m3.2xlarge']['1yr']['hourly']
24
+
25
+ upfront_cost = reserved_instances['us-west-1']['m3.2xlarge']['1yr']['upfront']
26
+ assert_equal upfront_cost.to_i, upfront_cost.to_i.to_s.to_i, 'upfront_cost #{upfront_cost} is not an integer value.'
27
+
28
+ puts "Favorite Upfront: $#{'%.2f' % reserved_instances['us-east']['m1.medium']['1yr']['upfront']}"
29
+ puts "Favorite Hourly: $#{'%.3f' % reserved_instances['us-east']['m1.medium']['1yr']['hourly']}"
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ec2_pricing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Dave Lane
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Retrieves up-to-date pricing information for all types of Amazon EC2
42
+ instances.
43
+ email:
44
+ - dclane@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - ec2_pricing.gemspec
55
+ - lib/ec2_pricing.rb
56
+ - lib/ec2_pricing/instances.rb
57
+ - lib/ec2_pricing/version.rb
58
+ - test/pricing_test.rb
59
+ homepage: https://github.com/NotDaveLane/ec2_pricing
60
+ licenses:
61
+ - Apache 2.0
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.2.0
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Provides pricing information for Amazon EC2 instances.
83
+ test_files:
84
+ - test/pricing_test.rb