Browse files

refactored library so that it can encompass multiple apis, and added …

…support for elb
  • Loading branch information...
1 parent 0b3f8fc commit 7a7f0d00e5a486bfac7ce86ab480e4b6ffb37a88 Kris Rasmussen committed with Jul 2, 2009
Showing with 1,852 additions and 1,729 deletions.
  1. +4 −4 ChangeLog
  2. +12 −12 README.rdoc
  3. +3 −3 bin/ec2-gem-example.rb
  4. +2 −2 bin/ec2-gem-profile.rb
  5. +4 −4 bin/ec2sh
  6. +2 −1 bin/setup.rb
  7. +35 −69 lib/{EC2.rb → AWS.rb}
  8. +67 −0 lib/AWS/EC2.rb
  9. +43 −0 lib/AWS/EC2/availability_zones.rb
  10. +46 −0 lib/AWS/EC2/console.rb
  11. +154 −0 lib/AWS/EC2/elastic_ips.rb
  12. +168 −0 lib/AWS/EC2/image_attributes.rb
  13. +136 −0 lib/AWS/EC2/images.rb
  14. +218 −0 lib/AWS/EC2/instances.rb
  15. +96 −0 lib/AWS/EC2/keypairs.rb
  16. +45 −0 lib/AWS/EC2/products.rb
  17. +234 −0 lib/AWS/EC2/security_groups.rb
  18. +96 −0 lib/AWS/EC2/snapshots.rb
  19. +172 −0 lib/AWS/EC2/volumes.rb
  20. +67 −0 lib/AWS/ELB.rb
  21. +87 −0 lib/AWS/ELB/load_balancers.rb
  22. +1 −2 lib/{EC2 → AWS}/exceptions.rb
  23. +3 −3 lib/{EC2 → AWS}/responses.rb
  24. +0 −41 lib/EC2/availability_zones.rb
  25. +0 −44 lib/EC2/console.rb
  26. +0 −153 lib/EC2/elastic_ips.rb
  27. +0 −166 lib/EC2/image_attributes.rb
  28. +0 −134 lib/EC2/images.rb
  29. +0 −216 lib/EC2/instances.rb
  30. +0 −94 lib/EC2/keypairs.rb
  31. +0 −85 lib/EC2/load_balancers.rb
  32. +0 −43 lib/EC2/products.rb
  33. +0 −232 lib/EC2/security_groups.rb
  34. +0 −94 lib/EC2/snapshots.rb
  35. +0 −170 lib/EC2/volumes.rb
  36. +4 −4 perftools/ec2prof-results.txt
  37. +4 −4 perftools/ec2prof.symbols
  38. +13 −13 test/test_EC2.rb
  39. +1 −1 test/test_EC2_availability_zones.rb
  40. +4 −4 test/test_EC2_console.rb
  41. +12 −12 test/test_EC2_elastic_ips.rb
  42. +34 −34 test/test_EC2_image_attributes.rb
  43. +6 −6 test/test_EC2_images.rb
  44. +31 −31 test/test_EC2_instances.rb
  45. +9 −9 test/test_EC2_keypairs.rb
  46. +6 −6 test/test_EC2_products.rb
  47. +1 −1 test/test_EC2_responses.rb
  48. +1 −1 test/test_EC2_s3_xmlsimple.rb
  49. +12 −12 test/test_EC2_security_groups.rb
  50. +1 −1 test/test_EC2_snapshots.rb
  51. +1 −1 test/test_EC2_volumes.rb
  52. +16 −16 test/{test_EC2_load_balancers.rb → test_ELB_load_balancers.rb}
  53. +1 −1 test/test_helper.rb
