amazon-ec2 0.4.8 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/ChangeLog +7 -4
  2. data/README.rdoc +12 -12
  3. data/README_dev.rdoc +6 -0
  4. data/Rakefile +2 -1
  5. data/VERSION +1 -1
  6. data/amazon-ec2.gemspec +25 -18
  7. data/bin/ec2-gem-example.rb +3 -3
  8. data/bin/ec2-gem-profile.rb +2 -2
  9. data/bin/ec2sh +4 -4
  10. data/bin/setup.rb +4 -2
  11. data/lib/{EC2.rb → AWS.rb} +33 -67
  12. data/lib/AWS/EC2.rb +67 -0
  13. data/lib/AWS/EC2/availability_zones.rb +43 -0
  14. data/lib/AWS/EC2/console.rb +46 -0
  15. data/lib/AWS/EC2/elastic_ips.rb +154 -0
  16. data/lib/AWS/EC2/image_attributes.rb +168 -0
  17. data/lib/AWS/EC2/images.rb +136 -0
  18. data/lib/AWS/EC2/instances.rb +218 -0
  19. data/lib/AWS/EC2/keypairs.rb +96 -0
  20. data/lib/AWS/EC2/products.rb +45 -0
  21. data/lib/AWS/EC2/security_groups.rb +234 -0
  22. data/lib/AWS/EC2/snapshots.rb +96 -0
  23. data/lib/AWS/EC2/volumes.rb +172 -0
  24. data/lib/AWS/ELB.rb +67 -0
  25. data/lib/AWS/ELB/load_balancers.rb +198 -0
  26. data/lib/{EC2 → AWS}/exceptions.rb +21 -2
  27. data/lib/{EC2 → AWS}/responses.rb +4 -5
  28. data/perftools/ec2prof-results.txt +4 -4
  29. data/perftools/ec2prof.symbols +4 -4
  30. data/test/test_EC2.rb +14 -14
  31. data/test/test_EC2_availability_zones.rb +2 -2
  32. data/test/test_EC2_console.rb +5 -5
  33. data/test/test_EC2_elastic_ips.rb +13 -13
  34. data/test/test_EC2_image_attributes.rb +35 -35
  35. data/test/test_EC2_images.rb +7 -7
  36. data/test/test_EC2_instances.rb +35 -35
  37. data/test/test_EC2_keypairs.rb +10 -10
  38. data/test/test_EC2_products.rb +7 -7
  39. data/test/test_EC2_responses.rb +2 -2
  40. data/test/test_EC2_s3_xmlsimple.rb +2 -2
  41. data/test/test_EC2_security_groups.rb +13 -13
  42. data/test/test_EC2_snapshots.rb +2 -2
  43. data/test/test_EC2_volumes.rb +2 -2
  44. data/test/test_ELB_load_balancers.rb +239 -0
  45. data/test/test_helper.rb +1 -1
  46. metadata +24 -17
  47. data/lib/EC2/availability_zones.rb +0 -41
  48. data/lib/EC2/console.rb +0 -44
  49. data/lib/EC2/elastic_ips.rb +0 -153
  50. data/lib/EC2/image_attributes.rb +0 -166
  51. data/lib/EC2/images.rb +0 -134
  52. data/lib/EC2/instances.rb +0 -216
  53. data/lib/EC2/keypairs.rb +0 -94
  54. data/lib/EC2/products.rb +0 -43
  55. data/lib/EC2/security_groups.rb +0 -232
  56. data/lib/EC2/snapshots.rb +0 -94
  57. data/lib/EC2/volumes.rb +0 -170
data/ChangeLog CHANGED
@@ -1,3 +1,6 @@
1
+ === 0.5.0 2009-08-11
2
+ * Major re-factor by Kris Rasmussen (krisr) to add support for the AWS Elastic Load Balancer API. Kudos Kris!
3
+
1
4
  === 0.4.0 2009-06-06
2
5
  * Using technicalpickles/jeweler to manage gem now. See : http://github.com/technicalpickles/jeweler/tree/master
3
6
 
@@ -23,13 +26,13 @@
23
26
 
24
27
  === 0.3.2 2008-12-11
25
28
  * Updated API version to 2008-12-01
