ec2spec 0.1.1 → 0.1.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 +4 -4
- data/.travis.yml +9 -2
- data/CHANGELOG.md +17 -0
- data/Gemfile.lock +1 -1
- data/README.md +82 -14
- data/ec2spec.gemspec +0 -3
- data/lib/ec2spec/cli.rb +13 -3
- data/lib/ec2spec/client.rb +32 -41
- data/lib/ec2spec/const.rb +5 -0
- data/lib/ec2spec/hash_formatter.rb +11 -0
- data/lib/ec2spec/host_result.rb +36 -4
- data/lib/ec2spec/json_formatter.rb +12 -0
- data/lib/ec2spec/logger.rb +10 -0
- data/lib/ec2spec/offer_file.rb +44 -22
- data/lib/ec2spec/offer_index_file.rb +60 -0
- data/lib/ec2spec/plain_text_formatter.rb +23 -0
- data/lib/ec2spec/version.rb +1 -1
- data/lib/ec2spec.rb +5 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f654ed96111dcd1d53c9518fbf643b443d3ff727
|
4
|
+
data.tar.gz: 21342c52833a9f060f19de8318ad1f6cd5a35d2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56b4f3e02cd6b46d652cafdc9ea549bb82bc6d265ac339fd65c6d6d115e877f1510c2b0eda5a31becd75f727c29953e70e3f02c2de0fd07cbbfc5f549c8959c1
|
7
|
+
data.tar.gz: 04fde02c25dbebf9faa24036bb02fe14a9cce4d94f0b0e7de66f6590981ea5f49261811364afd6aeda4944a8a620d8c94c51ca818bb002f17347ba2815344554
|
data/.travis.yml
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
|
-
- 2.3.
|
5
|
-
|
4
|
+
- 2.3.0
|
5
|
+
- 2.4.0
|
6
|
+
- 2.5.0
|
7
|
+
before_install:
|
8
|
+
- gem install bundler -v 1.16.1
|
9
|
+
- gem install rubocop
|
10
|
+
script:
|
11
|
+
- rubocop --fail-level=W
|
12
|
+
- bundle exec rspec
|
data/CHANGELOG.md
ADDED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,34 +1,102 @@
|
|
1
1
|
# ec2spec
|
2
2
|
|
3
|
-
|
3
|
+
[](https://badge.fury.io/rb/ec2spec)
|
4
|
+
[](https://travis-ci.org/kyoshidajp/ec2spec)
|
5
|
+
[][license]
|
4
6
|
|
5
|
-
|
7
|
+
[license]: https://github.com/kyoshidajp/ec2spec/blob/master/LICENSE
|
8
|
+
|
9
|
+
ec2spec is a simple comparison tool for Amazon EC2 Instances you can access.
|
10
|
+
|
11
|
+
Supports the following items.
|
12
|
+
|
13
|
+
| item | from |
|
14
|
+
| :------- | :------ |
|
15
|
+
| instance type | host |
|
16
|
+
| instance id | host |
|
17
|
+
| vCPU | AWS Price List API |
|
18
|
+
| memory | AWS Price List API |
|
19
|
+
| price | AWS Price List API |
|
20
|
+
|
21
|
+
The target host must be accessible from the machine. Also, only On-Demand way and Linux machine.
|
6
22
|
|
7
23
|
## Installation
|
8
24
|
|
9
|
-
|
25
|
+
```
|
26
|
+
$ gem install ec2spec
|
27
|
+
```
|
10
28
|
|
11
|
-
|
12
|
-
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
```
|
32
|
+
$ ec2spec ssh -h host1 ... [options]
|
13
33
|
```
|
14
34
|
|
15
|
-
|
35
|
+
### Options
|
36
|
+
|
37
|
+
```
|
38
|
+
-h, --host Target hosts name.
|
16
39
|
|
17
|
-
|
40
|
+
--days How many days per one month.
|
18
41
|
|
19
|
-
|
42
|
+
--format Output format (default: plain_text).
|
43
|
+
plain_text, json, hash
|
20
44
|
|
21
|
-
|
45
|
+
--region Region of EC2 (default: ap-northeast-1).
|
22
46
|
|
23
|
-
|
47
|
+
--debug Output logs as DEBUG level.
|
48
|
+
```
|
49
|
+
|
50
|
+
### Example
|
51
|
+
|
52
|
+
```
|
53
|
+
$ ec2spec ssh -h host1 host2 host3
|
54
|
+
```
|
55
|
+
|
56
|
+
```
|
57
|
+
I, [2018-08-12T20:54:25.814752 #64341] INFO -- : Started: host1
|
58
|
+
I, [2018-08-12T20:54:25.814835 #64341] INFO -- : Started: host2
|
59
|
+
I, [2018-08-12T20:54:25.814867 #64341] INFO -- : Started: host3
|
60
|
+
I, [2018-08-12T20:54:25.826113 #64341] INFO -- : Finished: host3
|
61
|
+
I, [2018-08-12T20:54:29.385848 #64341] INFO -- : Finished: host1
|
62
|
+
I, [2018-08-12T20:54:37.560003 #64341] INFO -- : Finished: host2
|
63
|
+
+---------------+-------------+-------------+-------+
|
64
|
+
| | host1 | host2 | host3 |
|
65
|
+
+---------------+-------------+-------------|-------+
|
66
|
+
| instance_type | t2.micro | c4.2xlarge | N/A |
|
67
|
+
| instance_id | i-xxxxxxxx | i-yyyyyyyy | N/A |
|
68
|
+
| vCPU | 1 | 8 | N/A |
|
69
|
+
| memory | 1 GiB | 15 GiB | N/A |
|
70
|
+
| price (USD/H) | 0.0152 | 0.504 | N/A |
|
71
|
+
| price (USD/M) | 11.3088 | 374.976 | N/A |
|
72
|
+
+---------------+-------------+---------------------+
|
73
|
+
```
|
74
|
+
|
75
|
+
The data of `host3` could not be acquired due to some error.
|
76
|
+
|
77
|
+
## As a library
|
78
|
+
|
79
|
+
```
|
80
|
+
> require 'ec2spec'
|
81
|
+
> hosts = %w[host1 host2]
|
82
|
+
> client = Ec2spec::Client.new(hosts, 30, 'hash')
|
83
|
+
> result_json = client.run
|
84
|
+
> puts result_json
|
85
|
+
I, [2018-08-12T20:54:25.814752 #64341] INFO -- : Started: host1
|
86
|
+
I, [2018-08-12T20:54:25.814835 #64341] INFO -- : Started: host2
|
87
|
+
I, [2018-08-12T20:54:29.385848 #64341] INFO -- : Finished: host1
|
88
|
+
I, [2018-08-12T20:54:37.560003 #64341] INFO -- : Finished: host2
|
89
|
+
=> {"host1":{"instance_type":"t2.micro","instance_id":"i-xxxxxxxx","vCPU":"1","memory":"1 GiB","price (USD/H)":0.152,"price (USD/M)":11.3088},"host2":{"instance_type":"c4.2xlarge","instance_id":"i-yyyyyyyy","vCPU":"8","memory":"15 GiB","price (USD/H)":0.504,"price (USD/M)":374.976}}
|
90
|
+
```
|
24
91
|
|
25
|
-
|
92
|
+
## Requirement
|
26
93
|
|
27
|
-
|
94
|
+
- Ruby(MRI) 2.3.0 or higher
|
28
95
|
|
29
|
-
|
96
|
+
## Competitors
|
30
97
|
|
31
|
-
|
98
|
+
- [Amazon Web Services Simple Monthly Calculator](https://calculator.s3.amazonaws.com/index.html)
|
99
|
+
- [Amazon EC2 Instance Comparison](https://www.ec2instances.info/)
|
32
100
|
|
33
101
|
## Contributing
|
34
102
|
|
data/ec2spec.gemspec
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
lib = File.expand_path('lib', __dir__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
3
|
require 'ec2spec/version'
|
4
|
-
|
5
|
-
# rubocop:disable Metrics/BlockLength
|
6
4
|
Gem::Specification.new do |spec|
|
7
5
|
spec.name = 'ec2spec'
|
8
6
|
spec.version = Ec2spec::VERSION
|
@@ -31,4 +29,3 @@ Gem::Specification.new do |spec|
|
|
31
29
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
32
30
|
spec.add_development_dependency 'rubocop'
|
33
31
|
end
|
34
|
-
# rubocop:enable Metrics/BlockLength
|
data/lib/ec2spec/cli.rb
CHANGED
@@ -2,14 +2,24 @@ require 'thor'
|
|
2
2
|
|
3
3
|
module Ec2spec
|
4
4
|
class CLI < Thor
|
5
|
-
desc 'ssh
|
5
|
+
desc 'ssh -h host1 ...', 'Compare the specifications of EC2 instances.'
|
6
6
|
option 'host', aliases: 'h', type: :array, equired: true
|
7
7
|
option 'days', type: :numeric
|
8
|
+
option 'format'
|
9
|
+
option 'region'
|
10
|
+
option 'debug', type: :boolean
|
11
|
+
|
12
|
+
# rubocop:disable Metrics/AbcSize
|
8
13
|
def ssh
|
9
14
|
hosts = options['host']
|
10
15
|
days = options['days']
|
11
|
-
|
12
|
-
|
16
|
+
format = options['format'] || :plain_text
|
17
|
+
region = options['region'] || 'ap-northeast-1'
|
18
|
+
|
19
|
+
Ec2spec.logger.level = Logger::DEBUG if options['debug']
|
20
|
+
client = Ec2spec::Client.new(hosts, days, format, region)
|
21
|
+
puts client.run
|
13
22
|
end
|
23
|
+
# rubocop:enable Metrics/AbcSize
|
14
24
|
end
|
15
25
|
end
|
data/lib/ec2spec/client.rb
CHANGED
@@ -1,25 +1,30 @@
|
|
1
|
-
require '
|
1
|
+
require 'ec2spec/json_formatter'
|
2
|
+
require 'ec2spec/plain_text_formatter'
|
3
|
+
require 'ec2spec/hash_formatter'
|
2
4
|
|
3
5
|
module Ec2spec
|
6
|
+
class UndefineFormatterError < StandardError; end
|
7
|
+
|
4
8
|
class Client
|
5
9
|
META_DATA_URL_BASE = 'http://169.254.169.254/latest/meta-data/'
|
6
10
|
META_DATA_INSTANCE_TYPE_PATH = '/instance-type'
|
7
11
|
META_DATA_INSTANCE_ID_PATH = '/instance-id'
|
12
|
+
DEFAULT_REGION = 'ap-northeast-1'
|
8
13
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
'price (USD/H)' => :price_per_unit,
|
14
|
-
'price (USD/M)' => :price_per_month,
|
14
|
+
OUTPUT_FORMATTERS = {
|
15
|
+
plain_text: PlainTextFormatter,
|
16
|
+
json: JsonFormatter,
|
17
|
+
hash: HashFormatter,
|
15
18
|
}
|
16
19
|
|
17
|
-
def initialize(hosts, days)
|
18
|
-
@log = Logger.new(STDOUT)
|
19
|
-
@log.level = Logger::INFO
|
20
|
-
|
20
|
+
def initialize(hosts, days, format, region = DEFAULT_REGION)
|
21
21
|
@hosts = hosts
|
22
22
|
@days = days
|
23
|
+
@format = format
|
24
|
+
@region = region
|
25
|
+
|
26
|
+
extend_formatter
|
27
|
+
OfferFile.instance.prepare(@region)
|
23
28
|
end
|
24
29
|
|
25
30
|
def run
|
@@ -29,24 +34,34 @@ module Ec2spec
|
|
29
34
|
exec_host_result(host, backend)
|
30
35
|
end
|
31
36
|
end
|
32
|
-
|
33
|
-
output
|
37
|
+
results = threads.each(&:join).map(&:value)
|
38
|
+
output(results, @hosts)
|
34
39
|
end
|
35
40
|
|
36
41
|
private
|
37
42
|
|
43
|
+
def extend_formatter
|
44
|
+
format_sym = begin
|
45
|
+
@format.to_sym
|
46
|
+
rescue NoMethodError
|
47
|
+
raise UndefineFormatterError
|
48
|
+
end
|
49
|
+
|
50
|
+
raise UndefineFormatterError unless OUTPUT_FORMATTERS.key?(format_sym)
|
51
|
+
extend OUTPUT_FORMATTERS[format_sym]
|
52
|
+
end
|
53
|
+
|
38
54
|
def exec_host_result(host, backend)
|
39
|
-
|
55
|
+
Ec2spec.logger.info("Started: #{host.host}")
|
40
56
|
|
41
57
|
begin
|
42
58
|
host.instance_type = instance_type(backend)
|
43
59
|
host.instance_id = instance_id(backend)
|
44
|
-
host.memory = memory(backend)
|
45
60
|
rescue Errno::ECONNREFUSED
|
46
61
|
host.na_values
|
47
62
|
end
|
48
63
|
|
49
|
-
|
64
|
+
Ec2spec.logger.info("Finished: #{host.host}")
|
50
65
|
host
|
51
66
|
end
|
52
67
|
|
@@ -72,39 +87,15 @@ module Ec2spec
|
|
72
87
|
"curl -s #{metadata_url(META_DATA_INSTANCE_ID_PATH)}"
|
73
88
|
end
|
74
89
|
|
75
|
-
def memory(backend)
|
76
|
-
Specinfra::HostInventory::Memory.new(backend.host_inventory).get['total']
|
77
|
-
end
|
78
|
-
|
79
90
|
def target(host_name)
|
80
91
|
ssh_options = Net::SSH::Config.for(host_name)
|
81
92
|
backend = Specinfra::Backend::Ssh.new(
|
82
93
|
host: ssh_options[:host_name],
|
83
94
|
ssh_options: ssh_options,
|
84
95
|
)
|
85
|
-
host = Ec2spec::HostResult.new(host_name, @days)
|
96
|
+
host = Ec2spec::HostResult.new(@region, host_name, @days)
|
86
97
|
host.backend = backend
|
87
98
|
host
|
88
99
|
end
|
89
|
-
|
90
|
-
def output
|
91
|
-
results = @results.map(&:value)
|
92
|
-
table = Terminal::Table.new
|
93
|
-
table.headings = table_header(results)
|
94
|
-
table.rows = table_rows(results)
|
95
|
-
column_count = @hosts.size + 1
|
96
|
-
column_count.times { |i| table.align_column(i, :right) }
|
97
|
-
puts table
|
98
|
-
end
|
99
|
-
|
100
|
-
def table_header(results)
|
101
|
-
[''].concat(results.map(&:host))
|
102
|
-
end
|
103
|
-
|
104
|
-
def table_rows(results)
|
105
|
-
TABLE_LABEL_WITH_METHODS.each_with_object([]) do |(k, v), row|
|
106
|
-
row << [k].concat(results.map(&v))
|
107
|
-
end
|
108
|
-
end
|
109
100
|
end
|
110
101
|
end
|
data/lib/ec2spec/host_result.rb
CHANGED
@@ -3,11 +3,21 @@ module Ec2spec
|
|
3
3
|
MONTH_OF_DAYS = 31
|
4
4
|
NA_VALUE = 'N/A'
|
5
5
|
|
6
|
-
|
6
|
+
LABEL_WITH_METHODS = {
|
7
|
+
'instance_type' => :instance_type,
|
8
|
+
'instance_id' => :instance_id,
|
9
|
+
'vCPU' => :vcpu,
|
10
|
+
'memory' => :memory,
|
11
|
+
'price (USD/H)' => :price_per_unit,
|
12
|
+
'price (USD/M)' => :price_per_month,
|
13
|
+
}
|
14
|
+
|
15
|
+
attr_accessor :host, :backend, :instance_id, :cpu
|
7
16
|
attr_reader :instance_type
|
8
17
|
attr_writer :price_per_unit
|
9
18
|
|
10
|
-
def initialize(host, days = nil)
|
19
|
+
def initialize(region, host, days = nil)
|
20
|
+
@region = region
|
11
21
|
@host = host
|
12
22
|
@backend = nil
|
13
23
|
@days = days || MONTH_OF_DAYS
|
@@ -25,17 +35,39 @@ module Ec2spec
|
|
25
35
|
@instance_type = value
|
26
36
|
|
27
37
|
return if value == NA_VALUE
|
28
|
-
@offer_file = Ec2spec::OfferFile.new(value)
|
29
38
|
price_per_unit
|
30
39
|
end
|
31
40
|
|
41
|
+
def vcpu
|
42
|
+
@vcpu ||=
|
43
|
+
Ec2spec::OfferFile.instance.vcpu(@instance_type)
|
44
|
+
end
|
45
|
+
|
46
|
+
def memory
|
47
|
+
@memory ||=
|
48
|
+
Ec2spec::OfferFile.instance.memory(@instance_type)
|
49
|
+
end
|
50
|
+
|
32
51
|
def price_per_unit
|
33
|
-
@price_per_unit ||=
|
52
|
+
@price_per_unit ||=
|
53
|
+
Ec2spec::OfferFile.instance.price_per_unit(@instance_type)
|
34
54
|
end
|
35
55
|
|
36
56
|
def price_per_month
|
37
57
|
return NA_VALUE if @price_per_unit == NA_VALUE
|
38
58
|
@price_per_unit * 24 * @days
|
39
59
|
end
|
60
|
+
|
61
|
+
def to_hash
|
62
|
+
host_values
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def host_values
|
68
|
+
LABEL_WITH_METHODS.each_with_object({}) do |(k, v), hash|
|
69
|
+
hash[k] = public_send(v)
|
70
|
+
end
|
71
|
+
end
|
40
72
|
end
|
41
73
|
end
|
data/lib/ec2spec/offer_file.rb
CHANGED
@@ -1,19 +1,41 @@
|
|
1
|
-
require '
|
2
|
-
require 'faraday'
|
1
|
+
require 'singleton'
|
3
2
|
|
4
3
|
module Ec2spec
|
5
4
|
class OfferFile
|
6
|
-
|
5
|
+
include Singleton
|
6
|
+
|
7
7
|
OFFER_FILE_NAME = 'price_list.json'
|
8
|
-
OFFER_FILE_DIR = '.ec2spec'
|
9
8
|
|
10
|
-
def
|
11
|
-
@
|
12
|
-
|
9
|
+
def prepare(region)
|
10
|
+
@region = region
|
11
|
+
|
12
|
+
if File.exist?(offer_file_path)
|
13
|
+
Ec2spec.logger.debug('Read from cached offer file')
|
14
|
+
else
|
15
|
+
Ec2spec.logger.info('Downloading: offer file')
|
16
|
+
download
|
17
|
+
Ec2spec.logger.info("Downloaded: offer file (#{offer_file_path})")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def products
|
22
|
+
offer_file_json['products']
|
23
|
+
end
|
24
|
+
|
25
|
+
def vcpu(instance_type)
|
26
|
+
sku_instance_type = sku(instance_type)
|
27
|
+
product = products[sku_instance_type]['attributes']
|
28
|
+
product['vcpu']
|
29
|
+
end
|
30
|
+
|
31
|
+
def memory(instance_type)
|
32
|
+
sku_instance_type = sku(instance_type)
|
33
|
+
product = products[sku_instance_type]['attributes']
|
34
|
+
product['memory']
|
13
35
|
end
|
14
36
|
|
15
|
-
def price_per_unit
|
16
|
-
sku_instance_type = sku
|
37
|
+
def price_per_unit(instance_type)
|
38
|
+
sku_instance_type = sku(instance_type)
|
17
39
|
on_demand = offer_file_json['terms']['OnDemand']
|
18
40
|
sku_value = on_demand[sku_instance_type].first[1]
|
19
41
|
price_dimensions = sku_value['priceDimensions']
|
@@ -22,29 +44,29 @@ module Ec2spec
|
|
22
44
|
|
23
45
|
private
|
24
46
|
|
25
|
-
def
|
26
|
-
|
27
|
-
|
47
|
+
def download
|
48
|
+
http_conn = Faraday.new do |builder|
|
49
|
+
builder.adapter Faraday.default_adapter
|
50
|
+
end
|
51
|
+
|
52
|
+
offer_file_url = OfferIndexFile.instance.offer_file_url(@region)
|
53
|
+
response = http_conn.get(offer_file_url)
|
54
|
+
File.open(offer_file_path, 'wb') { |fp| fp.write(response.body) }
|
28
55
|
end
|
29
56
|
|
30
57
|
def offer_file_path
|
31
|
-
price_list_dir = File.join(ENV['HOME'],
|
58
|
+
price_list_dir = File.join(ENV['HOME'], Const::PROJECT_DIR)
|
32
59
|
Dir.mkdir(price_list_dir) unless Dir.exist?(price_list_dir)
|
33
60
|
File.join(price_list_dir, OFFER_FILE_NAME)
|
34
61
|
end
|
35
62
|
|
36
|
-
def
|
37
|
-
|
38
|
-
builder.adapter Faraday.default_adapter
|
39
|
-
end
|
40
|
-
response = http_conn.get(OFFER_FILE_URL)
|
41
|
-
File.open(offer_file_path, 'wb') { |fp| fp.write(response.body) }
|
63
|
+
def offer_file_json
|
64
|
+
@offer_file_json ||= JSON.parse(File.open(offer_file_path).read)
|
42
65
|
end
|
43
66
|
|
44
|
-
def sku
|
45
|
-
products = offer_file_json['products']
|
67
|
+
def sku(instance_type)
|
46
68
|
target_product = products.find do |product|
|
47
|
-
product?(product,
|
69
|
+
product?(product, instance_type)
|
48
70
|
end
|
49
71
|
target_product[1]['sku']
|
50
72
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Ec2spec
|
4
|
+
class OfferIndexFile
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
REGION_INDEX_FILE_URL = 'https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/region_index.json'
|
8
|
+
|
9
|
+
def offer_file_url(region)
|
10
|
+
mkdir_project_dir
|
11
|
+
offer_index_file_json
|
12
|
+
|
13
|
+
file_path = @offer_index_file_json['regions'][region]['currentVersionUrl']
|
14
|
+
parsed_url = URI.parse(REGION_INDEX_FILE_URL)
|
15
|
+
parsed_url.path = file_path
|
16
|
+
parsed_url.to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def project_dir
|
22
|
+
File.join(ENV['HOME'], Const::PROJECT_DIR)
|
23
|
+
end
|
24
|
+
|
25
|
+
def mkdir_project_dir
|
26
|
+
Dir.mkdir(project_dir) unless Dir.exist?(project_dir)
|
27
|
+
end
|
28
|
+
|
29
|
+
def region_index_file_path
|
30
|
+
File.join(project_dir, REGION_INDEX_FILE_URL)
|
31
|
+
end
|
32
|
+
|
33
|
+
def offer_index_file_path
|
34
|
+
file_name = File.basename(REGION_INDEX_FILE_URL)
|
35
|
+
File.join(project_dir, file_name)
|
36
|
+
end
|
37
|
+
|
38
|
+
def offer_index_file_json
|
39
|
+
if File.exist?(offer_index_file_path)
|
40
|
+
Ec2spec.logger.debug('Read from cached offer index file')
|
41
|
+
else
|
42
|
+
Ec2spec.logger.info('Downloading: offer index file')
|
43
|
+
download_region_index_file
|
44
|
+
Ec2spec.logger
|
45
|
+
.info("Downloaded: offer index file (#{offer_index_file_path})")
|
46
|
+
end
|
47
|
+
|
48
|
+
@offer_index_file_json ||=
|
49
|
+
JSON.parse(File.open(offer_index_file_path).read)
|
50
|
+
end
|
51
|
+
|
52
|
+
def download_region_index_file
|
53
|
+
http_conn = Faraday.new do |builder|
|
54
|
+
builder.adapter Faraday.default_adapter
|
55
|
+
end
|
56
|
+
response = http_conn.get(REGION_INDEX_FILE_URL)
|
57
|
+
File.open(offer_index_file_path, 'wb') { |fp| fp.write(response.body) }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Ec2spec
|
2
|
+
module PlainTextFormatter
|
3
|
+
def output(results, hosts)
|
4
|
+
table = Terminal::Table.new
|
5
|
+
table.headings = table_header(results)
|
6
|
+
table.rows = table_rows(results)
|
7
|
+
column_count = hosts.size + 1
|
8
|
+
column_count.times { |i| table.align_column(i, :right) }
|
9
|
+
table
|
10
|
+
end
|
11
|
+
|
12
|
+
def table_header(results)
|
13
|
+
[''].concat(results.map(&:host))
|
14
|
+
end
|
15
|
+
|
16
|
+
def table_rows(results)
|
17
|
+
Ec2spec::HostResult::LABEL_WITH_METHODS
|
18
|
+
.each_with_object([]) do |(k, v), row|
|
19
|
+
row << [k].concat(results.map(&v))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/ec2spec/version.rb
CHANGED
data/lib/ec2spec.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
1
3
|
require 'specinfra'
|
2
4
|
require 'terminal-table'
|
3
5
|
require 'ec2spec/cli'
|
4
6
|
require 'ec2spec/client'
|
7
|
+
require 'ec2spec/const'
|
5
8
|
require 'ec2spec/version'
|
6
9
|
require 'ec2spec/host_result'
|
10
|
+
require 'ec2spec/logger'
|
7
11
|
require 'ec2spec/offer_file'
|
12
|
+
require 'ec2spec/offer_index_file'
|
8
13
|
require 'ec2spec/price_calculator'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ec2spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katsuhiko
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-08-
|
12
|
+
date: 2018-08-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -137,6 +137,7 @@ files:
|
|
137
137
|
- ".rspec"
|
138
138
|
- ".rubocop.yml"
|
139
139
|
- ".travis.yml"
|
140
|
+
- CHANGELOG.md
|
140
141
|
- Gemfile
|
141
142
|
- Gemfile.lock
|
142
143
|
- LICENSE
|
@@ -149,8 +150,14 @@ files:
|
|
149
150
|
- lib/ec2spec.rb
|
150
151
|
- lib/ec2spec/cli.rb
|
151
152
|
- lib/ec2spec/client.rb
|
153
|
+
- lib/ec2spec/const.rb
|
154
|
+
- lib/ec2spec/hash_formatter.rb
|
152
155
|
- lib/ec2spec/host_result.rb
|
156
|
+
- lib/ec2spec/json_formatter.rb
|
157
|
+
- lib/ec2spec/logger.rb
|
153
158
|
- lib/ec2spec/offer_file.rb
|
159
|
+
- lib/ec2spec/offer_index_file.rb
|
160
|
+
- lib/ec2spec/plain_text_formatter.rb
|
154
161
|
- lib/ec2spec/price_calculator.rb
|
155
162
|
- lib/ec2spec/version.rb
|
156
163
|
homepage: https://github.com/kyoshidajp/ec2spec
|