deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject svn commit: r1226715 - /deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb
Date Tue, 03 Jan 2012 09:39:05 GMT
Author: marios
Date: Tue Jan  3 09:39:04 2012
New Revision: 1226715

URL: http://svn.apache.org/viewvc?rev=1226715&view=rev
Log:
Adds attach/detach volume to deltacloud mock driver

Modified:
    deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb

Modified: deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb?rev=1226715&r1=1226714&r2=1226715&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb (original)
+++ deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb Tue Jan  3 09:39:04
2012
@@ -264,6 +264,17 @@ module Deltacloud::Drivers::Mock
       @client.destroy(:storage_volumes, opts[:id])
     end
 
+    #opts: {:id=,:instance_id,:device}
+    def attach_storage_volume(credentials, opts)
+      check_credentials(credentials)
+      attach_volume_instance(opts[:id], opts[:device], opts[:instance_id])
+    end
+
+    def detach_storage_volume(credentials, opts)
+      check_credentials(credentials)
+      detach_volume_instance(opts[:id], opts[:instance_id])
+    end
+
     #
     # Storage Snapshots
     #
@@ -440,6 +451,32 @@ module Deltacloud::Drivers::Mock
       end
     end
 
+    def attach_volume_instance(volume_id, device, instance_id)
+      volume = @client.load(:storage_volumes, volume_id)
+      instance = @client.load(:instances, instance_id)
+      volume[:instance_id] = instance_id
+      volume[:device] = device
+      volume[:state] = "IN-USE"
+      instance[:storage_volumes] ||= []
+      instance[:storage_volumes] << {volume_id=>device}
+      @client.store(:storage_volumes, volume)
+      @client.store(:instances, instance)
+      StorageVolume.new(volume)
+    end
+
+    def detach_volume_instance(volume_id, instance_id)
+      volume = @client.load(:storage_volumes, volume_id)
+      instance = @client.load(:instances, instance_id)
+      volume[:instance_id] = nil
+      device = volume[:device]
+      volume[:device] = nil
+      volume[:state] = "AVAILABLE"
+      instance[:storage_volumes].delete({volume_id => device}) unless instance[:storage_volumes].nil?
+      @client.store(:storage_volumes, volume)
+      @client.store(:instances, instance)
+      StorageVolume.new(volume)
+    end
+
     exceptions do
 
       on /AuthFailure/ do



Mime
View raw message