26
- * Note : The new European EC2 zone should just work if you specify ':server => "eu-west-1.ec2.amazonaws.com"' when initializing EC2::Base.new(). Please report any issues you have with using this new service.
29
+ * Note : The new European EC2 zone should just work if you specify ':server => "eu-west-1.ec2.amazonaws.com"' when initializing AWS::EC2::Base.new(). Please report any issues you have with using this new service.
27
30
 
28
31
  === 0.3.1 2008-09-18
29
32
  * Added basic custom kernel id support to run_instances. Thanks to Keith Hudgins for the patch.
30
33
 
31
34
  === 0.3.0 2008-08-24
32
- * Changed response object from AmazonEC2::Response to Hash (patch from Yan Pritzker 'skwp') Thanks!
35
+ * Changed response object from AmazonAWS::Response to Hash (patch from Yan Pritzker 'skwp') Thanks!
33
36
  * Added support for Elastic Block Storage (patch from Yann Klis 'yannski') Thanks!
34
37
  * Bumped AWS EC2 API version to 2008-05-05
35
38
  * Bumped gem version number
@@ -105,7 +108,7 @@
105
108
  * MAJOR refactoring of how responses are returned to users. No longer do you have to call the
106
109
  .parse method, and no longer are you getting back simple arrays of information. Responses
107
110
  now come in the form of OpenStruct objects that contain all of the data for an object in
108
- Enumerable form so you can use iterators (.each, .each_pair, etc). All methods return an EC2::Response object
111
+ Enumerable form so you can use iterators (.each, .each_pair, etc). All methods return an AWS::Response object
109
112
  which inherits from OpenStruct. The return data from EC2, which is in XML form, is parsed
110
113
  with XmlSimple and is used to directly construct the return data structure. This allows us
111
114
  to know with some confidence that the data structure returned from AWS will always be consistent
@@ -116,7 +119,7 @@
116
119
  that match those handed to us by Amazon EC2. ArgumentError exceptions will also
117
120
  be thrown if you are making calls we know to be illegal or malformed. You should rescue
118
121
  these exceptions in your application instead of parsing text responses. All exceptions
119
- descend from EC2::Error. You can see them all in exceptions.rb in the gem install.
122
+ descend from AWS::Error. You can see them all in exceptions.rb in the gem install.
120
123
 
121
124
  * Added a full suite of test/spec unit tests which currently cover 100% of the public methods
122
125
  in this library. We have abot 92% code coverage according to rcov. This has greatly enhanced
data/README.rdoc CHANGED
@@ -57,9 +57,9 @@ The following gems should be installed automatically as part of your install of
57
57
 
58
58
  == Using amazon-ec2
59
59
 
60
- The library exposes one main interface class EC2::Base. It is through an instance of this class that you will perform all the operations for using the EC2 service including query string header signing.
60
+ The library exposes one main interface class AWS::EC2::Base. It is through an instance of this class that you will perform all the operations for using the EC2 service including query string header signing.
61
61
 
