From 2cf81fa9018c5669a306815cdab0551c6dfc120e Mon Sep 17 00:00:00 2001 From: rkyrychuk Date: Fri, 10 Feb 2012 16:36:14 +0200 Subject: [PATCH 1/2] Added filter to describe instances --- lib/AWS/EC2/instances.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/AWS/EC2/instances.rb b/lib/AWS/EC2/instances.rb index 71f7653..e2bc4b8 100644 --- a/lib/AWS/EC2/instances.rb +++ b/lib/AWS/EC2/instances.rb @@ -82,14 +82,20 @@ def run_instances( options = {} ) # 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. # + # An optional filter can be provided to to request information for instances that corresponds this filter only + # # 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 # # @option options [Array] :instance_id ([]) + # @option options [Hash] :filter ({}) # def describe_instances( options = {} ) - options = { :instance_id => [] }.merge(options) - params = pathlist("InstanceId", options[:instance_id]) + options = { :instance_id => [], :filter => {} }.merge(options) + params = {} + params.merge!(pathlist("InstanceId", options[:instance_id])) + params.merge!(pathhashlist("Filter", options[:filter].map{|k,v| {:name => k, :value => v}}, {:name => 'Name', :value => 'Value'})) + return response_generator(:action => "DescribeInstances", :params => params) end @@ -296,4 +302,3 @@ def self.local_instance_meta_data end end - From aa4f8a2062891fa86dd350636f117eb62b1954a0 Mon Sep 17 00:00:00 2001 From: rkyrychuk Date: Fri, 10 Feb 2012 16:44:04 +0200 Subject: [PATCH 2/2] Ruby style keys in filter --- lib/AWS/EC2/instances.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/AWS/EC2/instances.rb b/lib/AWS/EC2/instances.rb index e2bc4b8..caa2960 100644 --- a/lib/AWS/EC2/instances.rb +++ b/lib/AWS/EC2/instances.rb @@ -94,7 +94,7 @@ def describe_instances( options = {} ) options = { :instance_id => [], :filter => {} }.merge(options) params = {} params.merge!(pathlist("InstanceId", options[:instance_id])) - params.merge!(pathhashlist("Filter", options[:filter].map{|k,v| {:name => k, :value => v}}, {:name => 'Name', :value => 'Value'})) + params.merge!(pathhashlist("Filter", options[:filter].map{|k,v| {:name => k.is_a?(Symbol) ? k.to_s.gsub("_", "-") : k, :value => v}}, {:name => 'Name', :value => 'Value'})) return response_generator(:action => "DescribeInstances", :params => params) end