deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@redhat.com
Subject [PATCH 2/6] Adds attach/detach volume to deltacloud mock driver
Date Fri, 23 Dec 2011 16:31:20 GMT
From: marios <marios@redhat.com>


Signed-off-by: marios <marios@redhat.com>
---
 server/lib/deltacloud/drivers/mock/mock_driver.rb |   37 +++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index 5d07eed..bee75a0 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -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
-- 
1.7.6.4


Mime
View raw message