62
- The public methods on EC2::Base closely mirror the EC2 Query API, and as such the Query API Reference in the EC2 Developer Guide ( http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=84 ) will prove helpful.
62
+ The public methods on AWS::EC2::Base closely mirror the EC2 Query API, and as such the Query API Reference in the EC2 Developer Guide ( http://developer.amazonwebservices.com/connect/kbcategory.jspa?categoryID=84 ) will prove helpful.
63
63
 
64
64
 
65
65
  === Setting up
@@ -90,11 +90,11 @@ You can verify that this setup is complete by running the 'set' in a command win
90
90
 
91
91
  The library exposes one main interface module
92
92
 
93
- EC2::Base
93
+ AWS::EC2::Base
94
94
 
95
95
  This method requires arguments which include your AWS credentials and it will return an object that you can use to make method calls directly against EC2. All the operations for using the EC2 service, including query string header signing, are handled automatically for you. The connection string will look something like this:
96
96
 
97
- @ec2 = EC2::Base.new(:access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY)
97
+ @ec2 = AWS::EC2::Base.new(:access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY)
98
98
 
99
99
  I've tried to keep the public methods on 'amazon-ec2' as close as possible to the AWS EC2 Query API. This similarity allows you to reference the Query API Reference in the EC2 Developer Guide and be able to get started right away. In most cases the methods names only differ in how they are presented. e.g. 'DescribeImages' becomes '#describe_images()' in Ruby. Feel free to browse the full RDoc documentation for all classes and methods of 'amazon-ec2' if you want more details.
100
100
 
@@ -144,28 +144,28 @@ If you're not in front of a terminal shell now (perhaps you're browsing this sit
144
144
  returns : a string representation of ALL images
145
145
  >> @ec2.describe_images.to_s
146
146
 
147
- returns : an Array of EC2::Response objects, each an EC2 image and its data
147
+ returns : an Array of AWS::Response objects, each an EC2 image and its data
148
148
  >> @ec2.describe_images.imagesSet.item
149
149
  >> @ec2.describe_images.imagesSet.item[0] (a hash representing a single item in that array)
150
150
  >> @ec2.describe_images.imagesSet.item[0].to_s (a String representation of that item)
151
151
 
152
152
  >> @ec2.describe_images.imagesSet.item[0].to_s
153
- => "#<EC2::Response:0x100A465B4 imageId=\"ami-018e6b68\" imageLocation=\"rbuilder-online/phonehome-1.5.6-x86_10132.img.manifest.xml\" imageOwnerId=\"099034111737\" imageState=\"available\" isPublic=\"true\" parent=#<EC2::Response:0x100A469A6 ...>>"
153
+ => "#<AWS::Response:0x100A465B4 imageId=\"ami-018e6b68\" imageLocation=\"rbuilder-online/phonehome-1.5.6-x86_10132.img.manifest.xml\" imageOwnerId=\"099034111737\" imageState=\"available\" isPublic=\"true\" parent=#<AWS::Response:0x100A469A6 ...>>"
154
154
 
155
155
 
156
156
  === Ruby script usage example:
157
157
 
158
- Try out the following bit of code. This should walk through each image returned by a call to #describe_images and print out its key data. Note in the example below that you cannot walk through the results of the #describe_images call with the '.each' iterator (You'll get errors if you try). You need to instead walk through the Array of items which are in the 'imagesSet' embedded in the response. This reflects exactly the XML hierarchy of data returned from EC2 which we parse to Ruby OpenStruct objects (EC2::Response).
158
+ Try out the following bit of code. This should walk through each image returned by a call to #describe_images and print out its key data. Note in the example below that you cannot walk through the results of the #describe_images call with the '.each' iterator (You'll get errors if you try). You need to instead walk through the Array of items which are in the 'imagesSet' embedded in the response. This reflects exactly the XML hierarchy of data returned from EC2 which we parse to Ruby OpenStruct objects (AWS::Response).
159
159
 
160
160
  #!/usr/bin/env ruby
161
161
 
162
162
  require 'rubygems'
163
- require 'EC2'
163
+ require 'AWS'
164
164
 
165
165
  ACCESS_KEY_ID = '--YOUR AWS ACCESS KEY ID--'
166
166
  SECRET_ACCESS_KEY = '--YOUR AWS SECRET ACCESS KEY--'
167
167
 
168
- ec2 = EC2::Base.new(:access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY)
168
+ ec2 = AWS::EC2::Base.new(:access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY)
169
169
 
170
170
  puts "----- listing images owned by 'amazon' -----"
171
171
  ec2.describe_images(:owner_id => "amazon").imagesSet.item.each do |image|
@@ -191,7 +191,7 @@ Try out the following bit of code. This should walk through each image returned
191
191
 
192
192
  [some controller code ...]
193
193
 
194
- ec2 = EC2::Base.new(:access_key_id => "YOUR_AWS_ACCESS_KEY_ID", :secret_access_key => "YOUR_AWS_SECRET_ACCESS_KEY")
194
+ ec2 = AWS::EC2::Base.new(:access_key_id => "YOUR_AWS_ACCESS_KEY_ID", :secret_access_key => "YOUR_AWS_SECRET_ACCESS_KEY")
195
195
 
196
196
  # get ALL public images
197
197
  @ec2_images = ec2.describe_images().imagesSet.item
@@ -244,7 +244,7 @@ Try out the following bit of code. This should walk through each image returned
244
244
  <% end %>
245
245
 
246
246
 
247
- === Important notes regarding the structure of EC2::Response Objects
247
+ === Important notes regarding the structure of AWS::Response Objects
248
248
 
249
249
  One of the key benefits of this new version of the library is that all responses from EC2 are bundled up in a real data structure and no longer require parsing of text. The hash returned is populated directly from the XML given to us by EC2 in response to any command we issue. This means that future changes to the API and what is returned by EC2 will be handled transparently by the gem. This is a huge benefit. What this means though, is that you may have to do a little homework on what actually gets returned by EC2 as XML. For example, when you make a #describe_images call in 'ec2sh' what AWS returns behind the scenes looks like:
250
250
 
@@ -303,7 +303,7 @@ So, for example, if you wanted to get the image ID of the third image listed in
303
303
  >> puts @ec2.describe_images(:owner_id => 'amazon').imagesSet.item[2].imageId
304
304
  ami-23b6534a
305
305
 
306
- EC2 will typically return sets of things (imagesSet, reservationSet, etc.) which we map to ruby Arrays (.imagesSet.item in the example above). If you want to iterate over a response set you will need to iterate over this array. The Arrays will typically contain additional EC2::Response objects that represent each individual item. You'll find that you can use the 'ec2sh' to help you understand the structure more completely if you try issuing commands there as a way to practice seeing what will be returned and making sure you get exactly what you want.
306
+ EC2 will typically return sets of things (imagesSet, reservationSet, etc.) which we map to ruby Arrays (.imagesSet.item in the example above). If you want to iterate over a response set you will need to iterate over this array. The Arrays will typically contain additional AWS::Response objects that represent each individual item. You'll find that you can use the 'ec2sh' to help you understand the structure more completely if you try issuing commands there as a way to practice seeing what will be returned and making sure you get exactly what you want.
307
307
 
308
308
 
309
309
  == Additional Resources
data/README_dev.rdoc ADDED
@@ -0,0 +1,6 @@
1
+ = Dev Docs
2
+
3
+ Publishing the gem using Jeweler:
4
+
5
+ rake version:bump:patch release rubyforge:release rubyforge:release:docs
6
+
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'jeweler'
5
5
  Jeweler::Tasks.new do |gem|
6
6
  gem.name = "amazon-ec2"
7
7
  gem.summary = %Q{Amazon EC2 Ruby Gem}
8
- gem.description = %Q{An interface library that allows Ruby applications to easily connect to the HTTP 'Query API' for the Amazon Web Services Elastic Compute Cloud (EC2) and manipulate cloud servers.}
8
+ gem.description = %Q{A Ruby library for accessing the Amazon Web Services Elastic Compute Cloud (EC2) and Elastic Load Balancer (ELB) API's.}
9
9
  gem.email = "glenn@rempe.us"
10
10
  gem.homepage = "http://github.com/grempe/amazon-ec2"
11
11
  gem.authors = ["Glenn Rempe"]
@@ -36,6 +36,7 @@ begin
36
36
  test.libs << 'test'
37
37
  test.pattern = 'test/**/test_*.rb'
38
38
  test.verbose = true
39
+ test.rcov_opts << "--exclude /gems/,/Library/,spec"
39
40
  end
40
41
  rescue LoadError
41
42
  task :rcov do
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.8
1
+ 0.5.0
data/amazon-ec2.gemspec CHANGED
@@ -5,24 +5,26 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{amazon-ec2}
8
- s.version = "0.4.8"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Glenn Rempe"]
12
- s.date = %q{2009-08-09}
13
- s.description = %q{An interface library that allows Ruby applications to easily connect to the HTTP 'Query API' for the Amazon Web Services Elastic Compute Cloud (EC2) and manipulate cloud servers.}
12
+ s.date = %q{2009-08-11}
13
+ s.description = %q{A Ruby library for accessing the Amazon Web Services Elastic Compute Cloud (EC2) and Elastic Load Balancer (ELB) API's.}
14
14
  s.email = %q{glenn@rempe.us}
15
15
  s.executables = ["ec2-gem-example.rb", "ec2-gem-profile.rb", "ec2sh", "setup.rb"]
16
16
  s.extra_rdoc_files = [
17
17
  "ChangeLog",
18
18
  "LICENSE",
19
- "README.rdoc"
19
+ "README.rdoc",
20
+ "README_dev.rdoc"
20
21
  ]
21
22
  s.files = [
22
23
  ".gitignore",
23
24
  "ChangeLog",
24
25
  "LICENSE",
25
26
  "README.rdoc",
27
+ "README_dev.rdoc",
26
28
  "Rakefile",
27
29
  "VERSION",
28
30
  "amazon-ec2.gemspec",
@@ -31,20 +33,23 @@ Gem::Specification.new do |s|
31
33
  "bin/ec2sh",
32
34
  "bin/setup.rb",
33
35
  "deps.rip",
34
- "lib/EC2.rb",
35
- "lib/EC2/availability_zones.rb",
36
- "lib/EC2/console.rb",
37
- "lib/EC2/elastic_ips.rb",
38
- "lib/EC2/exceptions.rb",
39
- "lib/EC2/image_attributes.rb",
40
- "lib/EC2/images.rb",
41
- "lib/EC2/instances.rb",
42
- "lib/EC2/keypairs.rb",
43
- "lib/EC2/products.rb",
44
- "lib/EC2/responses.rb",
45
- "lib/EC2/security_groups.rb",
46
- "lib/EC2/snapshots.rb",
47
- "lib/EC2/volumes.rb",
36
+ "lib/AWS.rb",
37
+ "lib/AWS/EC2.rb",
38
+ "lib/AWS/EC2/availability_zones.rb",
39
+ "lib/AWS/EC2/console.rb",
40
+ "lib/AWS/EC2/elastic_ips.rb",
41
+ "lib/AWS/EC2/image_attributes.rb",
42
+ "lib/AWS/EC2/images.rb",
43
+ "lib/AWS/EC2/instances.rb",
44
+ "lib/AWS/EC2/keypairs.rb",
45
+ "lib/AWS/EC2/products.rb",
46
+ "lib/AWS/EC2/security_groups.rb",
47
+ "lib/AWS/EC2/snapshots.rb",
48
+ "lib/AWS/EC2/volumes.rb",
49
+ "lib/AWS/ELB.rb",
50
+ "lib/AWS/ELB/load_balancers.rb",
51
+ "lib/AWS/exceptions.rb",
52
+ "lib/AWS/responses.rb",
48
53
  "perftools/ec2prof",
49
54
  "perftools/ec2prof-results.dot",
50
55
  "perftools/ec2prof-results.txt",
@@ -63,6 +68,7 @@ Gem::Specification.new do |s|
63
68
  "test/test_EC2_security_groups.rb",
64
69
  "test/test_EC2_snapshots.rb",
65
70
  "test/test_EC2_volumes.rb",
71
+ "test/test_ELB_load_balancers.rb",
66
72
  "test/test_helper.rb",
67
73
  "wsdl/2007-08-29.ec2.wsdl",
68
74
  "wsdl/2008-02-01.ec2.wsdl",
@@ -90,6 +96,7 @@ Gem::Specification.new do |s|
90
96
  "test/test_EC2_security_groups.rb",
91
97
  "test/test_EC2_snapshots.rb",
92
98
  "test/test_EC2_volumes.rb",
99
+ "test/test_ELB_load_balancers.rb",
93
100
  "test/test_helper.rb"
94
101
  ]
95
102
 
@@ -9,7 +9,7 @@
9
9
  # Home:: http://github.com/grempe/amazon-ec2/tree/master
10
10
  #++
11
11
 
12
- require File.dirname(__FILE__) + '/../lib/EC2'
12
+ require File.dirname(__FILE__) + '/../lib/AWS'
13
13
  require 'pp'
14
14
 
15
15
  # pull these from the local shell environment variables set in ~/.bash_login
@@ -34,10 +34,10 @@ end
34
34
  # test different servers by running something like:
35
35
  # export EC2_URL='https://ec2.amazonaws.com';./bin/ec2-gem-example.rb
36
36
  if ENV['EC2_URL']
37
- ec2 = EC2::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY, :server => URI.parse(ENV['EC2_URL']).host )
37
+ ec2 = AWS::EC2::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY, :server => URI.parse(ENV['EC2_URL']).host )
38
38
  else
39
39
  # default server is US ec2.amazonaws.com
40
- ec2 = EC2::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY )
40
+ ec2 = AWS::EC2::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY )
41
41
  end
