incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject svn commit: r962058 - in /incubator/deltacloud/trunk/client-ruby: lib/deltacloud.rb lib/models/base_model.rb lib/models/instance.rb lib/models/storage_volume.rb specs/fixtures/storage_volumes/vol3.yml specs/spec_helper.rb specs/storage_volume_spec.rb
Date Thu, 08 Jul 2010 23:20:02 GMT
Author: lutter
Date: Thu Jul  8 23:20:02 2010
New Revision: 962058

URL: http://svn.apache.org/viewvc?rev=962058&view=rev
Log:
Client interface for storage-volumes.

Added:
    incubator/deltacloud/trunk/client-ruby/lib/models/storage_volume.rb
    incubator/deltacloud/trunk/client-ruby/specs/storage_volume_spec.rb
Modified:
    incubator/deltacloud/trunk/client-ruby/lib/deltacloud.rb
    incubator/deltacloud/trunk/client-ruby/lib/models/base_model.rb
    incubator/deltacloud/trunk/client-ruby/lib/models/instance.rb
    incubator/deltacloud/trunk/client-ruby/specs/fixtures/storage_volumes/vol3.yml
    incubator/deltacloud/trunk/client-ruby/specs/spec_helper.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=962058&r1=962057&r2=962058&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client-ruby/lib/deltacloud.rb (original)
+++ incubator/deltacloud/trunk/client-ruby/lib/deltacloud.rb Thu Jul  8 23:20:02 2010
@@ -6,6 +6,7 @@ require 'rexml/document'
 require 'models/flavor'
 require 'models/image'
 require 'models/instance'
+require 'models/storage_volume'
 
 class DeltaCloud
 
@@ -133,6 +134,38 @@ class DeltaCloud
     end  
   end
 
+  def storage_volumes()
+    storage_volumes = []
+    request( entry_points[:storage_volumes] ) do |response|
+      if ( response.is_a?( Net::HTTPSuccess ) )
+        doc = REXML::Document.new( response.body )
+        doc.get_elements( 'storage-volumes/storage-volume' ).each do |instance|
+          uri = instance.attributes['href']
+          storage_volumes << StorageVolume.new( self, uri, instance )
+        end
+      end
+    end
+    storage_volumes
+  end
+
+  def storage_volume(id)
+    request( entry_points[:storage_volumes], :get, {:id=>id } ) do |response|
+      if ( response.is_a?( Net::HTTPSuccess ) )
+        doc = REXML::Document.new( response.body )
+        doc.get_elements( 'storage-volumes/storage-volume' ).each do |storage_volume|
+          uri = storage_volume.attributes['href']
+          return StorageVolume.new( self, uri, storage_volume )
+        end
+      end
+    end
+    nil
+  end
+
+  ##
+  ##
+  ##
+  ##
+
   def fetch_resource(type, uri)
     request( uri ) do |response|
       doc = REXML::Document.new( response.body )

Modified: incubator/deltacloud/trunk/client-ruby/lib/models/base_model.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client-ruby/lib/models/base_model.rb?rev=962058&r1=962057&r2=962058&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client-ruby/lib/models/base_model.rb (original)
+++ incubator/deltacloud/trunk/client-ruby/lib/models/base_model.rb Thu Jul  8 23:20:02 2010
@@ -24,6 +24,7 @@ class BaseModel
   end
 
   def id()
+    check_load_payload
     @id
   end
 

Modified: incubator/deltacloud/trunk/client-ruby/lib/models/instance.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client-ruby/lib/models/instance.rb?rev=962058&r1=962057&r2=962058&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client-ruby/lib/models/instance.rb (original)
+++ incubator/deltacloud/trunk/client-ruby/lib/models/instance.rb Thu Jul  8 23:20:02 2010
@@ -17,23 +17,25 @@ class Instance < BaseModel
 
   def load_payload(xml=nil)
     super(xml)
-    @owner_id = xml.text('owner_id')
-    @public_addresses = []
-    xml.get_elements( 'public-addresses/address' ).each do |address|
-      @public_addresses << address.text
-    end
-    @private_addresses = []
-    xml.get_elements( 'private-addresses/address' ).each do |address|
-      @private_addresses << address.text
-    end
-    image_uri = xml.get_elements( 'image' )[0].attributes['href']
-    @image = Image.new( @client, image_uri )
-    flavor_uri = xml.get_elements( 'flavor' )[0].attributes['href']
-    @flavor = Flavor.new( @client, flavor_uri )
-    @state = xml.text( 'state' )
-    @actions = []
-    xml.get_elements( 'actions/link' ).each do |link|
-      @actions << link.attributes['rel']
+    unless xml.nil?
+      @owner_id = xml.text('owner_id')
+      @public_addresses = []
+      xml.get_elements( 'public-addresses/address' ).each do |address|
+        @public_addresses << address.text
+      end
+      @private_addresses = []
+      xml.get_elements( 'private-addresses/address' ).each do |address|
+        @private_addresses << address.text
+      end
+      image_uri = xml.get_elements( 'image' )[0].attributes['href']
+      @image = Image.new( @client, image_uri )
+      flavor_uri = xml.get_elements( 'flavor' )[0].attributes['href']
+      @flavor = Flavor.new( @client, flavor_uri )
+      @state = xml.text( 'state' )
+      @actions = []
+      xml.get_elements( 'actions/link' ).each do |link|
+        @actions << link.attributes['rel']
+      end
     end
   end
 end

