You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by lu...@apache.org on 2010/07/09 01:18:19 UTC
svn commit: r962034 - in /incubator/deltacloud/trunk/client-ruby:
lib/deltacloud.rb specs/images_spec.rb
Author: lutter
Date: Thu Jul 8 23:18:19 2010
New Revision: 962034
URL: http://svn.apache.org/viewvc?rev=962034&view=rev
Log:
Adding more image filtering specs.
Modified:
incubator/deltacloud/trunk/client-ruby/lib/deltacloud.rb
incubator/deltacloud/trunk/client-ruby/specs/images_spec.rb
Modified: incubator/deltacloud/trunk/client-ruby/lib/deltacloud.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client-ruby/lib/deltacloud.rb?rev=962034&r1=962033&r2=962034&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client-ruby/lib/deltacloud.rb (original)
+++ incubator/deltacloud/trunk/client-ruby/lib/deltacloud.rb Thu Jul 8 23:18:19 2010
@@ -45,10 +45,7 @@ class DeltaCloud
def images(opts={})
images = []
request_path = entry_points[:images]
- if ( opts[:owner] )
- request_path += "?owner_id=#{opts[:owner]}"
- end
- request( request_path ) do |response|
+ request( request_path, :get, opts ) do |response|
if ( response.is_a?( Net::HTTPSuccess ) )
doc = REXML::Document.new( response.body )
doc.get_elements( 'images/image' ).each do |image|
@@ -75,7 +72,7 @@ class DeltaCloud
end
def instance(id)
- request( entry_points[:instances], :get, {'id'=>id} ) do |response|
+ request( entry_points[:instances], :get, {:id=>id } ) do |response|
if ( response.is_a?( Net::HTTPSuccess ) )
doc = REXML::Document.new( response.body )
doc.get_elements( 'instances/instance' ).each do |instance|
@@ -92,7 +89,7 @@ class DeltaCloud
end
def create_instance(image_id, flavor_id)
- request( entry_points[:instances], :post, { 'image_id'=>image_id, 'flavor_id'=>flavor_id} ) do |response|
+ request( entry_points[:instances], :post, {}, { 'image_id'=>image_id, 'flavor_id'=>flavor_id} ) do |response|
if ( response.is_a?( Net::HTTPSuccess ) )
doc = REXML::Document.new( response.body )
instance = doc.root
@@ -150,12 +147,17 @@ class DeltaCloud
end
end
- def request(path='', method=:get, form_data={}, &block)
+ def request(path='', method=:get, query_args={}, form_data={}, &block)
if ( path =~ /^http/ )
request_path = path
else
request_path = "#{api_path}#{path}"
end
+ query_string = query_args.keys.collect{|key| "#{key}=#{query_args[key]}"}.join("&")
+ if ( query_string != '' )
+ request_path += "?#{query_string}"
+ end
+
logger << "Request [#{method.to_s.upcase} #{request_path}]\n"
request = eval( "Net::HTTP::#{method.to_s.capitalize}" ).new( request_path )
request.basic_auth( @name, @password )
Modified: incubator/deltacloud/trunk/client-ruby/specs/images_spec.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client-ruby/specs/images_spec.rb?rev=962034&r1=962033&r2=962034&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client-ruby/specs/images_spec.rb (original)
+++ incubator/deltacloud/trunk/client-ruby/specs/images_spec.rb Thu Jul 8 23:18:19 2010
@@ -25,7 +25,7 @@ describe "images" do
it "should allow retrieval of my own images" do
DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
- images = client.images( :owner=>:self )
+ images = client.images( :owner_id=>:self )
images.should_not be_empty
images.size.should eql( 1 )
images.each do |image|
@@ -40,4 +40,28 @@ describe "images" do
end
end
end
+
+ describe "filtering by architecture" do
+ it "return matching images" do
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
+ images = client.images( :architecture=>'x86_64' )
+ images.should_not be_empty
+ images.each do |image|
+ image.architecture.should eql( 'x86_64' )
+ end
+ images = client.images( :architecture=>'i386' )
+ images.should_not be_empty
+ images.each do |image|
+ image.architecture.should eql( 'i386' )
+ end
+ end
+ end
+
+ it "should return an empty array for no matches" do
+ DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
+ images = client.images( :architecture=>'8088' )
+ images.should be_empty
+ end
+ end
+ end
end