incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject svn commit: r962064 - in /incubator/deltacloud/trunk/client-ruby: lib/ lib/models/ specs/ specs/fixtures/storage_snapshots/
Date Thu, 08 Jul 2010 23:20:28 GMT
Author: lutter
Date: Thu Jul  8 23:20:28 2010
New Revision: 962064

URL: http://svn.apache.org/viewvc?rev=962064&view=rev
Log:
Wire up storage-snapshots to client.

Added:
    incubator/deltacloud/trunk/client-ruby/lib/models/storage_snapshot.rb
    incubator/deltacloud/trunk/client-ruby/specs/fixtures/storage_snapshots/snap1.yml
    incubator/deltacloud/trunk/client-ruby/specs/fixtures/storage_snapshots/snap2.yml
    incubator/deltacloud/trunk/client-ruby/specs/fixtures/storage_snapshots/snap3.yml
    incubator/deltacloud/trunk/client-ruby/specs/storage_snapshot_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/flavor.rb
    incubator/deltacloud/trunk/client-ruby/lib/models/image.rb
    incubator/deltacloud/trunk/client-ruby/lib/models/instance.rb
    incubator/deltacloud/trunk/client-ruby/lib/models/storage_volume.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=962064&r1=962063&r2=962064&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client-ruby/lib/deltacloud.rb (original)
+++ incubator/deltacloud/trunk/client-ruby/lib/deltacloud.rb Thu Jul  8 23:20:28 2010
@@ -7,6 +7,7 @@ require 'models/flavor'
 require 'models/image'
 require 'models/instance'
 require 'models/storage_volume'
+require 'models/storage_snapshot'
 
 class DeltaCloud
 
@@ -173,6 +174,39 @@ class DeltaCloud
     nil
   end
 
+  def storage_snapshots()
+    storage_snapshots = []
+    request( entry_points[:storage_snapshots] ) do |response|
+      if ( response.is_a?( Net::HTTPSuccess ) )
+        doc = REXML::Document.new( response.body )
+        doc.get_elements( 'storage-snapshots/storage-snapshot' ).each do |instance|
+          uri = instance.attributes['href']
+          storage_snapshots << StorageSnapshot.new( self, uri, instance )
+        end
+      end
+    end
+    storage_snapshots
+  end
+
+  def storage_snapshot(id)
+    request( entry_points[:storage_snapshots], :get, {:id=>id } ) do |response|
+      if ( response.is_a?( Net::HTTPSuccess ) )
+        doc = REXML::Document.new( response.body )
+        doc.get_elements( 'storage-snapshots/storage-snapshot' ).each do |storage_snapshot|
+          uri = storage_snapshot.attributes['href']
+          return StorageSnapshot.new( self, uri, storage_snapshot )
+        end
+      end
+    end
+    nil
+  end
+
+  def fetch_storage_snapshot(uri)
+    xml = fetch_resource( :storage_snapshot, uri ) 
+    return StorageSnapshot.new( self, uri, xml ) if xml
+    nil
+  end
+
   ##
   ##
   ##

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=962064&r1=962063&r2=962064&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:28 2010
@@ -1,6 +1,14 @@
 
 class BaseModel
 
+  def self.xml_tag_name(name=nil)
+    unless ( name.nil? ) 
+      @xml_tag_name = name
+    end
+    @xml_tag_name || self.class.name.downcase.to_sym
+  end
+
+
   def self.attribute(attr)
     build_reader attr
   end
@@ -30,7 +38,7 @@ class BaseModel
 
   def check_load_payload()
     return if @loaded
-    xml = @client.fetch_resource( self.class.name.downcase.to_sym, @uri )
+    xml = @client.fetch_resource( self.class.xml_tag_name.to_sym, @uri )
     load_payload(xml)
   end
 

Modified: incubator/deltacloud/trunk/client-ruby/lib/models/flavor.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client-ruby/lib/models/flavor.rb?rev=962064&r1=962063&r2=962064&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client-ruby/lib/models/flavor.rb (original)
+++ incubator/deltacloud/trunk/client-ruby/lib/models/flavor.rb Thu Jul  8 23:20:28 2010
@@ -3,6 +3,8 @@ require 'models/base_model'
 
 class Flavor < BaseModel
 
+  xml_tag_name :flavor
+
   attribute :memory
   attribute :storage
   attribute :architecture

Modified: incubator/deltacloud/trunk/client-ruby/lib/models/image.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client-ruby/lib/models/image.rb?rev=962064&r1=962063&r2=962064&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client-ruby/lib/models/image.rb (original)
+++ incubator/deltacloud/trunk/client-ruby/lib/models/image.rb Thu Jul  8 23:20:28 2010
@@ -3,6 +3,8 @@ require 'models/base_model'
 
 class Image < BaseModel
 
+  xml_tag_name :image
+
   attribute :description
   attribute :owner_id
   attribute :architecture

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=962064&r1=962063&r2=962064&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:28 2010
@@ -3,6 +3,8 @@ require 'models/base_model'
 
 class Instance < BaseModel
 
+  xml_tag_name :instance
+
   attribute :owner_id
   attribute :public_addresses
   attribute :private_addresses

