deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [5/5] git commit: OS: Methods should return empty array on unknown entity
Date Thu, 30 Aug 2012 09:51:44 GMT
OS: Methods should return empty array on unknown entity

* Methods like instance, images, etc. should return an empty
  array instead of throwing 404 exception.


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/41a2f7bf
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/41a2f7bf
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/41a2f7bf

Branch: refs/heads/master
Commit: 41a2f7bfe972a86d4e6d15b8605488a912ec4ce6
Parents: 33a556a
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Mon Aug 27 12:29:25 2012 +0200
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Thu Aug 30 11:52:07 2012 +0200

----------------------------------------------------------------------
 .../drivers/openstack/openstack_driver.rb          |   40 ++++++++++-----
 1 files changed, 27 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/41a2f7bf/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/openstack/openstack_driver.rb b/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
index 2f67a08..5b29840 100644
--- a/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
+++ b/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
@@ -45,8 +45,13 @@ module Deltacloud
           results = []
           safely do
             if opts[:id]
-              flavor = os.flavor(opts[:id])
-              results << convert_from_flavor(flavor)
+              begin
+                flavor = os.flavor(opts[:id])
+                results << convert_from_flavor(flavor)
+              rescue => e
+                raise e unless e.message =~ /The resource could not be found/
+                results = []
+              end
             else
               results = os.flavors.collect do |f|
                 convert_from_flavor(f)
@@ -62,17 +67,20 @@ module Deltacloud
           profiles = hardware_profiles(credentials)
           safely do
             if(opts[:id])
-              img = os.get_image(opts[:id])
-              results << convert_from_image(img, os.connection.authuser)
+              begin
+                img = os.get_image(opts[:id])
+                results << convert_from_image(img, os.connection.authuser)
+              rescue => e
+                raise e unless e.message =~ /Image not found/
+                results = []
+              end
             else
-              results = os.list_images.collect do |img|
-                convert_from_image(img, os.connection.authuser)
+              results = os.list_images.collect do |i|
+                convert_from_image(i, os.connection.authuser)
               end
             end
           end
-          results.each do |img|
-            img.hardware_profiles = profiles
-          end
+          results.each { |img| img.hardware_profiles = profiles }
           filter_on(results, :owner_id, opts)
         end
 
@@ -108,6 +116,7 @@ module Deltacloud
                 end
               end
           end
+          return [] if opts[:id] and opts[:id] != 'default'
           [ Realm.new( { :id=>'default',
                         :name=>'default',
                         :limit => limits,
@@ -119,11 +128,16 @@ module Deltacloud
           insts = []
           safely do
             if opts[:id]
-              server = os.get_server(opts[:id])
-              insts << convert_from_server(server, os.connection.authuser)
+              begin
+                server = os.get_server(opts[:id])
+                insts << convert_from_server(server, os.connection.authuser)
+              rescue => e
+                raise e unless e.message =~ /The resource could not be found/
+                insts = []
+              end
             else
-              insts = os.list_servers_detail.collect do |server|
-                convert_from_server(server, os.connection.authuser)
+              insts = os.list_servers_detail.collect do |s|
+                convert_from_server(s, os.connection.authuser)
               end
             end
           end


Mime
View raw message