1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[openstack|volume] Volume attach/detach to Server

This commit is contained in:
Marjun Pagalan 2012-03-01 20:24:36 +08:00 committed by Nelvin Driz
parent 1bd045767e
commit c29cc00b00
4 changed files with 64 additions and 0 deletions

View file

@ -124,6 +124,8 @@ module Fog
request :create_volume
request :get_volume_details
request :delete_volume
request :attach_volume
request :detach_volume
request :create_volume_snapshot
request :list_snapshots

View file

@ -37,6 +37,19 @@ module Fog
connection.delete_volume(id)
true
end
def attach(server_id, name)
requires :id
data = connection.attach_volume(id, server_id, name)
merge_attributes(:attachments => attachments << data.body['volumeAttachment'])
true
end
def detach(server_id, attachment_id)
requires :id
connection.detach_volume(server_id, attachment_id)
true
end
end
end

View file

@ -0,0 +1,28 @@
module Fog
module Compute
class OpenStack
class Real
def attach_volume(volume_id, server_id, device)
data = {
'volumeAttachment' => {
'volumeId' => volume_id.to_s,
'device' => device
}
}
request(
:body => MultiJson.encode(data),
:expects => [200, 202],
:method => 'POST',
:path => "servers/%s/os-volume_attachments" % [server_id]
)
end
end
class Mock
end
end
end
end

View file

@ -0,0 +1,21 @@
module Fog
module Compute
class OpenStack
class Real
def detach_volume(server_id, attachment_id)
request(
:expects => 202,
:method => 'DELETE',
:path => "servers/%s/os-volume_attachments/%s" % [server_id, attachment_id]
)
end
end
class Mock
end
end
end
end