View
8 ChangeLog
@@ -23,13 +23,13 @@
=== 0.3.2 2008-12-11
* Updated API version to 2008-12-01
- * 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.
+ * 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.
=== 0.3.1 2008-09-18
* Added basic custom kernel id support to run_instances. Thanks to Keith Hudgins for the patch.
=== 0.3.0 2008-08-24
- * Changed response object from AmazonEC2::Response to Hash (patch from Yan Pritzker 'skwp') Thanks!
+ * Changed response object from AmazonAWS::Response to Hash (patch from Yan Pritzker 'skwp') Thanks!
* Added support for Elastic Block Storage (patch from Yann Klis 'yannski') Thanks!
* Bumped AWS EC2 API version to 2008-05-05
* Bumped gem version number
@@ -105,7 +105,7 @@
* MAJOR refactoring of how responses are returned to users. No longer do you have to call the
.parse method, and no longer are you getting back simple arrays of information. Responses
now come in the form of OpenStruct objects that contain all of the data for an object in
- Enumerable form so you can use iterators (.each, .each_pair, etc). All methods return an EC2::Response object
+ Enumerable form so you can use iterators (.each, .each_pair, etc). All methods return an AWS::Response object
which inherits from OpenStruct. The return data from EC2, which is in XML form, is parsed
with XmlSimple and is used to directly construct the return data structure. This allows us
to know with some confidence that the data structure returned from AWS will always be consistent
@@ -116,7 +116,7 @@
that match those handed to us by Amazon EC2. ArgumentError exceptions will also
be thrown if you are making calls we know to be illegal or malformed. You should rescue
these exceptions in your application instead of parsing text responses. All exceptions
- descend from EC2::Error. You can see them all in exceptions.rb in the gem install.
+ descend from AWS::Error. You can see them all in exceptions.rb in the gem install.
* Added a full suite of test/spec unit tests which currently cover 100% of the public methods
in this library. We have abot 92% code coverage according to rcov. This has greatly enhanced
View
24 README.rdoc
@@ -57,9 +57,9 @@ The following gems should be installed automatically as part of your install of
== Using amazon-ec2
-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.
+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.
-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.
+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.
=== Setting up
@@ -90,11 +90,11 @@ You can verify that this setup is complete by running the 'set' in a command win
The library exposes one main interface module
- EC2::Base
+ AWS::EC2::Base
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:
- @ec2 = EC2::Base.new(:access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY)
+ @ec2 = AWS::EC2::Base.new(:access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY)
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.
@@ -144,28 +144,28 @@ If you're not in front of a terminal shell now (perhaps you're browsing this sit
returns : a string representation of ALL images
>> @ec2.describe_images.to_s
- returns : an Array of EC2::Response objects, each an EC2 image and its data
+ returns : an Array of AWS::Response objects, each an EC2 image and its data
>> @ec2.describe_images.imagesSet.item
>> @ec2.describe_images.imagesSet.item[0] (a hash representing a single item in that array)
>> @ec2.describe_images.imagesSet.item[0].to_s (a String representation of that item)
>> @ec2.describe_images.imagesSet.item[0].to_s
- => "#<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 ...>>"
+ => "#<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 ...>>"
=== Ruby script usage example:
-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).
+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).
#!/usr/bin/env ruby
require 'rubygems'
- require 'EC2'
+ require 'AWS'
ACCESS_KEY_ID = '--YOUR AWS ACCESS KEY ID--'
SECRET_ACCESS_KEY = '--YOUR AWS SECRET ACCESS KEY--'
- ec2 = EC2::Base.new(:access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY)
+ ec2 = AWS::EC2::Base.new(:access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY)
puts "----- listing images owned by 'amazon' -----"
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
[some controller code ...]
- ec2 = EC2::Base.new(:access_key_id => "YOUR_AWS_ACCESS_KEY_ID", :secret_access_key => "YOUR_AWS_SECRET_ACCESS_KEY")
+ ec2 = AWS::EC2::Base.new(:access_key_id => "YOUR_AWS_ACCESS_KEY_ID", :secret_access_key => "YOUR_AWS_SECRET_ACCESS_KEY")
# get ALL public images
@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
<% end %>
-=== Important notes regarding the structure of EC2::Response Objects
+=== Important notes regarding the structure of AWS::Response Objects
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:
@@ -303,7 +303,7 @@ So, for example, if you wanted to get the image ID of the third image listed in
>> puts @ec2.describe_images(:owner_id => 'amazon').imagesSet.item[2].imageId
ami-23b6534a
-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.
+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.
== Additional Resources
View
6 bin/ec2-gem-example.rb
@@ -9,7 +9,7 @@
# Home:: http://github.com/grempe/amazon-ec2/tree/master
#++
-require File.dirname(__FILE__) + '/../lib/EC2'
+require File.dirname(__FILE__) + '/../lib/AWS'
require 'pp'
# pull these from the local shell environment variables set in ~/.bash_login
@@ -34,10 +34,10 @@
# test different servers by running something like:
# export EC2_URL='https://ec2.amazonaws.com';./bin/ec2-gem-example.rb
if ENV['EC2_URL']
- ec2 = EC2::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY, :server => URI.parse(ENV['EC2_URL']).host )
+ ec2 = AWS::EC2::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY, :server => URI.parse(ENV['EC2_URL']).host )
else
# default server is US ec2.amazonaws.com
- ec2 = EC2::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY )
+ ec2 = AWS::EC2::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY )
end
puts "----- ec2.methods.sort -----"
View
4 bin/ec2-gem-profile.rb
@@ -2,9 +2,9 @@
# Basic single command application that we can call with perftools.rb to get consistent results.
-require File.dirname(__FILE__) + '/../lib/EC2'
+require File.dirname(__FILE__) + '/../lib/AWS'
ACCESS_KEY_ID = ENV['AMAZON_ACCESS_KEY_ID']
SECRET_ACCESS_KEY = ENV['AMAZON_SECRET_ACCESS_KEY']
-ec2 = EC2::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY )
+ec2 = AWS::EC2::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY )
@images = ec2.describe_images
View
8 bin/ec2sh
@@ -19,9 +19,9 @@
# macbook-pro:~ glenn$ ec2sh
# >> @ec2.describe_images
-# => [#<EC2::Item image_location...
+# => [#<AWS::EC2::Item image_location...
-ec2_lib = File.dirname(__FILE__) + '/../lib/EC2'
+ec2_lib = File.dirname(__FILE__) + '/../lib/AWS'
setup = File.dirname(__FILE__) + '/setup'
irb_name = RUBY_PLATFORM =~ /mswin32/ ? 'irb.bat' : 'irb'
@@ -48,15 +48,15 @@ if ( ENV['AMAZON_ACCESS_KEY_ID'] && ENV['AMAZON_SECRET_ACCESS_KEY'] )
returns : a string representation of ALL images
>> @ec2.describe_images.to_s
- returns : an Array of EC2::Response objects, each an EC2 image and its data
+ returns : an Array of AWS::Response objects, each an EC2 image and its data
>> @ec2.describe_images.imagesSet.item
>> @ec2.describe_images.imagesSet.item[0] (a hash representing a single item in that array)
>> @ec2.describe_images.imagesSet.item[0].to_s (a String representation of that item)
MESSAGE
puts welcome_message
- exec "#{irb_name} -r #{ec2_lib} -r #{setup} --simple-prompt"
+ exec "#{irb_name} -r #{ec2_lib} -r #{elb_lib} -r #{setup} --simple-prompt"
else
puts "You must define AMAZON_ACCESS_KEY_ID and AMAZON_SECRET_ACCESS_KEY as shell environment variables before running #{$0}!"
end
View
3 bin/setup.rb
@@ -17,7 +17,8 @@
if ENV['EC2_URL']
opts[:server] = URI.parse(ENV['EC2_URL']).host
end
- @ec2 = EC2::Base.new(opts)
+ @ec2 = AWS::EC2::Base.new(opts)
+ @elb = AWS::ELB::Base.new(opts)
end
puts "EC2 Server: #{opts[:server]}"
View
104 lib/EC2.rb → lib/AWS.rb
@@ -1,46 +1,17 @@
-#--
-# Amazon Web Services EC2 Query API Ruby library
-#
-# Ruby Gem Name:: amazon-ec2
-# Author:: Glenn Rempe (mailto:glenn@rempe.us)
-# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
-# License:: Distributes under the same terms as Ruby
-# Home:: http://github.com/grempe/amazon-ec2/tree/master
-#++
-
-%w[ base64 cgi openssl digest/sha1 net/https rexml/document time ostruct ].each { |f| require f }
-
-# Require any lib files that we have bundled with this Ruby Gem in the lib/EC2 directory.
-# Parts of the EC2 module and Base class are broken out into separate
+# Require any lib files that we have bundled with this Ruby Gem in the lib/AWS directory.
+# Parts of the AWS module and Base class are broken out into separate
# files for maintainability and are organized by the functional groupings defined
-# in the EC2 API developers guide.
-Dir[File.join(File.dirname(__FILE__), 'EC2/**/*.rb')].sort.each { |lib| require lib }
-
-module EC2
-
- # Which host FQDN will we connect to for all API calls to AWS?
- # If EC2_URL is defined in the users ENV we can use that. It is
- # expected that this var is set with something like:
- # export EC2_URL='https://ec2.amazonaws.com'
- #
- if ENV['EC2_URL']
- EC2_URL = ENV['EC2_URL']
- VALID_HOSTS = ['https://ec2.amazonaws.com', 'https://us-east-1.ec2.amazonaws.com', 'https://eu-west-1.ec2.amazonaws.com']
- raise ArgumentError, "Invalid EC2_URL environment variable : #{EC2_URL}" unless VALID_HOSTS.include?(EC2_URL)
- DEFAULT_HOST = URI.parse(EC2_URL).host
- else
- # default US host
- DEFAULT_HOST = 'ec2.amazonaws.com'
- end
+# in the AWS API developers guide.
- # This is the version of the API as defined by Amazon Web Services
- API_VERSION = '2008-12-01'
+%w[ base64 cgi openssl digest/sha1 net/https rexml/document time ostruct ].each { |f| require f }
+
+module AWS
# Builds the canonical string for signing. This strips out all '&', '?', and '='
# from the query string to be signed.
# Note: The parameters in the path passed in must already be sorted in
# case-insensitive alphabetical order and must not be url encoded.
- def EC2.canonical_string(params, host = DEFAULT_HOST, method="POST", base="/")
+ def AWS.canonical_string(params, host, method="POST", base="/")
# Sort, and encode parameters into a canonical string.
sorted_params = params.sort {|x,y| x[0] <=> y[0]}
encoded_params = sorted_params.collect do |p|
@@ -64,7 +35,7 @@ def EC2.canonical_string(params, host = DEFAULT_HOST, method="POST", base="/")
# hmac-sha1 sum, and then base64 encoding it. Optionally, it will also
# url encode the result of that to protect the string if it's going to
# be used as a query string parameter.
- def EC2.encode(secret_access_key, str, urlencode=true)
+ def AWS.encode(secret_access_key, str, urlencode=true)
digest = OpenSSL::Digest::Digest.new('sha1')
b64_hmac =
Base64.encode64(
@@ -76,26 +47,7 @@ def EC2.encode(secret_access_key, str, urlencode=true)
return b64_hmac
end
end
-
-
- #Introduction:
- #
- # The library exposes one main interface class, 'EC2::Base'.
- # This class provides all the methods for using the EC2 service
- # including the handling of header signing and other security issues .
- # This class uses Net::HTTP to interface with the EC2 Query API interface.
- #
- #Required Arguments:
- #
- # :access_key_id => String (default : "")
- # :secret_access_key => String (default : "")
- #
- #Optional Arguments:
- #
- # :use_ssl => Boolean (default : true)
- # :server => String (default : 'ec2.amazonaws.com')
- # :proxy_server => String (default : nil)
- #
+
class Base
attr_reader :use_ssl, :server, :proxy_server, :port
@@ -105,7 +57,7 @@ def initialize( options = {} )
options = { :access_key_id => "",
:secret_access_key => "",
:use_ssl => true,
- :server => DEFAULT_HOST,
+ :server => default_host,
:proxy_server => nil
}.merge(options)
@@ -149,7 +101,7 @@ def initialize( options = {} )
end
- private
+ protected
# pathlist is a utility method which takes a key string and and array as input.
# It converts the array into a Hash with the hash key being 'Key.n' where
@@ -172,7 +124,20 @@ def pathlist(key, arr)
end
params
end
-
+
+ # Same as _pathlist_ except it deals with arrays of hashes.
+ # So if you pass in args
+ # ("People", [{:name=>'jon', :age=>'22'}, {:name=>'chris'}], {:name => 'Name', :age => 'Age'}) you should get
+ # {"People.1.Name"=>"jon", "People.1.Age"=>'22', 'People.2.Name'=>'chris'}
+ def pathhashlist(key, arr_of_hashes, mappings)
+ params ={}
+ arr_of_hashes.each_with_index do |hash, i|
+ hash.each do |attribute, value|
+ params["#{key}.#{i+1}.#{mappings[attribute]}"] = value
+ end
+ end
+ params
+ end
# Make the connection to AWS EC2 passing in our request. This is generally called from
# within a 'Response' class object or one of its sub-classes so the response is interpreted
@@ -188,7 +153,7 @@ def make_request(action, params, data='')
"SignatureVersion" => "2",
"SignatureMethod" => 'HmacSHA1',
"AWSAccessKeyId" => @access_key_id,
- "Version" => API_VERSION,
+ "Version" => api_version,
"Timestamp"=>Time.now.getutc.iso8601} )
sig = get_aws_auth_param(params, @secret_access_key, @server)
@@ -205,7 +170,7 @@ def make_request(action, params, data='')
# Make a call to see if we need to throw an error based on the response given by EC2
# All error classes are defined in EC2/exceptions.rb
- ec2_error?(response)
+ aws_error?(response)
return response
@@ -215,8 +180,8 @@ def make_request(action, params, data='')
# Set the Authorization header using AWS signed header authentication
def get_aws_auth_param(params, secret_access_key, server)
- canonical_string = EC2.canonical_string(params, server)
- encoded_canonical = EC2.encode(secret_access_key, canonical_string)
+ canonical_string = AWS.canonical_string(params, server)
+ encoded_canonical = AWS.encode(secret_access_key, canonical_string)
end
# allow us to have a one line call in each method which will do all of the work
@@ -238,7 +203,7 @@ def response_generator( options = {} )
# Raises the appropriate error if the specified Net::HTTPResponse object
# contains an Amazon EC2 error; returns +false+ otherwise.
- def ec2_error?(response)
+ def aws_error?(response)
# return false if we got a HTTP 200 code,
# otherwise there is some type of error (40x,50x) and
@@ -266,14 +231,15 @@ def ec2_error?(response)
# Raise one of our specific error classes if it exists.
# otherwise, throw a generic EC2 Error with a few details.
- if EC2.const_defined?(error_code)
- raise EC2.const_get(error_code), error_message
+ if AWS.const_defined?(error_code)
+ raise AWS.const_get(error_code), error_message
else
- raise EC2::Error, error_message
+ raise AWS::Error, error_message
end
end
end
-
end
+
+Dir[File.join(File.dirname(__FILE__), 'AWS/*.rb')].sort.each { |lib| require lib }
View
67 lib/AWS/EC2.rb
@@ -0,0 +1,67 @@
+#--
+# Amazon Web Services EC2 Query API Ruby library
+#
+# Ruby Gem Name:: amazon-ec2
+# Author:: Glenn Rempe (mailto:glenn@rempe.us)
+# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
+# License:: Distributes under the same terms as Ruby
+# Home:: http://github.com/grempe/amazon-ec2/tree/master
+#++
+
+# Require any lib files that we have bundled with this Ruby Gem in the lib/EC2 directory.
+# Parts of the EC2 module and Base class are broken out into separate
+# files for maintainability and are organized by the functional groupings defined
+# in the EC2 API developers guide.
+Dir[File.join(File.dirname(__FILE__), 'EC2/**/*.rb')].sort.each { |lib| require lib }
+
+module AWS
+ module EC2
+
+ # Which host FQDN will we connect to for all API calls to AWS?
+ # If EC2_URL is defined in the users ENV we can use that. It is
+ # expected that this var is set with something like:
+ # export EC2_URL='https://ec2.amazonaws.com'
+ #
+ if ENV['EC2_URL']
+ EC2_URL = ENV['EC2_URL']
+ VALID_HOSTS = ['https://ec2.amazonaws.com', 'https://us-east-1.ec2.amazonaws.com', 'https://eu-west-1.ec2.amazonaws.com']
+ raise ArgumentError, "Invalid EC2_URL environment variable : #{EC2_URL}" unless VALID_HOSTS.include?(EC2_URL)
+ DEFAULT_HOST = URI.parse(EC2_URL).host
+ else
+ # default US host
+ DEFAULT_HOST = 'ec2.amazonaws.com'
+ end
+
+ # This is the version of the API as defined by Amazon Web Services
+ API_VERSION = '2008-12-01'
+
+ #Introduction:
+ #
+ # The library exposes one main interface class, 'AWS::EC2::Base'.
+ # This class provides all the methods for using the EC2 service
+ # including the handling of header signing and other security issues .
+ # This class uses Net::HTTP to interface with the EC2 Query API interface.
+ #
+ #Required Arguments:
+ #
+ # :access_key_id => String (default : "")
+ # :secret_access_key => String (default : "")
+ #
+ #Optional Arguments:
+ #
+ # :use_ssl => Boolean (default : true)
+ # :server => String (default : 'ec2.amazonaws.com')
+ # :proxy_server => String (default : nil)
+ #
+ class Base < AWS::Base
+ def api_version
+ API_VERSION
+ end
+
+ def default_host
+ DEFAULT_HOST
+ end
+ end
+
+ end
+end
View
43 lib/AWS/EC2/availability_zones.rb
@@ -0,0 +1,43 @@
+#--
+# Amazon Web Services EC2 Query API Ruby library
+#
+# Ruby Gem Name:: amazon-ec2
+# Author:: Glenn Rempe (mailto:glenn@rempe.us)
+# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
+# License:: Distributes under the same terms as Ruby
+# Home:: http://github.com/grempe/amazon-ec2/tree/master
+#++
+
+module AWS
+ module EC2
+
+ class Base < AWS::Base
+
+ #Amazon Developer Guide Docs:
+ #
+ # The DescribeAvailabilityZones operation describes availability zones that are currently
+ # available to the account and their states.
+ #
+ # An optional list of zone names can be passed.
+ #
+ #Required Arguments:
+ #
+ # none
+ #
+ #Optional Arguments:
+ #
+ # :zone_name => Array (default : [])
+ #
+
+ def describe_availability_zones( options = {} )
+
+ options = { :zone_name => [] }.merge(options)
+
+ params = pathlist("ZoneName", options[:zone_name] )
+
+ return response_generator(:action => "DescribeAvailabilityZones", :params => params)
+
+ end
+ end
+ end
+end
View
46 lib/AWS/EC2/console.rb
@@ -0,0 +1,46 @@
+#--
+# Amazon Web Services EC2 Query API Ruby library
+#
+# Ruby Gem Name:: amazon-ec2
+# Author:: Glenn Rempe (mailto:glenn@rempe.us)
+# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
+# License:: Distributes under the same terms as Ruby
+# Home:: http://github.com/grempe/amazon-ec2/tree/master
+#++
+
+module AWS
+ module EC2
+
+ class Base < AWS::Base
+
+ #Amazon Developer Guide Docs:
+ #
+ # The GetConsoleOutput operation retrieves console output that has been posted for the specified instance.
+ #
+ # Instance console output is buffered and posted shortly after instance boot, reboot and once the instance
+ # is terminated. Only the most recent 64 KB of posted output is available. Console output is available for
+ # at least 1 hour after the most recent post.
+ #
+ #Required Arguments:
+ #
+ # :instance_id => String (default : "")
+ #
+ #Optional Arguments:
+ #
+ # none
+ #
+ def get_console_output( options ={} )
+
+ options = {:instance_id => ""}.merge(options)
+
+ raise ArgumentError, "No instance ID provided" if options[:instance_id].nil? || options[:instance_id].empty?
+
+ params = { "InstanceId" => options[:instance_id] }
+
+ return response_generator(:action => "GetConsoleOutput", :params => params)
+
+ end
+ end
+
+ end
+end
View
154 lib/AWS/EC2/elastic_ips.rb
@@ -0,0 +1,154 @@
+#--
+# Amazon Web Services EC2 Query API Ruby library
+#
+# Ruby Gem Name:: amazon-ec2
+# Author:: Glenn Rempe (mailto:glenn@rempe.us)
+# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
+# License:: Distributes under the same terms as Ruby
+# Home:: http://github.com/grempe/amazon-ec2/tree/master
+#++
+
+module AWS
+ module EC2
+ class Base < AWS::Base
+
+
+ #Amazon Developer Guide Docs:
+ #
+ # The AllocateAddress operation acquires an elastic IP address for use with your account.
+ #
+ #Required Arguments:
+ #
+ # none
+ #
+ #Optional Arguments:
+ #
+ # none
+ #
+ def allocate_address
+
+ return response_generator(:action => "AllocateAddress")
+
+ end
+
+ #Amazon Developer Guide Docs:
+ #
+ # The DescribeAddresses operation lists elastic IP addresses assigned to your account.
+ #
+ #Required Arguments:
+ #
+ # :public_ip => Array (default : [], can be empty)
+ #
+ #Optional Arguments:
+ #
+ # none
+ #
+ def describe_addresses( options = {} )
+
+ options = { :public_ip => [] }.merge(options)
+
+ params = pathlist("PublicIp", options[:public_ip])
+
+ return response_generator(:action => "DescribeAddresses", :params => params)
+
+ end
+
+ #Amazon Developer Guide Docs:
+ #
+ # The ReleaseAddress operation releases an elastic IP address associated with your account.
+ #
+ # If you run this operation on an elastic IP address that is already released, the address
+ # might be assigned to another account which will cause Amazon EC2 to return an error.
+ #
+ # Note : Releasing an IP address automatically disassociates it from any instance
+ # with which it is associated. For more information, see DisassociateAddress.
+ #
+ # Important! After releasing an elastic IP address, it is released to the IP
+ # address pool and might no longer be available to your account. Make sure
+ # to update your DNS records and any servers or devices that communicate
+ # with the address.
+ #
+ #Required Arguments:
+ #
+ # :public_ip => String (default : '')
+ #
+ #Optional Arguments:
+ #
+ # none
+ #
+ def release_address( options = {} )
+
+ options = { :public_ip => '' }.merge(options)
+
+ raise ArgumentError, "No ':public_ip' provided" if options[:public_ip].nil? || options[:public_ip].empty?
+
+ params = { "PublicIp" => options[:public_ip] }
+
+ return response_generator(:action => "ReleaseAddress", :params => params)
+
+ end
+
+ #Amazon Developer Guide Docs:
+ #
+ # The AssociateAddress operation associates an elastic IP address with an instance.
+ #
+ # If the IP address is currently assigned to another instance, the IP address
+ # is assigned to the new instance. This is an idempotent operation. If you enter
+ # it more than once, Amazon EC2 does not return an error.
+ #
+ #Required Arguments:
+ #
+ # :instance_id => String (default : '')
+ # :public_ip => String (default : '')
+ #
+ #Optional Arguments:
+ #
+ # none
+ #
+ def associate_address( options = {} )
+
+ options = { :instance_id => '', :public_ip => '' }.merge(options)
+
+ raise ArgumentError, "No ':instance_id' provided" if options[:instance_id].nil? || options[:instance_id].empty?
+ raise ArgumentError, "No ':public_ip' provided" if options[:public_ip].nil? || options[:public_ip].empty?
+
+ params = {
+ "InstanceId" => options[:instance_id],
+ "PublicIp" => options[:public_ip]
+ }
+
+ return response_generator(:action => "AssociateAddress", :params => params)
+
+ end
+
+ #Amazon Developer Guide Docs:
+ #
+ # The DisassociateAddress operation disassociates the specified elastic IP
+ # address from the instance to which it is assigned. This is an idempotent
+ # operation. If you enter it more than once, Amazon EC2 does not return
+ # an error.
+ #
+ #Required Arguments:
+ #
+ # :public_ip => String (default : '')
+ #
+ #Optional Arguments:
+ #
+ # none
+ #
+ def disassociate_address( options = {} )
+
+ options = { :public_ip => '' }.merge(options)
+
+ raise ArgumentError, "No ':public_ip' provided" if options[:public_ip].nil? || options[:public_ip].empty?
+
+ params = { "PublicIp" => options[:public_ip] }
+
+ return response_generator(:action => "DisassociateAddress", :params => params)
+
+ end
+
+ end
+
+ end
+end
View
168 lib/AWS/EC2/image_attributes.rb
@@ -0,0 +1,168 @@
+#--
+# Amazon Web Services EC2 Query API Ruby library
+#
+# Ruby Gem Name:: amazon-ec2
+# Author:: Glenn Rempe (mailto:glenn@rempe.us)
+# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
+# License:: Distributes under the same terms as Ruby
+# Home:: http://github.com/grempe/amazon-ec2/tree/master
+#++
+
+module AWS
+ module EC2
+
+ class Base < AWS::Base
+
+ #Amazon Developer Guide Docs:
+ #
+ # The ModifyImageAttribute operation modifies an attribute of an AMI. The following attributes may
+ # currently be modified:
+ #
+ # 'launchPermission' : Controls who has permission to launch the AMI. Launch permissions can be
+ # granted to specific users by adding userIds. The AMI can be made public by adding the 'all' group.
+ #
+ # 'productCodes' : Associates product codes with AMIs. This allows a developer to charge a user extra
+ # for using the AMIs. productCodes is a write once attribute - once it has been set it can not be
+ # changed or removed. Currently only one product code is supported per AMI.
+ #
+ #Required Arguments:
+ #
+ # :image_id => String (default : "")
+ # :attribute => String ('launchPermission' or 'productCodes', default : "launchPermission")
+ # :operation_type => String (default : "")
+ #
+ #Optional Arguments:
+ #
+ # :user_id => Array (default : [])
+ # :group => Array (default : [])
+ # :product_code => Array (default : [])
+ #
+ def modify_image_attribute( options = {} )
+
+ # defaults
+ options = { :image_id => "",
+ :attribute => "launchPermission",
+ :operation_type => "",
+ :user_id => [],
+ :group => [],
+ :product_code => [] }.merge(options)
+
+ raise ArgumentError, "No ':image_id' provided" if options[:image_id].nil? || options[:image_id].empty?
+ raise ArgumentError, "No ':attribute' provided" if options[:attribute].nil? || options[:attribute].empty?
+
+ # OperationType is not required if modifying a product code.
+ unless options[:attribute] == 'productCodes'
+ raise ArgumentError, "No ':operation_type' provided" if options[:operation_type].nil? || options[:operation_type].empty?
+ end
+
+ params = {
+ "ImageId" => options[:image_id],
+ "Attribute" => options[:attribute],
+ "OperationType" => options[:operation_type]
+ }
+
+ # test options provided and make sure they are valid
+ case options[:attribute]
+ when "launchPermission"
+
+ unless options[:operation_type] == "add" || options[:operation_type] == "remove"
+ raise ArgumentError, ":operation_type was #{options[:operation_type].to_s} but must be either 'add' or 'remove'"
+ end
+
+ if (options[:user_id].nil? || options[:user_id].empty?) && (options[:group].nil? || options[:group].empty?)
+ raise ArgumentError, "Option :attribute=>'launchPermission' requires ':user_id' or ':group' options to also be specified"
+ end
+ params.merge!(pathlist("UserId", options[:user_id])) unless options[:user_id].nil?
+ params.merge!(pathlist("Group", options[:group])) unless options[:group].nil?
+ when "productCodes"
+ if (options[:product_code].nil? || options[:product_code].empty?)
+ raise ArgumentError, "Option :attribute=>'productCodes' requires ':product_code' to be specified"
+ end
+ params.merge!(pathlist("ProductCode", options[:product_code])) unless options[:product_code].nil?
+ else
+ raise ArgumentError, "attribute : #{options[:attribute].to_s} is not an known attribute."
+ end
+
+ return response_generator(:action => "ModifyImageAttribute", :params => params)
+
+ end
+
+ #Amazon Developer Guide Docs:
+ #
+ # The DescribeImageAttribute operation returns information about an attribute of an AMI.
+ #
+ #Required Arguments:
+ #
+ # :image_id => String (default : "")
+ # :attribute => String ("launchPermission" or "productCodes", default : "launchPermission")
+ #
+ #Optional Arguments:
+ #
+ # none
+ #
+ def describe_image_attribute( options = {} )
+
+ # defaults
+ options = {:image_id => "",
+ :attribute => "launchPermission"
+ }.merge(options)
+
+ raise ArgumentError, "No ':image_id' provided" if options[:image_id].nil? || options[:image_id].empty?
+ raise ArgumentError, "No ':attribute' provided" if options[:attribute].nil? || options[:attribute].empty?
+
+ params = { "ImageId" => options[:image_id], "Attribute" => options[:attribute] }
+
+ # test options provided and make sure they are valid
+ case options[:attribute]
+ when "launchPermission", "productCodes"
+ # these args are ok
+ else
+ raise ArgumentError, "attribute : #{options[:attribute].to_s} is not an known attribute."
+ end
+
+ return response_generator(:action => "DescribeImageAttribute", :params => params)
+
+ end
+
+
+ #Amazon Developer Guide Docs:
+ #
+ # The ResetImageAttribute operation resets an attribute of an AMI to its default value.
+ #
+ #Required Arguments:
+ #
+ # :image_id => String (default : "")
+ # :attribute => String (default : "launchPermission")
+ #
+ #Optional Arguments:
+ #
+ # none
+ #
+ def reset_image_attribute( options = {} )
+
+ # defaults
+ options = {:image_id => "",
+ :attribute => "launchPermission"}.merge(options)
+
+ raise ArgumentError, "No ':image_id' provided" if options[:image_id].nil? || options[:image_id].empty?
+ raise ArgumentError, "No ':attribute' provided" if options[:attribute].nil? || options[:attribute].empty?
+
+ params = {"ImageId" => options[:image_id],
+ "Attribute" => options[:attribute] }
+
+ # test options provided and make sure they are valid
+ case options[:attribute]
+ when "launchPermission"
+ # these args are ok
+ else
+ raise ArgumentError, "attribute : #{options[:attribute].to_s} is not an known attribute."
+ end
+
+ return response_generator(:action => "ResetImageAttribute", :params => params)
+
+ end
+
+ end
+
+ end
+end
View
136 lib/AWS/EC2/images.rb
@@ -0,0 +1,136 @@
+#--
+# Amazon Web Services EC2 Query API Ruby library
+#
+# Ruby Gem Name:: amazon-ec2
+# Author:: Glenn Rempe (mailto:glenn@rempe.us)
+# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
+# License:: Distributes under the same terms as Ruby
+# Home:: http://github.com/grempe/amazon-ec2/tree/master
+#++
+
+module AWS
+ module EC2
+
+ class Base < AWS::Base
+
+ #Amazon Developer Guide Docs:
+ #
+ # The RegisterImage operation registers an AMI with Amazon EC2. Images must be registered before
+ # they can be launched. Each AMI is associated with an unique ID which is provided by the EC2
+ # service via the Registerimage operation. As part of the registration process, Amazon EC2 will
+ # retrieve the specified image manifest from Amazon S3 and verify that the image is owned by the
+ # user requesting image registration. The image manifest is retrieved once and stored within the
+ # Amazon EC2 network. Any modifications to an image in Amazon S3 invalidate this registration.
+ # If you do have to make changes and upload a new image deregister the previous image and register
+ # the new image.
+ #
+ #Required Arguments:
+ #
+ # :image_location => String (default : "")
+ #
+ #Optional Arguments:
+ #
+ # none
+ #
+ def register_image( options = {} )
+
+ options = {:image_location => ""}.merge(options)
+
+ raise ArgumentError, "No :image_location provided" if options[:image_location].nil? || options[:image_location].empty?
+
+ params = { "ImageLocation" => options[:image_location] }
+
+ return response_generator(:action => "RegisterImage", :params => params)
+
+ end
+
+ #Amazon Developer Guide Docs:
+ #
+ # The DescribeImages operation returns information about AMIs available for use by the user. This
+ # includes both public AMIs (those available for any user to launch) and private AMIs (those owned by
+ # the user making the request and those owned by other users that the user making the request has explicit
+ # launch permissions for).
+ #
+ # The list of AMIs returned can be modified via optional lists of AMI IDs, owners or users with launch
+ # permissions. If all three optional lists are empty all AMIs the user has launch permissions for are
+ # returned. Launch permissions fall into three categories:
+ #
+ # Launch Permission Description
+ #
+ # public - The all group has launch permissions for the AMI. All users have launch permissions for these AMIs.
+ # explicit - The owner of the AMIs has granted a specific user launch permissions for the AMI.
+ # implicit - A user has implicit launch permissions for all AMIs he or she owns.
+ #
+ # If one or more of the lists are specified the result set is the intersection of AMIs matching the criteria of
+ # the individual lists.
+ #
+ # Providing the list of AMI IDs requests information for those AMIs only. If no AMI IDs are provided,
+ # information of all relevant AMIs will be returned. If an AMI is specified that does not exist a fault is
+ # returned. If an AMI is specified that exists but the user making the request does not have launch
+ # permissions for, then that AMI will not be included in the returned results.
+ #
+ # Providing the list of owners requests information for AMIs owned by the specified owners only. Only
+ # AMIs the user has launch permissions for are returned. The items of the list may be account ids for
+ # AMIs owned by users with those account ids, amazon for AMIs owned by Amazon or self for AMIs
+ # owned by the user making the request.
+ #
+ # The executable list may be provided to request information for AMIs that only the specified users have
+ # launch permissions for. The items of the list may be account ids for AMIs owned by the user making the
+ # request that the users with the specified account ids have explicit launch permissions for, self for AMIs
+ # the user making the request has explicit launch permissions for or all for public AMIs.
+ #
+ # Deregistered images will be included in the returned results for an unspecified interval subsequent to
+ # deregistration.
+ #
+ #Required Arguments:
+ #
+ # none
+ #
+ #Optional Arguments:
+ #
+ # :image_id => Array (default : [])
+ # :owner_id => Array (default : [])
+ # :executable_by => Array (default : [])
+ #
+ def describe_images( options = {} )
+
+ options = { :image_id => [], :owner_id => [], :executable_by => [] }.merge(options)
+
+ params = pathlist( "ImageId", options[:image_id] )
+ params.merge!(pathlist( "Owner", options[:owner_id] ))
+ params.merge!(pathlist( "ExecutableBy", options[:executable_by] ))
+
+ return response_generator(:action => "DescribeImages", :params => params)
+
+ end
+
+ #Amazon Developer Guide Docs:
+ #
+ # The DeregisterImage operation deregisters an AMI. Once deregistered, instances of the AMI may no
+ # longer be launched.
+ #
+ #Required Arguments:
+ #
+ # :image_id => String (default : "")
+ #
+ #Optional Arguments:
+ #
+ # none
+ #
+ def deregister_image( options = {} )
+
+ # defaults
+ options = { :image_id => "" }.merge(options)
+
+ raise ArgumentError, "No :image_id provided" if options[:image_id].nil? || options[:image_id].empty?
+
+ params = { "ImageId" => options[:image_id] }
+
+ return response_generator(:action => "DeregisterImage", :params => params)
+
+ end
+
+ end
+
+ end
+end
View
218 lib/AWS/EC2/instances.rb
@@ -0,0 +1,218 @@
+#--
+# Amazon Web Services EC2 Query API Ruby library
+#
+# Ruby Gem Name:: amazon-ec2
+# Author:: Glenn Rempe (mailto:glenn@rempe.us)
+# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
+# License:: Distributes under the same terms as Ruby
+# Home:: http://github.com/grempe/amazon-ec2/tree/master
+#++
+
+module AWS
+ module EC2
+
+ class Base < AWS::Base
+
+ #Amazon Developer Guide Docs:
+ #
+ # The RunInstances operation launches a specified number of instances.
+ #
+ # Note : The Query version of RunInstances only allows instances of a single AMI to be launched in
+ # one call. This is different from the SOAP API call of the same name but similar to the
+ # ec2-run-instances command line tool.
+ #
+ # If Amazon EC2 cannot launch the minimum number AMIs you request, no instances launch. If there
+ # is insufficient capacity to launch the maximum number of AMIs you request, Amazon EC2 launches
+ # as many as possible to satisfy the requested maximum values.
+ #
+ # Every instance is launched in a security group. If you do not specify a security group at
+ # launch, the instances start in the default security group.
+ #
+ # An optional instance type can be specified. Currently supported types are 'm1.small', 'm1.large',
+ # 'm1.xlarge' and the high CPU types 'c1.medium' and 'c1.xlarge'. 'm1.small' is the default
+ # if no instance_type is specified.
+ #
+ # You can provide an optional key pair ID for each image in the launch request. All instances
+ # that are created from images that use this key pair will have access to the associated public
+ # key at boot. You can use this key to provide secure access to an instance of an image on a
+ # per-instance basis. Amazon EC2 public images use this feature to provide secure access
+ # without passwords.
+ #
+ # Important! Launching public images without a key pair ID will leave them inaccessible.
+ #
+ # The public key material is made available to the instance at boot time by placing it in a file named
+ # openssh_id.pub on a logical device that is exposed to the instance as /dev/sda2 (the ephemeral
+ # store). The format of this file is suitable for use as an entry within ~/.ssh/authorized_keys (the
+ # OpenSSH format). This can be done at boot time (as part of rclocal, for example) allowing for secure
+ # password-less access.
+ #
+ # Optional user data can be provided in the launch request. All instances comprising the launch
+ # request have access to this data (see Instance Metadata for details).
+ #
+ # If any of the AMIs have product codes attached for which the user has not subscribed,
+ # the RunInstances call will fail.
+ #
+ #Required Arguments:
+ #
+ # :image_id => String (Default : "")
+ # :min_count => Integer (default : 1 )
+ # :max_count => Integer (default : 1 )
+ #
+ #Optional Arguments:
+ #
+ # :key_name => String (default : nil)
+ # :group_id => Array (default : [])
+ # :user_data => String (default : nil)
+ # :addressing_type => String (default : "public")
+ # :instance_type => String (default : "m1.small")
+ # :kernel_id => String (default : nil)
+ # :availability_zone => String (default : nil)
+ # :base64_encoded => Boolean (default : false)
+ #
+ def run_instances( options = {} )
+
+ options = { :image_id => "",
+ :min_count => 1,
+ :max_count => 1,
+ :key_name => nil,
+ :group_id => [],
+ :user_data => nil,
+ :addressing_type => "public",
+ :instance_type => "m1.small",
+ :kernel_id => nil,
+ :availability_zone => nil,
+ :base64_encoded => false }.merge(options)
+
+ # Do some validation on the arguments provided
+ raise ArgumentError, ":image_id must be provided" if options[:image_id].nil? || options[:image_id].empty?
+ raise ArgumentError, ":min_count is not valid" unless options[:min_count].to_i > 0
+ raise ArgumentError, ":max_count is not valid" unless options[:max_count].to_i > 0
+ raise ArgumentError, ":addressing_type must be 'direct' or 'public'" unless options[:addressing_type] == "public" || options[:addressing_type] == "direct"
+ raise ArgumentError, ":instance_type must be 'm1.small', 'm1.large', 'm1.xlarge', 'c1.medium', or 'c1.xlarge'" unless options[:instance_type] == "m1.small" || options[:instance_type] == "m1.large" || options[:instance_type] == "m1.xlarge" || options[:instance_type] == "c1.medium" || options[:instance_type] == "c1.xlarge"
+ raise ArgumentError, ":base64_encoded must be 'true' or 'false'" unless options[:base64_encoded] == true || options[:base64_encoded] == false
+
+ user_data = extract_user_data(options)
+
+ params = {
+ "ImageId" => options[:image_id],
+ "MinCount" => options[:min_count].to_s,
+ "MaxCount" => options[:max_count].to_s,
+ }.merge(pathlist("SecurityGroup", options[:group_id]))
+
+ params["KeyName"] = options[:key_name] unless options[:key_name].nil?
+ params["UserData"] = user_data unless user_data.nil?
+ params["AddressingType"] = options[:addressing_type]
+ params["InstanceType"] = options[:instance_type]
+ params["KernelId"] = options[:kernel_id] unless options[:kernel_id].nil?
+ params["Placement.AvailabilityZone"] = options[:availability_zone] unless options[:availability_zone].nil?
+
+ return response_generator(:action => "RunInstances", :params => params)
+
+ end
+
+ # If :user_data is passed in then URL escape and Base64 encode it
+ # as needed. Need for URL Escape + Base64 encoding is determined
+ # by :base64_encoded param.
+ def extract_user_data(options)
+ return unless options[:user_data]
+ if options[:user_data]
+ if options[:base64_encoded]
+ Base64.encode64(options[:user_data]).gsub(/\n/,"").strip()
+ else
+ options[:user_data]
+ end
+ end
+ end
+
+
+ #Amazon Developer Guide Docs:
+ #
+ # The DescribeInstances operation returns information about instances owned by the user
+ # making the request.
+ #
+ # An optional list of instance IDs may be provided to request information for those instances only. If no
+ # instance IDs are provided, information of all relevant instances information will be returned. If an
+ # instance is specified that does not exist a fault is returned. If an instance is specified that exists but is not
+ # owned by the user making the request, then that instance will not be included in the returned results.
+ #
+ # Recently terminated instances will be included in the returned results for a small interval subsequent to
+ # their termination. This interval is typically of the order of one hour
+ #
+ #Required Arguments:
+ #
+ # none
+ #
+ #Optional Arguments:
+ #
+ # :instance_id => Array (default : [])
+ #
+ def describe_instances( options = {} )
+
+ options = { :instance_id => [] }.merge(options)
+
+ params = pathlist("InstanceId", options[:instance_id])
+
+ return response_generator(:action => "DescribeInstances", :params => params)
+
+ end
+
+
+ #Amazon Developer Guide Docs:
+ #
+ # The RebootInstances operation requests a reboot of one or more instances. This operation is
+ # asynchronous; it only queues a request to reboot the specified instance(s). The operation will succeed
+ # provided the instances are valid and belong to the user. Terminated instances will be ignored.
+ #
+ #Required Arguments:
+ #
+ # :instance_id => Array (default : [])
+ #
+ #Optional Arguments:
+ #
+ # none
+ #
+ def reboot_instances( options = {} )
+
+ # defaults
+ options = { :instance_id => [] }.merge(options)
+
+ raise ArgumentError, "No instance IDs provided" if options[:instance_id].nil? || options[:instance_id].empty?
+
+ params = pathlist("InstanceId", options[:instance_id])
+
+ return response_generator(:action => "RebootInstances", :params => params)
+
+ end
+
+
+ #Amazon Developer Guide Docs:
+ #
+ # The TerminateInstances operation shuts down one or more instances. This operation is idempotent
+ # and terminating an instance that is in the process of shutting down (or already terminated) will succeed.
+ # Terminated instances remain visible for a short period of time (approximately one hour) after
+ # termination, after which their instance ID is invalidated.
+ #
+ #Required Arguments:
+ #
+ # :instance_id => Array (default : [])
+ #
+ #Optional Arguments:
+ #
+ # none
+ #
+ def terminate_instances( options = {} )
+
+ options = { :instance_id => [] }.merge(options)
+
+ raise ArgumentError, "No :instance_id provided" if options[:instance_id].nil? || options[:instance_id].empty?
+
+ params = pathlist("InstanceId", options[:instance_id])
+
+ return response_generator(:action => "TerminateInstances", :params => params)
+
+ end
+
+ end
+
+ end
+end
View
96 lib/AWS/EC2/keypairs.rb
@@ -0,0 +1,96 @@
+#--
+# Amazon Web Services EC2 Query API Ruby library
+#
+# Ruby Gem Name:: amazon-ec2
+# Author:: Glenn Rempe (mailto:glenn@rempe.us)
+# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
+# License:: Distributes under the same terms as Ruby
+# Home:: http://github.com/grempe/amazon-ec2/tree/master
+#++
+
+module AWS
+ module EC2
+
+ class Base < AWS::Base
+
+
+ #Amazon Developer Guide Docs:
+ #
+ # The CreateKeyPair operation creates a new 2048 bit RSA keypair and returns a unique ID that can be
+ # used to reference this keypair when launching new instances.
+ #
+ #Required Arguments:
+ #
+ # :key_name => String (default : "")
+ #
+ #Optional Arguments:
+ #
+ # none
+ #
+ def create_keypair( options = {} )
+
+ # defaults
+ options = { :key_name => "" }.merge(options)
+
+ raise ArgumentError, "No :key_name provided" if options[:key_name].nil? || options[:key_name].empty?
+
+ params = { "KeyName" => options[:key_name] }
+
+ return response_generator(:action => "CreateKeyPair", :params => params)
+
+ end
+
+
+ #Amazon Developer Guide Docs:
+ #
+ # The DescribeKeyPairs operation returns information about keypairs available for use by the user
+ # making the request. Selected keypairs may be specified or the list may be left empty if information for
+ # all registered keypairs is required.
+ #
+ #Required Arguments:
+ #
+ # :key_name => Array (default : [])
+ #
+ #Optional Arguments:
+ #
+ # none
+ #
+ def describe_keypairs( options = {} )
+
+ options = { :key_name => [] }.merge(options)
+
+ params = pathlist("KeyName", options[:key_name] )
+
+ return response_generator(:action => "DescribeKeyPairs", :params => params)
+
+ end
+
+
+ #Amazon Developer Guide Docs:
+ #
+ # The DeleteKeyPair operation deletes a keypair.
+ #
+ #Required Arguments:
+ #
+ # :key_name => String (default : "")
+ #
+ #Optional Arguments:
+ #
+ # none
+ #
+ def delete_keypair( options = {} )
+
+ options = { :key_name => "" }.merge(options)
+
+ raise ArgumentError, "No :key_name provided" if options[:key_name].nil? || options[:key_name].empty?
+
+ params = { "KeyName" => options[:key_name] }
+
+ return response_generator(:action => "DeleteKeyPair", :params => params)
+
+ end
+
+ end
+
+ end
+end
View
45 lib/AWS/EC2/products.rb
@@ -0,0 +1,45 @@
+#--
+# Amazon Web Services EC2 Query API Ruby library
+#
+# Ruby Gem Name:: amazon-ec2
+# Author:: Glenn Rempe (mailto:glenn@rempe.us)
+# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
+# License:: Distributes under the same terms as Ruby
+# Home:: http://github.com/grempe/amazon-ec2/tree/master
+#++
+
+module AWS
+ module EC2
+
+ class Base < AWS::Base
+
+ #Amazon Developer Guide Docs:
+ #
+ # The ConfirmProductInstance operation returns true if the given product code is attached to the instance
+ # with the given instance id. False is returned if the product code is not attached to the instance.
+ #
+ #Required Arguments:
+ #
+ # :product_code => String (default : "")
+ # :instance_id => String (default : "")
+ #
+ #Optional Arguments:
+ #
+ # none
+ #
+ def confirm_product_instance( options ={} )
+
+ options = {:product_code => "", :instance_id => ""}.merge(options)
+
+ raise ArgumentError, "No product code provided" if options[:product_code].nil? || options[:product_code].empty?
+ raise ArgumentError, "No instance ID provided" if options[:instance_id].nil? || options[:instance_id].empty?
+
+ params = { "ProductCode" => options[:product_code], "InstanceId" => options[:instance_id] }
+
+ return response_generator(:action => "ConfirmProductInstance", :params => params)
+
+ end
+ end
+
+ end
+end
View
234 lib/AWS/EC2/security_groups.rb
@@ -0,0 +1,234 @@
+#--
+# Amazon Web Services EC2 Query API Ruby library
+#
+# Ruby Gem Name:: amazon-ec2
+# Author:: Glenn Rempe (mailto:glenn@rempe.us)
+# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
+# License:: Distributes under the same terms as Ruby
+# Home:: http://github.com/grempe/amazon-ec2/tree/master
+#++
+
+module AWS
+ module EC2
+
+ class Base < AWS::Base
+
+
+ #Amazon Developer Guide Docs:
+ #
+ # The CreateSecurityGroup operation creates a new security group. Every instance is launched
+ # in a security group. If none is specified as part of the launch request then instances
+ # are launched in the default security group. Instances within the same security group have
+ # unrestricted network access to one another. Instances will reject network access attempts from other
+ # instances in a different security group. As the owner of instances you may grant or revoke specific
+ # permissions using the AuthorizeSecurityGroupIngress and RevokeSecurityGroupIngress operations.
+ #
+ #Required Arguments:
+ #
+ # :group_name => String (default : "")
+ # :group_description => String (default : "")
+ #
+ #Optional Arguments:
+ #
+ # none
+ #
+ def create_security_group( options = {} )
+
+ options = {:group_name => "",
+ :group_description => ""
+ }.merge(options)
+
+ raise ArgumentError, "No :group_name provided" if options[:group_name].nil? || options[:group_name].empty?
+ raise ArgumentError, "No :group_description provided" if options[:group_description].nil? || options[:group_description].empty?
+
+ params = {
+ "GroupName" => options[:group_name],
+ "GroupDescription" => options[:group_description]
+ }
+
+ return response_generator(:action => "CreateSecurityGroup", :params => params)
+
+ end
+
+
+ #Amazon Developer Guide Docs:
+ #
+ # The DescribeSecurityGroups operation returns information about security groups owned by the
+ # user making the request.
+ #
+ # An optional list of security group names may be provided to request information for those security
+ # groups only. If no security group names are provided, information of all security groups will be
+ # returned. If a group is specified that does not exist a fault is returned.
+ #
+ #Required Arguments:
+ #
+ # none
+ #
+ #Optional Arguments:
+ #
+ # :group_name => Array (default : [])
+ #
+ def describe_security_groups( options = {} )
+
+ options = { :group_name => [] }.merge(options)
+
+ params = pathlist("GroupName", options[:group_name] )
+
+ return response_generator(:action => "DescribeSecurityGroups", :params => params)
+
+ end
+
+
+ #Amazon Developer Guide Docs:
+ #
+ # The DeleteSecurityGroup operation deletes a security group.
+ #
+ # If an attempt is made to delete a security group and any instances exist that are members of that group a
+ # fault is returned.
+ #
+ #Required Arguments:
+ #
+ # :group_name => String (default : "")
+ #
+ #Optional Arguments:
+ #
+ # none
+ #
+ def delete_security_group( options = {} )
+
+ options = { :group_name => "" }.merge(options)
+
+ raise ArgumentError, "No :group_name provided" if options[:group_name].nil? || options[:group_name].empty?
+
+ params = { "GroupName" => options[:group_name] }
+
+ return response_generator(:action => "DeleteSecurityGroup", :params => params)
+
+ end
+
+
+ #Amazon Developer Guide Docs:
+ #
+ # The AuthorizeSecurityGroupIngress operation adds permissions to a security group.
+ #
+ # Permissions are specified in terms of the IP protocol (TCP, UDP or ICMP), the source of the request (by
+ # IP range or an Amazon EC2 user-group pair), source and destination port ranges (for TCP and UDP),
+ # and ICMP codes and types (for ICMP). When authorizing ICMP, -1 may be used as a wildcard in the
+ # type and code fields.
+ #
+ # Permission changes are propagated to instances within the security group being modified as quickly as
+ # possible. However, a small delay is likely, depending on the number of instances that are members of
+ # the indicated group.
+ #
+ # When authorizing a user/group pair permission, GroupName, SourceSecurityGroupName and
+ # SourceSecurityGroupOwnerId must be specified. When authorizing a CIDR IP permission,
+ # GroupName, IpProtocol, FromPort, ToPort and CidrIp must be specified. Mixing these two types
+ # of parameters is not allowed.
+ #
+ #Required Arguments:
+ #
+ # :group_name => String (default : "")
+ #
+ #Optional Arguments:
+ #
+ # :ip_protocol => String (default : nil) : Required when authorizing CIDR IP permission
+ # :from_port => Integer (default : nil) : Required when authorizing CIDR IP permission
+ # :to_port => Integer (default : nil) : Required when authorizing CIDR IP permission
+ # :cidr_ip => String (default : nil): Required when authorizing CIDR IP permission
+ # :source_security_group_name => String (default : nil) : Required when authorizing user group pair permissions
+ # :source_security_group_owner_id => String (default : nil) : Required when authorizing user group pair permissions
+ #
+ def authorize_security_group_ingress( options = {} )
+
+ # defaults
+ options = { :group_name => nil,
+ :ip_protocol => nil,
+ :from_port => nil,
+ :to_port => nil,
+ :cidr_ip => nil,
+ :source_security_group_name => nil,
+ :source_security_group_owner_id => nil }.merge(options)
+
+ # lets not validate the rest of the possible permutations of required params and instead let
+ # EC2 sort it out on the server side. We'll only require :group_name as that is always needed.
+ raise ArgumentError, "No :group_name provided" if options[:group_name].nil? || options[:group_name].empty?
+
+ params = { "GroupName" => options[:group_name],
+ "IpProtocol" => options[:ip_protocol],
+ "FromPort" => options[:from_port].to_s,
+ "ToPort" => options[:to_port].to_s,
+ "CidrIp" => options[:cidr_ip],
+ "SourceSecurityGroupName" => options[:source_security_group_name],
+ "SourceSecurityGroupOwnerId" => options[:source_security_group_owner_id]
+ }
+
+ return response_generator(:action => "AuthorizeSecurityGroupIngress", :params => params)
+
+ end
+
+
+ #Amazon Developer Guide Docs:
+ #
+ # The RevokeSecurityGroupIngress operation revokes existing permissions that were previously
+ # granted to a security group. The permissions to revoke must be specified using the same values
+ # originally used to grant the permission.
+ #
+ # Permissions are specified in terms of the IP protocol (TCP, UDP or ICMP), the source of the request (by
+ # IP range or an Amazon EC2 user-group pair), source and destination port ranges (for TCP and UDP),
+ # and ICMP codes and types (for ICMP). When authorizing ICMP, -1 may be used as a wildcard in the
+ # type and code fields.
+ #
+ # Permission changes are propagated to instances within the security group being modified as quickly as
+ # possible. However, a small delay is likely, depending on the number of instances that are members of
+ # the indicated group.
+ #
+ # When revoking a user/group pair permission, GroupName, SourceSecurityGroupName and
+ # SourceSecurityGroupOwnerId must be specified. When authorizing a CIDR IP permission,
+ # GroupName, IpProtocol, FromPort, ToPort and CidrIp must be specified. Mixing these two types
+ # of parameters is not allowed.
+ #
+ #Required Arguments:
+ #
+ # :group_name => String (default : "")
+ #
+ #Optional Arguments:
+ #
+ # :ip_protocol => String (default : nil) : Required when revoking CIDR IP permission
+ # :from_port => Integer (default : nil) : Required when revoking CIDR IP permission
+ # :to_port => Integer (default : nil) : Required when revoking CIDR IP permission
+ # :cidr_ip => String (default : nil): Required when revoking CIDR IP permission
+ # :source_security_group_name => String (default : nil) : Required when revoking user group pair permissions
+ # :source_security_group_owner_id => String (default : nil) : Required when revoking user group pair permissions
+ #
+ def revoke_security_group_ingress( options = {} )
+
+ # defaults
+ options = { :group_name => nil,
+ :ip_protocol => nil,
+ :from_port => nil,
+ :to_port => nil,
+ :cidr_ip => nil,
+ :source_security_group_name => nil,
+ :source_security_group_owner_id => nil }.merge(options)
+
+ # lets not validate the rest of the possible permutations of required params and instead let
+ # EC2 sort it out on the server side. We'll only require :group_name as that is always needed.
+ raise ArgumentError, "No :group_name provided" if options[:group_name].nil? || options[:group_name].empty?
+
+ params = { "GroupName" => options[:group_name],
+ "IpProtocol" => options[:ip_protocol],
+ "FromPort" => options[:from_port].to_s,
+ "ToPort" => options[:to_port].to_s,
+ "CidrIp" => options[:cidr_ip],
+ "SourceSecurityGroupName" => options[:source_security_group_name],
+ "SourceSecurityGroupOwnerId" => options[:source_security_group_owner_id]
+ }
+
+ return response_generator(:action => "RevokeSecurityGroupIngress", :params => params)
+
+ end
+
+ end
+
+ end
+end
View
96 lib/AWS/EC2/snapshots.rb
@@ -0,0 +1,96 @@
+#--
+# Amazon Web Services EC2 Query API Ruby library, EBS snaphshots support
+#
+# Ruby Gem Name:: amazon-ec2
+# Author:: Yann Klis (mailto:yann.klis@novelys.com)
+# Copyright:: Copyright (c) 2008 Yann Klis
+# License:: Distributes under the same terms as Ruby
+# Home:: http://github.com/grempe/amazon-ec2/tree/master
+#++
+
+module AWS
+ module EC2
+
+ class Base < AWS::Base
+
+ #Amazon Developer Guide Docs:
+ #
+ # The DescribeSnapshots operation describes the status of Amazon EBS snapshots.
+ #
+ #Required Arguments:
+ #
+ # none
+ #
+ #Optional Arguments:
+ #
+ # :snapshot_id => Array (default : [])
+ #
+
+ def describe_snapshots( options = {} )
+
+ options = { :snapshot_id => [] }.merge(options)
+
+ params = pathlist("SnapshotId", options[:snapshot_id] )
+
+ return response_generator(:action => "DescribeSnapshots", :params => params)
+
+ end
+
+ #Amazon Developer Guide Docs:
+ #
+ # The CreateSnapshot operation creates a snapshot of an Amazon EBS volume and stores it in Amazon S3. You can use snapshots for backups, to launch instances from identical snapshots, and to save data before shutting down an instance.
+ #
+ #Required Arguments:
+ #
+ # :volume_id => String (default : '')
+ #
+ #Optional Arguments:
+ #
+ # none
+ #
+
+ def create_snapshot( options = {} )
+
+ # defaults
+ options = { :volume_id => '' }.merge(options)
+
+ raise ArgumentError, "No :volume_id provided" if options[:volume_id].nil? || options[:volume_id].empty?
+
+ params = {
+ "VolumeId" => options[:volume_id]
+ }
+
+ return response_generator(:action => "CreateSnapshot", :params => params)
+
+ end
+
+ #Amazon Developer Guide Docs:
+ #
+ # The DeleteSnapshot operation deletes a snapshot of an Amazon EBS volume that is stored in Amazon S3.
+ #
+ #Required Arguments:
+ #
+ # :snapshot_id => String (default : '')
+ #
+ #Optional Arguments:
+ #
+ # none
+ #
+
+ def delete_snapshot( options = {} )
+
+ options = { :snapshot_id => '' }.merge(options)
+
+ raise ArgumentError, "No :snapshot_id provided" if options[:snapshot_id].nil? || options[:snapshot_id].empty?
+
+ params = {
+ "SnapshotId" => options[:snapshot_id]
+ }
+
+ return response_generator(:action => "DeleteSnapshot", :params => params)
+
+ end
+
+ end
+ end
+end
View
172 lib/AWS/EC2/volumes.rb
@@ -0,0 +1,172 @@
+#--
+# Amazon Web Services EC2 Query API Ruby library, EBS volumes support
+#
+# Ruby Gem Name:: amazon-ec2
+# Author:: Yann Klis (mailto:yann.klis@novelys.com)
+# Copyright:: Copyright (c) 2008 Yann Klis
+# License:: Distributes under the same terms as Ruby
+# Home:: http://github.com/grempe/amazon-ec2/tree/master
+#++
+
+module AWS
+ module EC2
+
+ class Base < AWS::Base
+
+ #Amazon Developer Guide Docs:
+ #
+ # The DescribeVolumes operation lists one or more Amazon EBS volumes that you own, If you do not specify any volumes, Amazon EBS returns all volumes that you own.
+ #
+ #Required Arguments:
+ #
+ # none
+ #
+ #Optional Arguments:
+ #
+ # :volume_id => Array (default : [])
+ #
+
+ def describe_volumes( options = {} )
+
+ options = { :volume_id => [] }.merge(options)
+
+ params = pathlist("VolumeId", options[:volume_id] )
+
+ return response_generator(:action => "DescribeVolumes", :params => params)
+
+ end
+
+ #Amazon Developer Guide Docs:
+ #
+ # The CreateVolume operation creates a new Amazon EBS volume that you can mount from any Amazon EC2 instance.
+ #
+ #Required Arguments:
+ #
+ # :availability_zone => String (default : '')
+ #
+ #Optional Arguments:
+ #
+ # :size => String (default : '')
+ # :snapshot_id => String (default : '')
+ #
+
+ def create_volume( options = {} )
+
+ # defaults
+ options = { :availability_zone => '' }.merge(options)
+
+ raise ArgumentError, "No :availability_zone provided" if options[:availability_zone].nil? || options[:availability_zone].empty?
+
+ options = { :size => '' }.merge(options)
+ options = { :snapshot_id => '' }.merge(options)
+
+ params = {
+ "AvailabilityZone" => options[:availability_zone],
+ "Size" => options[:size],
+ "SnapshotId" => options[:snapshot_id]
+ }
+
+ return response_generator(:action => "CreateVolume", :params => params)
+
+ end
+
+ #Amazon Developer Guide Docs:
+ #
+ # The DeleteVolume operation deletes an Amazon EBS volume.
+ #
+ #Required Arguments:
+ #
+ # :volume_id => String (default : '')
+ #
+ #Optional Arguments:
+ #
+ # none
+ #
+
+ def delete_volume( options = {} )
+
+ options = { :volume_id => '' }.merge(options)
+
+ raise ArgumentError, "No :volume_id provided" if options[:volume_id].nil? || options[:volume_id].empty?
+
+ params = {
+ "VolumeId" => options[:volume_id]
+ }
+
+ return response_generator(:action => "DeleteVolume", :params => params)
+
+ end
+
+ #Amazon Developer Guide Docs:
+ #
+ # The AttachVolume operation attaches an Amazon EBS volume to an instance.
+ #
+ #Required Arguments:
+ #
+ # :volume_id => String (default : '')
+ # :instance_id => String (default : '')
+ # :device => String (default : '')
+ #
+ #Optional Arguments:
+ #
+ # none
+ #
+
+ def attach_volume( options = {} )
+
+ options = { :volume_id => '' }.merge(options)
+ options = { :instance_id => '' }.merge(options)
+ options = { :device => '' }.merge(options)
+
+ raise ArgumentError, "No :volume_id provided" if options[:volume_id].nil? || options[:volume_id].empty?
+ raise ArgumentError, "No :instance_id provided" if options[:instance_id].nil? || options[:instance_id].empty?
+ raise ArgumentError, "No :device provided" if options[:device].nil? || options[:device].empty?
+
+ params = {
+ "VolumeId" => options[:volume_id],
+ "InstanceId" => options[:instance_id],
+ "Device" => options[:device]
+ }
+
+ return response_generator(:action => "AttachVolume", :params => params)
+
+ end
+
+ #Amazon Developer Guide Docs:
+ #
+ # The DetachVolume operation detaches an Amazon EBS volume from an instance.
+ #
+ #Required Arguments:
+ #
+ # :volume_id => String (default : '')
+ #
+ #Optional Arguments:
+ #
+ # :instance_id => String (default : '')
+ # :device => String (default : '')
+ # :force => Boolean (default : '')
+ #
+
+ def detach_volume( options = {} )
+
+ options = { :volume_id => '' }.merge(options)
+
+ raise ArgumentError, "No :volume_id provided" if options[:volume_id].nil? || options[:volume_id].empty?
+
+ options = { :instance_id => '' }.merge(options)
+ options = { :device => '' }.merge(options)
+ options = { :force => '' }.merge(options)
+
+ params = {
+ "VolumeId" => options[:volume_id],
+ "InstanceId" => options[:instance_id],
+ "Device" => options[:device],
+ "Force" => options[:force]
+ }
+
+ return response_generator(:action => "DetachVolume", :params => params)
+
+ end
+ end
+ end
+end
View
67 lib/AWS/ELB.rb
@@ -0,0 +1,67 @@
+#--
+# Amazon Web Services EC2 Query API Ruby library
+#
+# Ruby Gem Name:: amazon-ec2
+# Author:: Glenn Rempe (mailto:glenn@rempe.us)
+# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
+# License:: Distributes under the same terms as Ruby
+# Home:: http://github.com/grempe/amazon-ec2/tree/master
+#++
+
+# Require any lib files that we have bundled with this Ruby Gem in the lib/EC2 directory.
+# Parts of the EC2 module and Base class are broken out into separate
+# files for maintainability and are organized by the functional groupings defined
+# in the EC2 API developers guide.
+Dir[File.join(File.dirname(__FILE__), 'ELB/**/*.rb')].sort.each { |lib| require lib }
+
+module AWS
+ module ELB
+
+ # Which host FQDN will we connect to for all API calls to AWS?
+ # If ELB_URL is defined in the users ENV we can use that. It is
+ # expected that this var is set with something like:
+ # export ELB_URL='https://ec2.amazonaws.com'
+ #
+ if ENV['ELB_URL']
+ ELB_URL = ENV['ELB_URL']
+ VALID_HOSTS = ['elasticloadbalancing.amazonaws.com']
+ raise ArgumentError, "Invalid ELB_URL environment variable : #{ELB_URL}" unless VALID_HOSTS.include?(ELB_URL)
+ DEFAULT_HOST = URI.parse(ELB_URL).host
+ else
+ # default US host
+ DEFAULT_HOST = 'elasticloadbalancing.amazonaws.com'
+ end
+
+ # This is the version of the API as defined by Amazon Web Services
+ API_VERSION = '2009-05-15'
+
+ #Introduction:
+ #
+ # The library exposes one main interface class, 'AWS::ELB::Base'.
+ # This class provides all the methods for using the ELB service
+ # including the handling of header signing and other security issues .
+ # This class uses Net::HTTP to interface with the ELB Query API interface.
+ #
+ #Required Arguments:
+ #
+ # :access_key_id => String (default : "")
+ # :secret_access_key => String (default : "")
+ #
+ #Optional Arguments:
+ #
+ # :use_ssl => Boolean (default : true)
+ # :server => String (default : 'elasticloadbalancing.amazonaws.com')
+ # :proxy_server => String (default : nil)
+ #
+ class Base < AWS::Base
+ def api_version
+ API_VERSION
+ end
+
+ def default_host
+ DEFAULT_HOST
+ end
+ end
+
+ end
+end
View
87 lib/AWS/ELB/load_balancers.rb
@@ -0,0 +1,87 @@
+module AWS
+ module ELB
+ class Base < AWS::Base
+ # Amazon Developer Guide Docs:
+ #
+ # This API creates a new LoadBalancer. Once the call has completed
+ # successfully, a new LoadBalancer will be created, but it will not be
+ # usable until at least one instance has been registered. When the
+ # LoadBalancer creation is completed, you can check whether it is usable
+ # by using the DescribeInstanceHealth API. The LoadBalancer is usable as
+ # soon as any registered instance is InService.
+ #
+ # Required Arguments:
+ #
+ # :load_balancer_name => String
+ # :availability_zones => Array
+ # :listeners => Array of Hashes (:protocol, :load_balancer_port, :instance_port)
+ # :availability_zones => Array of Strings
+ #
+ def create_load_balancer( options = {} )
+ raise ArgumentError, "No :availability_zones provided" if options[:availability_zones].nil? || options[:availability_zones].empty?
+ raise ArgumentError, "No :listeners provided" if options[:listeners].nil? || options[:listeners].empty?
+ raise ArgumentError, "No :load_balancer_name provided" if options[:load_balancer_name].nil? || options[:load_balancer_name].empty?
+
+ params = {}
+
+ params.merge!(pathlist('AvailabilityZones.member', [options[:availability_zones]].flatten))
+ params.merge!(pathhashlist('Listeners.member', [options[:listeners]].flatten, {
+ :protocol => 'Protocol',
+ :load_balancer_port => 'LoadBalancerPort',
+ :instance_port => 'InstancePort'
+ }))
+ params['LoadBalancerName'] = options[:load_balancer_name]
+
+ return response_generator(:action => "CreateLoadBalancer", :params => params)
+ end
+
+ # Amazon Developer Guide Docs:
+ #
+ # This API deletes the specified LoadBalancer. On deletion, all of the
+ # configured properties of the LoadBalancer will be deleted. If you
+ # attempt to recreate the LoadBalancer, you need to reconfigure all the
+ # settings. The DNS name associated with a deleted LoadBalancer is no
+ # longer be usable. Once deleted, the name and associated DNS record of
+ # the LoadBalancer no longer exist and traffic sent to any of its IP
+ # addresses will no longer be delivered to your instances. You will not
+ # get the same DNS name even if you create a new LoadBalancer with same
+ # LoadBalancerName.
+ #
+ # Required Arguments:
+ #
+ # :load_balancer_name => String
+ #
+ def delete_load_balancer( options = {} )
+ raise ArgumentError, "No :load_balancer_name provided" if options[:load_balancer_name].nil? || options[:load_balancer_name].empty?
+
+ params = { 'LoadBalancerName' => options[:load_balancer_name] }
+
+ return response_generator(:action => "DeleteLoadBalancer", :params => params)
+ end
+
+ # Amazon Developer Guide Docs:
+ #
+ # This API returns detailed configuration information for the specified
+ # LoadBalancers, or if no LoadBalancers are specified, then the API
+ # returns configuration information for all LoadBalancers created by the
+ # caller. For more information, please see LoadBalancer.
+ #
+ # You must have created the specified input LoadBalancers in order to
+ # retrieve this information. In other words, in order to successfully call
+ # this API, you must provide the same account credentials as those that
+ # were used to create the LoadBalancer.
+ #
+ # Optional Arguments:
+ #
+ # :load_balancer_names => String
+ #
+ def describe_load_balancers( options = {} )
+ options = { :load_balancer_names => [] }.merge(options)
+
+ params = pathlist("LoadBalancerName.member", options[:load_balancer_names])
+
+ return response_generator(:action => "DescribeLoadBalancers", :params => params)
+ end
+ end
+ end
+end
View
3 lib/EC2/exceptions.rb → lib/AWS/exceptions.rb
@@ -8,8 +8,7 @@
# Home:: http://github.com/grempe/amazon-ec2/tree/master
#++
-module EC2
-
+module AWS
# OUR CUSTOM ERROR CODES
# All of our errors are superclassed by Error < RuntimeError
View
6 lib/EC2/responses.rb → lib/AWS/responses.rb 100755 → 100644
@@ -19,9 +19,9 @@ def method_missing(meth, *args, &block)
end
end
-module EC2
+module AWS
- # The make_request() and ec2_error? methods, which are shared by all, will raise any
+ # The make_request() and aws_error? methods, which are shared by all, will raise any
# exceptions encountered along the way as it converses with EC2.
#
# Exception Handling: If for some reason an error occurrs when executing a method
@@ -59,4 +59,4 @@ def self.parse(options = {})
end # class Response
-end # module EC2
+end # module AWS
View
41 lib/EC2/availability_zones.rb
@@ -1,41 +0,0 @@
-#--
-# Amazon Web Services EC2 Query API Ruby library
-#
-# Ruby Gem Name:: amazon-ec2
-# Author:: Glenn Rempe (mailto:glenn@rempe.us)
-# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
-# License:: Distributes under the same terms as Ruby
-# Home:: http://github.com/grempe/amazon-ec2/tree/master
-#++
-
-module EC2
-
- class Base
-
- #Amazon Developer Guide Docs:
- #
- # The DescribeAvailabilityZones operation describes availability zones that are currently
- # available to the account and their states.
- #
- # An optional list of zone names can be passed.
- #
- #Required Arguments:
- #
- # none
- #
- #Optional Arguments:
- #
- # :zone_name => Array (default : [])
- #
-
- def describe_availability_zones( options = {} )
-
- options = { :zone_name => [] }.merge(options)
-
- params = pathlist("ZoneName", options[:zone_name] )
-
- return response_generator(:action => "DescribeAvailabilityZones", :params => params)
-
- end
- end
-end
View
44 lib/EC2/console.rb
@@ -1,44 +0,0 @@
-#--
-# Amazon Web Services EC2 Query API Ruby library
-#
-# Ruby Gem Name:: amazon-ec2
-# Author:: Glenn Rempe (mailto:glenn@rempe.us)
-# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
-# License:: Distributes under the same terms as Ruby
-# Home:: http://github.com/grempe/amazon-ec2/tree/master
-#++
-
-module EC2
-
- class Base
-
- #Amazon Developer Guide Docs:
- #
- # The GetConsoleOutput operation retrieves console output that has been posted for the specified instance.
- #
- # Instance console output is buffered and posted shortly after instance boot, reboot and once the instance
- # is terminated. Only the most recent 64 KB of posted output is available. Console output is available for
- # at least 1 hour after the most recent post.
- #
- #Required Arguments:
- #
- # :instance_id => String (default : "")
- #
- #Optional Arguments:
- #
- # none
- #
- def get_console_output( options ={} )
-
- options = {:instance_id => ""}.merge(options)
-
- raise ArgumentError, "No instance ID provided" if options[:instance_id].nil? || options[:instance_id].empty?
-
- params = { "InstanceId" => options[:instance_id] }
-
- return response_generator(:action => "GetConsoleOutput", :params => params)
-
- end
- end
-
-end
View
153 lib/EC2/elastic_ips.rb
@@ -1,153 +0,0 @@
-#--
-# Amazon Web Services EC2 Query API Ruby library
-#
-# Ruby Gem Name:: amazon-ec2
-# Author:: Glenn Rempe (mailto:glenn@rempe.us)
-# Copyright:: Copyright (c) 2007-2008 Glenn Rempe
-# License:: Distributes under the same terms as Ruby
-# Home:: http://github.com/grempe/amazon-ec2/tree/master
-#++