42
42
 
43
43
  puts "----- ec2.methods.sort -----"
@@ -2,9 +2,9 @@
2
2
 
3
3
  # Basic single command application that we can call with perftools.rb to get consistent results.
4
4
 
5
- require File.dirname(__FILE__) + '/../lib/EC2'
5
+ require File.dirname(__FILE__) + '/../lib/AWS'
6
6
  ACCESS_KEY_ID = ENV['AMAZON_ACCESS_KEY_ID']
7
7
  SECRET_ACCESS_KEY = ENV['AMAZON_SECRET_ACCESS_KEY']
8
- ec2 = EC2::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY )
8
+ ec2 = AWS::EC2::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY )
9
9
  @images = ec2.describe_images
10
10
 
data/bin/ec2sh CHANGED
@@ -19,9 +19,9 @@
19
19
 
20
20
  # macbook-pro:~ glenn$ ec2sh
21
21
  # >> @ec2.describe_images
22
- # => [#<EC2::Item image_location...
22
+ # => [#<AWS::EC2::Item image_location...
23
23
 
24
- ec2_lib = File.dirname(__FILE__) + '/../lib/EC2'
24
+ aws_lib = File.dirname(__FILE__) + '/../lib/AWS'
25
25
  setup = File.dirname(__FILE__) + '/setup'