Added: incubator/deltacloud/trunk/client-ruby/lib/models/storage_snapshot.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client-ruby/lib/models/storage_snapshot.rb?rev=962064&view=auto
==============================================================================
--- incubator/deltacloud/trunk/client-ruby/lib/models/storage_snapshot.rb (added)
+++ incubator/deltacloud/trunk/client-ruby/lib/models/storage_snapshot.rb Thu Jul  8 23:20:28
2010
@@ -0,0 +1,31 @@
+
+require 'models/base_model'
+
+class StorageSnapshot < BaseModel
+
+  xml_tag_name :storage_snapshot
+
+  attribute :created
+  attribute :state
+  attribute :storage_volume
+
+  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' )
+      storage_volumes = xml.get_elements( 'storage-volume' )
+      if ( ! storage_volumes.empty? )
+        storage_volume = storage_volumes.first
+        storage_volume_href = storage_volume.attributes['href']
+        if ( storage_volume_href ) 
+          @storage_volume = StorageVolume.new( @client, storage_volume_href )
+        end
+      end
+    end
+  end
+end

Modified: 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=962064&r1=962063&r2=962064&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client-ruby/lib/models/storage_volume.rb (original)
+++ incubator/deltacloud/trunk/client-ruby/lib/models/storage_volume.rb Thu Jul  8 23:20:28
2010
@@ -2,6 +2,8 @@ require 'models/base_model'
 
 class StorageVolume < BaseModel
 
+  xml_tag_name :storage_volume
+
   attribute :created
   attribute :state
   attribute :capacity

Added: incubator/deltacloud/trunk/client-ruby/specs/fixtures/storage_snapshots/snap1.yml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client-ruby/specs/fixtures/storage_snapshots/snap1.yml?rev=962064&view=auto
==============================================================================
--- incubator/deltacloud/trunk/client-ruby/specs/fixtures/storage_snapshots/snap1.yml (added)
+++ incubator/deltacloud/trunk/client-ruby/specs/fixtures/storage_snapshots/snap1.yml Thu
Jul  8 23:20:28 2010
@@ -0,0 +1,4 @@
+:owner_id: fedoraproject
+:created: Wed Jul 29 18:15:24 UTC 2009
+:state: COMPLETED
+:storage_volume_id: vol1

Added: incubator/deltacloud/trunk/client-ruby/specs/fixtures/storage_snapshots/snap2.yml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client-ruby/specs/fixtures/storage_snapshots/snap2.yml?rev=962064&view=auto
==============================================================================
--- incubator/deltacloud/trunk/client-ruby/specs/fixtures/storage_snapshots/snap2.yml (added)
+++ incubator/deltacloud/trunk/client-ruby/specs/fixtures/storage_snapshots/snap2.yml Thu
Jul  8 23:20:28 2010
@@ -0,0 +1,4 @@
+:owner_id: mockuser
+:created: Wed Jul 29 18:15:24 UTC 2009
+:state: COMPLETED
+:storage_volume_id: vol2

Added: incubator/deltacloud/trunk/client-ruby/specs/fixtures/storage_snapshots/snap3.yml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client-ruby/specs/fixtures/storage_snapshots/snap3.yml?rev=962064&view=auto
==============================================================================
--- incubator/deltacloud/trunk/client-ruby/specs/fixtures/storage_snapshots/snap3.yml (added)
+++ incubator/deltacloud/trunk/client-ruby/specs/fixtures/storage_snapshots/snap3.yml Thu
Jul  8 23:20:28 2010
@@ -0,0 +1,4 @@
+:owner_id: mockuser
+:created: Wed Jul 29 18:15:24 UTC 2009
+:state: COMPLETED
+:storage_volume_id: vol2

Added: incubator/deltacloud/trunk/client-ruby/specs/storage_snapshot_spec.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client-ruby/specs/storage_snapshot_spec.rb?rev=962064&view=auto
==============================================================================
--- incubator/deltacloud/trunk/client-ruby/specs/storage_snapshot_spec.rb (added)
+++ incubator/deltacloud/trunk/client-ruby/specs/storage_snapshot_spec.rb Thu Jul  8 23:20:28
2010
@@ -0,0 +1,59 @@
+
+require 'specs/spec_helper'
+
+describe "storage snapshot" 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_snapshots = client.storage_snapshots
+      storage_snapshots.should_not be_nil
+      storage_snapshots.should_not be_empty
+      ids = storage_snapshots.collect{|e| e.id}
+      ids.size.should eql( 2 )
+      ids.should include( 'snap2' )
+      ids.should include( 'snap3' )
+    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_snapshot = client.storage_snapshot( 'snap2' )
+      storage_snapshot.should_not be_nil
+      storage_snapshot.id.should eql( 'snap2' )
+      storage_snapshot.storage_volume.capacity.should eql( 1.0 )
+      storage_snapshot.storage_volume.id.should eql( 'vol2' )
+    end
+  end
+
+  it "should allow fetching of storage volume by URI"  do
+    client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
+    client.connect do |client|
+      storage_snapshot = client.fetch_storage_snapshot( API_URL + '/storage/snapshots/snap2'
)
+      storage_snapshot.should_not be_nil
+      storage_snapshot.id.should eql( 'snap2' )
+      storage_snapshot.storage_volume.capacity.should eql( 1.0 )
+      storage_snapshot.storage_volume.id.should eql( 'vol2' )
+    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_snapshot = client.storage_snapshot( "bogus" )
+      storage_snapshot.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_snapshot = client.fetch_storage_snapshot( API_URL + '/storage/snapshots/bogus'
)
+      storage_snapshot.should be_nil
+    end
+  end
+
+end



Mime
View raw message