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:20:17 UTC
svn commit: r962062 - in /incubator/deltacloud/trunk/client-ruby:
lib/deltacloud.rb specs/storage_volume_spec.rb
Author: lutter
Date: Thu Jul 8 23:20:17 2010
New Revision: 962062
URL: http://svn.apache.org/viewvc?rev=962062&view=rev
Log:
Better non-success response.
Modified:
incubator/deltacloud/trunk/client-ruby/lib/deltacloud.rb
incubator/deltacloud/trunk/client-ruby/specs/storage_volume_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=962062&r1=962061&r2=962062&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client-ruby/lib/deltacloud.rb (original)
+++ incubator/deltacloud/trunk/client-ruby/lib/deltacloud.rb Thu Jul 8 23:20:17 2010
@@ -57,7 +57,9 @@ class DeltaCloud
end
def fetch_flavor(uri)
- return Flavor.new( self, uri, fetch_resource( :flavor, uri ) )
+ xml = fetch_resource( :flavor, uri )
+ return Flavor.new( self, uri, xml ) if xml
+ nil
end
def images(opts={})
@@ -89,7 +91,9 @@ class DeltaCloud
end
def fetch_image(uri)
- return Image.new( self, uri, fetch_resource( :image, uri ) )
+ xml = fetch_resource( :image, uri )
+ return Image.new( self, uri, xml ) if xml
+ nil
end
def instances()
@@ -120,7 +124,9 @@ class DeltaCloud
end
def fetch_instance(uri)
- return Instance.new( self, uri, fetch_resource( :instance, uri ) )
+ xml = fetch_resource( :instance, uri )
+ return Instance.new( self, uri, xml ) if xml
+ nil
end
def create_instance(image_id, flavor_id)
@@ -162,7 +168,9 @@ class DeltaCloud
end
def fetch_storage_volume(uri)
- return StorageVolume.new( self, uri, fetch_resource( :storage_volume, uri ) )
+ xml = fetch_resource( :storage_volume, uri )
+ return StorageVolume.new( self, uri, xml ) if xml
+ nil
end
##
@@ -172,9 +180,11 @@ class DeltaCloud
def fetch_resource(type, uri)
request( uri ) do |response|
- doc = REXML::Document.new( response.body )
- if ( doc.root.name == type.to_s.gsub( /_/, '-' ) )
- return doc.root
+ if ( response.is_a?( Net::HTTPSuccess ) )
+ doc = REXML::Document.new( response.body )
+ if ( doc.root && ( doc.root.name == type.to_s.gsub( /_/, '-' ) ) )
+ return doc.root
+ end
end
end
nil
Modified: incubator/deltacloud/trunk/client-ruby/specs/storage_volume_spec.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client-ruby/specs/storage_volume_spec.rb?rev=962062&r1=962061&r2=962062&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client-ruby/specs/storage_volume_spec.rb (original)
+++ incubator/deltacloud/trunk/client-ruby/specs/storage_volume_spec.rb Thu Jul 8 23:20:17 2010
@@ -49,5 +49,21 @@ describe "storage volumes" do
end
end
+ it "should return nil for unknown storage volume by ID" do
+ client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
+ client.connect do |client|
+ storage_volume = client.storage_volume( 'bogus' )
+ storage_volume.should be_nil
+ end
+ end
+
+ it "should return nil for unknown storage volume by URI" do
+ client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
+ client.connect do |client|
+ storage_volume = client.fetch_storage_volume( API_URL + '/storage/volumes/bogus' )
+ storage_volume.should be_nil
+ end
+ end
+
end