26
26
  irb_name = RUBY_PLATFORM =~ /mswin32/ ? 'irb.bat' : 'irb'
27
27
 
@@ -48,7 +48,7 @@ if ( ENV['AMAZON_ACCESS_KEY_ID'] && ENV['AMAZON_SECRET_ACCESS_KEY'] )
48
48
  returns : a string representation of ALL images
49
49
  >> @ec2.describe_images.to_s
50
50
 
51
- returns : an Array of EC2::Response objects, each an EC2 image and its data
51
+ returns : an Array of AWS::Response objects, each an EC2 image and its data
52
52
  >> @ec2.describe_images.imagesSet.item
53
53
  >> @ec2.describe_images.imagesSet.item[0] (a hash representing a single item in that array)
54
54
  >> @ec2.describe_images.imagesSet.item[0].to_s (a String representation of that item)
@@ -56,7 +56,7 @@ if ( ENV['AMAZON_ACCESS_KEY_ID'] && ENV['AMAZON_SECRET_ACCESS_KEY'] )
56
56
  MESSAGE
57
57
 
58
58
  puts welcome_message
59
- exec "#{irb_name} -r #{ec2_lib} -r #{setup} --simple-prompt"
59
+ exec "#{irb_name} -r #{aws_lib} -r #{setup} --simple-prompt"
60
60
  else
