aws-ec2-instance_types 1.0.1 → 1.0.3
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 +8 -8
- data/VERSION +1 -1
- data/aws-ec2-instance_types.gemspec +2 -2
- data/bin/aws-ec2-instance_types +12 -1
- data/lib/dldinternet/aws/ec2/instance_types.rb +33 -33
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTYxZTFlM2U5MWMyMDNhZjNmM2M5MjhmODcxYWQ2Yzk2MTkxYjkzNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OTdmY2EyNTRkNWE4Y2JlOTE3OTJjZDA1Y2FkNTNjMTUwMzQ1Yjk5OA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NWFiZWFjMzI0YzZkNTkzZTljNWQ1MWQ4MzhkNjA4ODE3ZDMzNmVkZWRhZjli
|
10
|
+
NDgxZTgyZTkzOTIxNzI5YTMyZDdlM2NiMmM0MGVkYTc2Y2RjYTk3MzM0NTY4
|
11
|
+
MzllNTcyNzA5NDk3ZjRlZjc3NTNkMGRjODNhNmU0MGIwNjMxNDU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjRlZjY0NDg0OWU3YzNjNzk2NzEzYjg1YmU3NzU0MTUxNjAzN2E2ZmUzMTNm
|
14
|
+
M2MwMDBiZTIzOTAzZWM2YTE5ZDhiODE0NWUxZTk5OTEwOGVjNjJmNzllZmQx
|
15
|
+
OGMzOTk1MzRkM2IwYjQ4OGU2NTJhMjYzMWE3MTI4MDFlMzU3Mjc=
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.3
|
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: aws-ec2-instance_types 1.0.
|
5
|
+
# stub: aws-ec2-instance_types 1.0.3 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "aws-ec2-instance_types"
|
9
|
-
s.version = "1.0.
|
9
|
+
s.version = "1.0.3"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.authors = ["Christo De Lange"]
|
data/bin/aws-ec2-instance_types
CHANGED
@@ -7,5 +7,16 @@ $:.unshift(_lib) unless $:.include?(_lib)
|
|
7
7
|
require "dldinternet/aws/ec2"
|
8
8
|
include DLDInternet::AWS::EC2
|
9
9
|
|
10
|
+
require "mechanize"
|
11
|
+
mechanize = Mechanize.new
|
12
|
+
mechanize.open_timeout = 5
|
13
|
+
mechanize.read_timeout = 10
|
14
|
+
|
10
15
|
require "awesome_print"
|
11
|
-
|
16
|
+
require "colorize"
|
17
|
+
|
18
|
+
begin
|
19
|
+
puts getInstanceTypes(:mechanize => mechanize).ai
|
20
|
+
rescue Timeout::Error => e
|
21
|
+
puts "Unable to retrieve instance type details in a reasonable time (#{mechanize.open_timeout}s). Giving up ...".light_red
|
22
|
+
end
|
@@ -15,46 +15,46 @@ module DLDInternet
|
|
15
15
|
|
16
16
|
attr_reader :instance_types
|
17
17
|
|
18
|
-
def getInstanceTypes()
|
18
|
+
def getInstanceTypes(options={})
|
19
19
|
unless @instance_types
|
20
20
|
@instance_types = {}
|
21
21
|
require "mechanize"
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
22
|
+
mechanize = options[:mechanize]
|
23
|
+
unless mechanize
|
24
|
+
mechanize = Mechanize.new
|
25
|
+
mechanize.user_agent_alias = 'Mac Safari' # Pretend to use a Mac
|
26
|
+
end
|
27
|
+
url = options[:url] || 'http://aws.amazon.com/ec2/instance-types/instance-details/'
|
28
|
+
|
29
|
+
page = mechanize.get(url)
|
30
|
+
|
31
|
+
require "nokogiri"
|
32
|
+
nk = Nokogiri::HTML(page.body)
|
33
|
+
table = nk.css("div#yui-main div.yui-b table")
|
34
|
+
raise AWSEC2Error.new "Cannot find instance type table" unless table.is_a?(Nokogiri::XML::NodeSet)
|
35
|
+
rows = table.search('tr')[0..-1]
|
36
|
+
head = rows.shift
|
37
|
+
|
38
|
+
cols = head.search('td').collect { |td|
|
39
|
+
text = td.text.to_s
|
40
|
+
text = text.gsub(%r/(\r?\n)+/, ' ').strip
|
41
|
+
CGI.unescapeHTML(text)
|
42
|
+
}
|
39
43
|
|
40
|
-
|
41
|
-
|
44
|
+
@instance_types[:headings] = {}
|
45
|
+
(0..cols.size-1).map{|i| @instance_types[:headings][HEADINGS[i]] = cols[i] }
|
42
46
|
|
43
|
-
|
44
|
-
|
47
|
+
@instance_types[:details] = []
|
48
|
+
rows.each do |row|
|
45
49
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
cells = row.search('td').collect { |td|
|
51
|
+
CGI.unescapeHTML(td.text.to_s.gsub(%r/(\r?\n)+/, ' ').strip.gsub('32-bit or64-bit', '32-bit or 64-bit'))
|
52
|
+
}
|
53
|
+
raise StandardError.new "This row does not have the same number of cells as the table header: #{row.text.to_s.strip}" unless cells.size == cols.size
|
54
|
+
instance = {}
|
55
|
+
(0..cells.size-1).map{|i| instance[HEADINGS[i]] = cells[i] }
|
56
|
+
@instance_types[:details] << instance
|
53
57
|
|
54
|
-
end
|
55
|
-
rescue Net::HTTPNotFound => e
|
56
|
-
@logger.error "Unable to retrieve list of flavors! #{FLAVORS_URL} was not found! (#{e.message})"
|
57
|
-
raise e
|
58
58
|
end
|
59
59
|
end
|
60
60
|
@instance_types
|