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:50 UTC

svn commit: r962041 - in /incubator/deltacloud/trunk/client-ruby: lib/deltacloud.rb specs/flavors_spec.rb specs/instances_spec.rb

Author: lutter
Date: Thu Jul  8 23:18:50 2010
New Revision: 962041

URL: http://svn.apache.org/viewvc?rev=962041&view=rev
Log:
Add more functionality and tests for flavors.

Modified:
    incubator/deltacloud/trunk/client-ruby/lib/deltacloud.rb
    incubator/deltacloud/trunk/client-ruby/specs/flavors_spec.rb
    incubator/deltacloud/trunk/client-ruby/specs/instances_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=962041&r1=962040&r2=962041&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client-ruby/lib/deltacloud.rb (original)
+++ incubator/deltacloud/trunk/client-ruby/lib/deltacloud.rb Thu Jul  8 23:18:50 2010
@@ -30,7 +30,7 @@ class DeltaCloud
 
   def flavors(opts={})
     flavors = []
-    request( entry_points[:flavors] ) do |response|
+    request( entry_points[:flavors], :get, opts ) do |response|
       if ( response.is_a?( Net::HTTPSuccess ) )
         doc = REXML::Document.new( response.body )
         doc.get_elements( 'flavors/flavor' ).each do |flavor|
@@ -42,6 +42,23 @@ class DeltaCloud
     flavors 
   end
 
+  def flavor(id)
+    request( entry_points[:flavors], :get, {:id=>id } ) do |response|
+      if ( response.is_a?( Net::HTTPSuccess ) )
+        doc = REXML::Document.new( response.body )
+        doc.get_elements( 'flavors/flavor' ).each do |flavor|
+          uri = flavor.attributes['href']
+          return Flavor.new( self, uri, flavor )
+        end
+      end
+    end
+    nil
+  end
+
+  def fetch_flavor(uri)
+    return Flavor.new( self, uri, fetch_resource( :flavor, uri ) )
+  end
+
   def images(opts={})
     images = []
     request_path = entry_points[:images]

Modified: incubator/deltacloud/trunk/client-ruby/specs/flavors_spec.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client-ruby/specs/flavors_spec.rb?rev=962041&r1=962040&r2=962041&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client-ruby/specs/flavors_spec.rb (original)
+++ incubator/deltacloud/trunk/client-ruby/specs/flavors_spec.rb Thu Jul  8 23:18:50 2010
@@ -6,7 +6,7 @@ describe "flavors" do
   it_should_behave_like "all resources"
 
   it "should allow retrieval of all flavors" do
-    DeltaCloud.new( "name", "password", API_URL ) do |client|
+    DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
       flavors = client.flavors
       flavors.should_not be_empty
       flavors.each do |flavor|
@@ -21,4 +21,30 @@ describe "flavors" do
       end
     end
   end 
+
+  it "should allow filtering of flavors by architecture" do
+    DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
+      flavors = client.flavors( :architecture=>'i386' )
+      flavors.should_not be_empty
+      flavors.size.should eql( 1 )
+      flavors.first.architecture.should eql( 'i386' )
+    end
+  end
+
+  it "should allow fetching a flavor by id" do
+    DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
+      flavor = client.flavor( 'm1-small' )
+      flavor.should_not be_nil
+      flavor.resource_id.should eql( 'm1-small' )
+    end
+  end
+
+  it "should allow fetching a flavor by URI" do
+    DeltaCloud.new( API_NAME, API_PASSWORD, API_URL ) do |client|
+      flavor = client.fetch_flavor( API_URL + '/flavors/m1-small' )
+      flavor.should_not be_nil
+      flavor.resource_id.should eql( 'm1-small' )
+    end
+  end
+
 end

Modified: incubator/deltacloud/trunk/client-ruby/specs/instances_spec.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client-ruby/specs/instances_spec.rb?rev=962041&r1=962040&r2=962041&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client-ruby/specs/instances_spec.rb (original)
+++ incubator/deltacloud/trunk/client-ruby/specs/instances_spec.rb Thu Jul  8 23:18:50 2010
@@ -56,7 +56,6 @@ describe "instances" do
       instance.state.should eql( "RUNNING" )
       instance.actions.should_not be_nil
     end
-  
   end
 
   it "should allow creation of new instances" do