61
61
  puts "You must define AMAZON_ACCESS_KEY_ID and AMAZON_SECRET_ACCESS_KEY as shell environment variables before running #{$0}!"
62
62
  end
data/bin/setup.rb CHANGED
@@ -17,9 +17,11 @@ if ENV['AMAZON_ACCESS_KEY_ID'] && ENV['AMAZON_SECRET_ACCESS_KEY']
17
17
  if ENV['EC2_URL']
18
18
  opts[:server] = URI.parse(ENV['EC2_URL']).host
19
19
  end
20
- @ec2 = EC2::Base.new(opts)
20
+ @ec2 = AWS::EC2::Base.new(opts)
21
+ @elb = AWS::ELB::Base.new(opts)
21
22
  end
22
23
 
23
24
  puts "EC2 Server: #{opts[:server]}"
24
25
 
25
- include EC2
26
+ include AWS
27
+
@@ -1,46 +1,17 @@
1
- #--
2
- # Amazon Web Services EC2 Query API Ruby library
3
- #
4
- # Ruby Gem Name:: amazon-ec2
5
- # Author:: Glenn Rempe (mailto:glenn@rempe.us)
6
- # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
- # License:: Distributes under the same terms as Ruby
8
- # Home:: http://github.com/grempe/amazon-ec2/tree/master
9
- #++
10
-
11
- %w[ base64 cgi openssl digest/sha1 net/https rexml/document time ostruct ].each { |f| require f }
12
-
13
- # Require any lib files that we have bundled with this Ruby Gem in the lib/EC2 directory.
14
- # Parts of the EC2 module and Base class are broken out into separate
1
+ # Require any lib files that we have bundled with this Ruby Gem in the lib/AWS directory.
2
+ # Parts of the AWS module and Base class are broken out into separate
15
3
  # files for maintainability and are organized by the functional groupings defined
