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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjMzNTBlYjc5NjI4ODRhNmJlN2FiMTEwNGNiM2RhOTJiZTllNTBjYQ==
4
+ NTYxZTFlM2U5MWMyMDNhZjNmM2M5MjhmODcxYWQ2Yzk2MTkxYjkzNQ==
5
5
  data.tar.gz: !binary |-
6
- OTE2YzhjMDM1ZDAxZTQwZDhhNzVmMTI2YWVlMDQxYmQ5NjFjNTFkMA==
6
+ OTdmY2EyNTRkNWE4Y2JlOTE3OTJjZDA1Y2FkNTNjMTUwMzQ1Yjk5OA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjgzNTE2NTUyZDNlOWU3MzUyMzA1ODdkNTMyNjA0ZDg4YzY0Njc5YjEzNzdi
10
- OTRlYzZhOTE3YWFhN2NmOTc2YzljMTQxMjZkMzAxNmYzZTZkMzcyNmJmZWEz
11
- ZWJhNjg3MTcxZjBhM2JjMDU4ZmFkZjNjNGQ3MDAwMDFmZmZlMmM=
9
+ NWFiZWFjMzI0YzZkNTkzZTljNWQ1MWQ4MzhkNjA4ODE3ZDMzNmVkZWRhZjli
10
+ NDgxZTgyZTkzOTIxNzI5YTMyZDdlM2NiMmM0MGVkYTc2Y2RjYTk3MzM0NTY4
11
+ MzllNTcyNzA5NDk3ZjRlZjc3NTNkMGRjODNhNmU0MGIwNjMxNDU=
12
12
  data.tar.gz: !binary |-
13
- ZDQ3MDE4YjRkNDlkMDRlN2E2NGY3MjI4Yjg2ZmRjMWQyNTcxY2ZmMDQ2ZTJj
14
- MGQxOWFmMjMxZDIxNTMyMTFhMTg1MGEzZjQ3MWJmZjNkMjY3MjI5NGQ1NDk0
15
- MjdmN2Y1ZTE5ZGJkZDFmZWYwNmE0YTg3MjVlMmQ5YjllN2FlMWU=
13
+ MjRlZjY0NDg0OWU3YzNjNzk2NzEzYjg1YmU3NzU0MTUxNjAzN2E2ZmUzMTNm
14
+ M2MwMDBiZTIzOTAzZWM2YTE5ZDhiODE0NWUxZTk5OTEwOGVjNjJmNzllZmQx
15
+ OGMzOTk1MzRkM2IwYjQ4OGU2NTJhMjYzMWE3MTI4MDFlMzU3Mjc=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
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.1 ruby lib
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.1"
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"]
@@ -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
- puts getInstanceTypes.ai
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
- agent = Mechanize.new
23
- agent.user_agent_alias = 'Mac Safari' # Pretend to use a Mac
24
- begin
25
- page = agent.get('http://aws.amazon.com/ec2/instance-types/instance-details/')
26
- #body = page.body.gsub('<br>', " \n")
27
- require "nokogiri"
28
- nk = Nokogiri::HTML(page.body)
29
- table = nk.css("div#yui-main div.yui-b table")
30
- raise AWSEC2Error.new "Cannot find instance type table" unless table.is_a?(Nokogiri::XML::NodeSet)
31
- rows = table.search('tr')[0..-1]
32
- head = rows.shift
33
- #br = nbsp = Nokogiri::HTML("<br>").text
34
- cols = head.search('td').collect { |td|
35
- text = td.text.to_s
36
- text = text.gsub(%r/(\r?\n)+/, ' ').strip
37
- CGI.unescapeHTML(text)
38
- } #.select{ |col| col unless col == '' }
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
- @instance_types[:headings] = {}
41
- (0..cols.size-1).map{|i| @instance_types[:headings][HEADINGS[i]] = cols[i] }
44
+ @instance_types[:headings] = {}
45
+ (0..cols.size-1).map{|i| @instance_types[:headings][HEADINGS[i]] = cols[i] }
42
46
 
43
- @instance_types[:details] = []
44
- rows.each do |row|
47
+ @instance_types[:details] = []
48
+ rows.each do |row|
45
49
 
46
- cells = row.search('td').collect { |td|
47
- CGI.unescapeHTML(td.text.to_s.gsub(%r/(\r?\n)+/, ' ').strip.gsub('32-bit or64-bit', '32-bit or 64-bit'))
48
- }
49
- 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
50
- instance = {}
51
- (0..cells.size-1).map{|i| instance[HEADINGS[i]] = cells[i] }
52
- @instance_types[:details] << instance
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-ec2-instance_types
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christo De Lange