Added: incubator/deltacloud/trunk/client-ruby/lib/models/storage_volume.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client-ruby/lib/models/storage_volume.rb?rev=962058&view=auto
==============================================================================
--- incubator/deltacloud/trunk/client-ruby/lib/models/storage_volume.rb (added)
+++ incubator/deltacloud/trunk/client-ruby/lib/models/storage_volume.rb Thu Jul  8 23:20:02
2010
@@ -0,0 +1,32 @@
+require 'models/base_model'
+
+class StorageVolume < BaseModel
+
+  attribute :created
+  attribute :state
+  attribute :capacity
+  attribute :device
+  attribute :instance
+
+  def initialize(client, uri, xml=nil)
+    super( client, uri, xml )
+  end
+
+  def load_payload(xml=nil)
+    super(xml)
+    unless xml.nil?
+      @created = xml.text( 'created' )
+      @state = xml.text( 'state' )
+      @capacity = xml.text( 'capacity' ).to_f
+      @device = xml.text( 'device' )
+      instances = xml.get_elements( 'instance' )
+      if ( ! instances.empty? )
+        instance = instances.first
+        instance_href = instance.attributes['href']
+        if ( instance_href ) 
+          @instance = Instance.new( @client, instance_href )
+        end
+      end
+    end
+  end
+end

Modified: incubator/deltacloud/trunk/client-ruby/specs/fixtures/storage_volumes/vol3.yml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client-ruby/specs/fixtures/storage_volumes/vol3.yml?rev=962058&r1=962057&r2=962058&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client-ruby/specs/fixtures/storage_volumes/vol3.yml (original)
+++ incubator/deltacloud/trunk/client-ruby/specs/fixtures/storage_volumes/vol3.yml Thu Jul
 8 23:20:02 2010
@@ -2,5 +2,5 @@
 :created: Thu Jul 30 14:35:11 UTC 2009
 :state: IN-USE
 :capacity: 1
-:device: /dev/sda
+:device: /dev/sda1
 :instance_id: inst1

Modified: incubator/deltacloud/trunk/client-ruby/specs/spec_helper.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client-ruby/specs/spec_helper.rb?rev=962058&r1=962057&r2=962058&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client-ruby/specs/spec_helper.rb (original)
+++ incubator/deltacloud/trunk/client-ruby/specs/spec_helper.rb Thu Jul  8 23:20:02 2010
@@ -20,7 +20,6 @@ def clean_fixtures
 end
 
 def reload_fixtures
-  puts "reloading fixtures"
   clean_fixtures
   FileUtils.cp_r( File.dirname( __FILE__) + '/fixtures', File.dirname( __FILE__ ) + '/data'
)
 end

Added: 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=962058&view=auto
==============================================================================
--- incubator/deltacloud/trunk/client-ruby/specs/storage_volume_spec.rb (added)
+++ incubator/deltacloud/trunk/client-ruby/specs/storage_volume_spec.rb Thu Jul  8 23:20:02
2010
@@ -0,0 +1,38 @@
+
+require 'specs/spec_helper'
+
+describe "storage volumes" do
+
+  it_should_behave_like "all resources"
+
+  it "allow retrieval of all storage volumes owned by the current user" do
+    client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
+    client.connect do |client|
+      storage_volumes = client.storage_volumes
+      storage_volumes.should_not be_nil
+      storage_volumes.should_not be_empty
+      ids = storage_volumes.collect{|e| e.id}
+      ids.size.should eql( 2 )
+      ids.should include( 'vol2' )
+      ids.should include( 'vol3' )
+    end
+  end
+
+  it "should allow fetching of storage volume by id" do
+    client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
+    client.connect do |client|
+      storage_volume = client.storage_volume( 'vol3' )
+      storage_volume.id.should eql( 'vol3' )
+      storage_volume.uri.should eql( API_URL + '/storage/volumes/vol3' )
+      storage_volume.state.should eql( 'IN-USE' )
+      storage_volume.capacity.should eql( 1.0 )
+      storage_volume.device.should eql( '/dev/sda1' )
+      storage_volume.instance.should_not be_nil
+      storage_volume.instance.id.should eql( 'inst1' )
+      storage_volume.instance.flavor.architecture.should eql( 'i386' )
+    end
+  
+  end
+
+
+end



Mime
View raw message