16
- # in the EC2 API developers guide.
17
- Dir[File.join(File.dirname(__FILE__), 'EC2/**/*.rb')].sort.each { |lib| require lib }
18
-
19
- module EC2
20
-
21
- # Which host FQDN will we connect to for all API calls to AWS?
22
- # If EC2_URL is defined in the users ENV we can use that. It is
23
- # expected that this var is set with something like:
24
- # export EC2_URL='https://ec2.amazonaws.com'
25
- #
26
- if ENV['EC2_URL']
27
- EC2_URL = ENV['EC2_URL']
28
- VALID_HOSTS = ['https://ec2.amazonaws.com', 'https://us-east-1.ec2.amazonaws.com', 'https://eu-west-1.ec2.amazonaws.com']
29
- raise ArgumentError, "Invalid EC2_URL environment variable : #{EC2_URL}" unless VALID_HOSTS.include?(EC2_URL)
30
- DEFAULT_HOST = URI.parse(EC2_URL).host
31
- else
32
- # default US host
33
- DEFAULT_HOST = 'ec2.amazonaws.com'
34
- end
4
+ # in the AWS API developers guide.
5
+
35
6
 
36
- # This is the version of the API as defined by Amazon Web Services
37
- API_VERSION = '2008-12-01'
7
+ %w[ base64 cgi openssl digest/sha1 net/https rexml/document time ostruct ].each { |f| require f }
38
8
 
9
+ module AWS
39
10
  # Builds the canonical string for signing. This strips out all '&', '?', and '='
40
11
  # from the query string to be signed.
41
12
  # Note: The parameters in the path passed in must already be sorted in
42
13
  # case-insensitive alphabetical order and must not be url encoded.
43
- def EC2.canonical_string(params, host = DEFAULT_HOST, method="POST", base="/")
14
+ def AWS.canonical_string(params, host, method="POST", base="/")
44
15
  # Sort, and encode parameters into a canonical string.
45
16
  sorted_params = params.sort {|x,y| x[0] <=> y[0]}
46
17
  encoded_params = sorted_params.collect do |p|
@@ -64,7 +35,7 @@ module EC2
64
35
  # hmac-sha1 sum, and then base64 encoding it. Optionally, it will also
65
36
  # url encode the result of that to protect the string if it's going to
66
37
  # be used as a query string parameter.
67
- def EC2.encode(secret_access_key, str, urlencode=true)
38
+ def AWS.encode(secret_access_key, str, urlencode=true)
68
39
  digest = OpenSSL::Digest::Digest.new('sha1')
69
40
  b64_hmac =
