From fc146770f60f87f8417148cb306e6ac0cf087d5f Mon Sep 17 00:00:00 2001 From: Rupak Ganguly Date: Wed, 11 Jul 2012 19:21:35 -0400 Subject: [PATCH] Add attach and detach methods to the volume model using the compute service attribute. --- lib/fog/hp/models/block_storage/volume.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/fog/hp/models/block_storage/volume.rb b/lib/fog/hp/models/block_storage/volume.rb index 81446b0ef..43c7b354c 100644 --- a/lib/fog/hp/models/block_storage/volume.rb +++ b/lib/fog/hp/models/block_storage/volume.rb @@ -43,9 +43,28 @@ module Fog self.status == 'available' end + # volume can be attached to only one server at a time + def attach(new_server_id, device) + requires :id + unless in_use? + data = connection.compute.attach_volume(new_server_id, id, device) + merge_attributes(:attachments => attachments << data.body['volumeAttachment']) + true + else + false + end + end + + def detach + requires :id + if has_attachments? + connection.compute.detach_volume(server_id, id) + end + true + end + def destroy requires :id - connection.delete_volume(id) true end