Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Experimental support for EC2 tags provided by tomdz.

  • Loading branch information...
commit 098e5287dc33f548dd1fbe141db74694cb4ff89b 2 parents da53f4b + 1b7f6c2
@grempe authored
Showing with 95 additions and 2 deletions.
  1. +6 −0 ChangeLog
  2. +41 −1 lib/AWS.rb
  3. +1 −1  lib/AWS/EC2.rb
  4. +47 −0 lib/AWS/EC2/tags.rb
View
6 ChangeLog
@@ -2,6 +2,12 @@
=== 0.9.17 2010-11-21
* Converted from Jeweler to Bundler, 'bundle install' to install dependencies
+ * Adding ability to launch t1.micro instances for ec2 regular and spot price
+ instances
+ * Adding support for describe/modify/reset instance attributes with tests.
+ * Updated to API version : 2010-08-31
+ * Added experimental support for EC2 create_tags, describe_tags, delete_tags
+
=== 0.9.16 2010-07-07
* Less strict checking on which server endpoints you can pass in as an environment var.
View
42 lib/AWS.rb
@@ -219,7 +219,46 @@ 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.to_s
+ if value.is_a? Array
+ params["#{key}.#{i+1}.Name"] = mappings[attribute]
+ value.each_with_index do |item, j|
+ params["#{key}.#{i+1}.Value.#{j+1}"] = item.to_s
+ end
+ else
+ params["#{key}.#{i+1}.#{mappings[attribute]}"] = value.to_s
+ end
+ end
+ end
+ params
+ end
+
+ # Same as _pathhashlist_ except it generates explicit <prefix>.Key= and <prefix>.Value or <prefix>.Value.1, <prefix>.Value.2
+ # depending on whether the value is a scalar or an array.
+ #
+ # So if you pass in args
+ # ("People", [{:name=>'jon'}, {:names=>['chris', 'bob']} with key_name = 'Key' and value_name = 'Value',
+ # you should get
+ # {"People.1.Key"=>"name", "People.1.Value"=>'jon', "People.2.Key"=>'names', 'People.2.Value.1'=>'chris', 'People.2.Value.2'=>'bob'}
+ def pathkvlist(key, arr_of_hashes, key_name, value_name, mappings)
+ raise ArgumentError, "expected a key that is a String" unless key.is_a? String
+ raise ArgumentError, "expected a arr_of_hashes that is an Array" unless arr_of_hashes.is_a? Array
+ arr_of_hashes.each{|h| raise ArgumentError, "expected each element of arr_of_hashes to be a Hash" unless h.is_a?(Hash)}
+ raise ArgumentError, "expected a key_nam that is a String" unless key_name.is_a? String
+ raise ArgumentError, "expected a value_name that is a String" unless value_name.is_a? String
+ raise ArgumentError, "expected a mappings that is an Hash" unless mappings.is_a? Hash
+ params = {}
+ arr_of_hashes.each_with_index do |hash, i|
+ hash.each do |attribute, value|
+ params["#{key}.#{i+1}.#{key_name}"] = mappings.fetch(attribute, attribute)
+ if !value.nil?
+ if value.is_a? Array
+ value.each_with_index do |item, j|
+ params["#{key}.#{i+1}.#{value_name}.#{j+1}"] = item.to_s
+ end
+ else
+ params["#{key}.#{i+1}.#{value_name}"] = value.to_s
+ end
+ end
end
end
params
@@ -282,6 +321,7 @@ def response_generator( options = {} )
http_response = make_request(options[:action], options[:params])
http_xml = http_response.body
+
return Response.parse(:xml => http_xml)
end
View
2  lib/AWS/EC2.rb
@@ -14,7 +14,7 @@ module EC2
DEFAULT_HOST = 'ec2.amazonaws.com'
end
- API_VERSION = '2009-11-30'
+ API_VERSION = '2010-08-31'
class Base < AWS::Base
def api_version
View
47 lib/AWS/EC2/tags.rb
@@ -0,0 +1,47 @@
+module AWS
+ module EC2
+ class Base < AWS::Base
+
+ # The CreateTags operation adds or overwrites tags for the specified resource(s).
+ #
+ # @option options [Array] :resource_id ([]) The ids of the resource(s) to tag
+ # @option options [Array] :tag ([]) An array of Hashes representing the tags { tag_name => tag_value }. Use nil or empty string to get a tag without a value
+ #
+ def create_tags( options = {} )
+ raise ArgumentError, "No :resource_id provided" if options[:resource_id].nil? || options[:resource_id].empty?
+ raise ArgumentError, "No :tag provided" if options[:tag].nil? || options[:tag].empty?
+
+ params = pathlist("ResourceId", options[:resource_id] )
+ params.merge!(pathkvlist('Tag', options[:tag], 'Key', 'Value', {}))
+ return response_generator(:action => "CreateTags", :params => params)
+ end
+
+ # The DescribeTags operation lists the tags, If you do not specify any filters, all tags will be returned.
+ #
+ # @option options [optional, Array] :filter ([]) An array of Hashes representing the filters. Note that the values in the hashes have to be arrays. E.g. [{:key => ['name']}, {:resource_type => ['instance']},...]
+ #
+ def describe_tags( options = {} )
+ params = {}
+ if options[:filter]
+ params.merge!(pathkvlist('Filter', options[:filter], 'Name', 'Value', {:resource_id => 'resource-id', :resource_type => 'resource-type' }))
+ end
+ return response_generator(:action => "DescribeTags", :params => params)
+ end
+
+ # The DeleteTags operation deletes tags for the specified resource(s).
+ #
+ # @option options [Array] :resource_id ([]) The ids of the resource(s) to tag
+ # @option options [Array] :tag ([]) An array of Hashes representing the tags { tag_name => tag_value }. If a value is given (instead of nil/empty string), then the tag is only deleted if it has this value
+ #
+ def delete_tags( options = {} )
+ raise ArgumentError, "No :resource_id provided" if options[:resource_id].nil? || options[:resource_id].empty?
+ raise ArgumentError, "No :tag provided" if options[:tag].nil? || options[:tag].empty?
+
+ params = pathlist("ResourceId", options[:resource_id] )
+ params.merge!(pathkvlist('Tag', options[:tag], 'Key', 'Value', {}))
+ return response_generator(:action => "DeleteTags", :params => params)
+ end
+ end
+ end
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.