70
41
  Base64.encode64(
@@ -77,25 +48,6 @@ module EC2
77
48
  end
78
49
  end
79
50
 
80
-
81
- #Introduction:
82
- #
83
- # The library exposes one main interface class, 'EC2::Base'.
84
- # This class provides all the methods for using the EC2 service
85
- # including the handling of header signing and other security issues .
86
- # This class uses Net::HTTP to interface with the EC2 Query API interface.
87
- #
88
- #Required Arguments:
89
- #
90
- # :access_key_id => String (default : "")
91
- # :secret_access_key => String (default : "")
92
- #
93
- #Optional Arguments:
94
- #
95
- # :use_ssl => Boolean (default : true)
96
- # :server => String (default : 'ec2.amazonaws.com')
97
- # :proxy_server => String (default : nil)
98
- #
99
51
  class Base
100
52
 
101
53
  attr_reader :use_ssl, :server, :proxy_server, :port
@@ -105,7 +57,7 @@ module EC2
105
57
  options = { :access_key_id => "",
106
58
  :secret_access_key => "",
107
59
  :use_ssl => true,
108
- :server => DEFAULT_HOST,
60
+ :server => default_host,
109
61
  :proxy_server => nil
110
62
  }.merge(options)
111
63
 
@@ -149,7 +101,7 @@ module EC2
149
101
  end
150
102
 
151
103
 
152
- private
104
+ protected
153
105
 
154
106
  # pathlist is a utility method which takes a key string and and array as input.
155
107
  # It converts the array into a Hash with the hash key being 'Key.n' where
@@ -173,6 +125,19 @@ module EC2
173
125
  params
174
126
  end
175
127
 
128
+ # Same as _pathlist_ except it deals with arrays of hashes.
129
+ # So if you pass in args
130
+ # ("People", [{:name=>'jon', :age=>'22'}, {:name=>'chris'}], {:name => 'Name', :age => 'Age'}) you should get
131
+ # {"People.1.Name"=>"jon", "People.1.Age"=>'22', 'People.2.Name'=>'chris'}
132
+ def pathhashlist(key, arr_of_hashes, mappings)
133
+ params ={}
134
+ arr_of_hashes.each_with_index do |hash, i|
135
+ hash.each do |attribute, value|
136
+ params["#{key}.#{i+1}.#{mappings[attribute]}"] = value
137
+ end
138
+ end
139
+ params
140
+ end
176
141
 
177
142
  # Make the connection to AWS EC2 passing in our request. This is generally called from
178
143
  # within a 'Response' class object or one of its sub-classes so the response is interpreted
@@ -188,7 +153,7 @@ module EC2
188
153
  "SignatureVersion" => "2",
189
154
  "SignatureMethod" => 'HmacSHA1',
190
155
  "AWSAccessKeyId" => @access_key_id,
191
- "Version" => API_VERSION,
156
+ "Version" => api_version,
192
157
  "Timestamp"=>Time.now.getutc.iso8601} )
193
158
 
194
159
  sig = get_aws_auth_param(params, @secret_access_key, @server)
@@ -205,7 +170,7 @@ module EC2
205
170
 
206
171
  # Make a call to see if we need to throw an error based on the response given by EC2
207
172
  # All error classes are defined in EC2/exceptions.rb
208
- ec2_error?(response)
173
+ aws_error?(response)
209
174
 
210
175
  return response
211
176
 
@@ -215,8 +180,8 @@ module EC2
215
180
 
216
181
  # Set the Authorization header using AWS signed header authentication
217
182
  def get_aws_auth_param(params, secret_access_key, server)
218
- canonical_string = EC2.canonical_string(params, server)
219
- encoded_canonical = EC2.encode(secret_access_key, canonical_string)
183
+ canonical_string = AWS.canonical_string(params, server)
184
+ encoded_canonical = AWS.encode(secret_access_key, canonical_string)
220
185
  end
221
186
 
222
187
  # allow us to have a one line call in each method which will do all of the work
@@ -238,7 +203,7 @@ module EC2
238
203
 
239
204
  # Raises the appropriate error if the specified Net::HTTPResponse object
240
205
  # contains an Amazon EC2 error; returns +false+ otherwise.
241
- def ec2_error?(response)
206
+ def aws_error?(response)
242
207
 
243
208
  # return false if we got a HTTP 200 code,
244
209
  # otherwise there is some type of error (40x,50x) and
@@ -266,14 +231,15 @@ module EC2
266
231
 
267
232
  # Raise one of our specific error classes if it exists.
268
233
  # otherwise, throw a generic EC2 Error with a few details.
269
- if EC2.const_defined?(error_code)
270
- raise EC2.const_get(error_code), error_message
234
+ if AWS.const_defined?(error_code)
235
+ raise AWS.const_get(error_code), error_message
271
236
  else
272
- raise EC2::Error, error_message
237
+ raise AWS::Error, error_message
273
238
  end
274
239
 
275
240
  end
276
241
 
277
242
  end
278
-
279
243
  end
244
+
245
+ Dir[File.join(File.dirname(__FILE__), 'AWS/*.rb')].sort.each { |lib| require lib }