-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[rackspace|compute] Add attachments model and collection.
Provide a method for attaching, listing, and detaching block storage volumes on Rackspace next-generation cloud servers.
- Loading branch information
Julio Feijo
authored and
Brad Gignac
committed
Sep 13, 2012
1 parent
4a5fc11
commit 8920e7b
Showing
7 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'fog/core/model' | ||
|
||
module Fog | ||
module Compute | ||
class RackspaceV2 | ||
class Attachment < Fog::Model | ||
identity :id | ||
|
||
attribute :server_id, :aliases => 'serverId' | ||
attribute :volume_id, :aliases => 'volumeId' | ||
attribute :device | ||
|
||
def save | ||
requires :server, :identity, :device | ||
data = connection.attach_volume(server.identity, identity, device) | ||
merge_attributes(data.body['volumeAttachment']) | ||
true | ||
end | ||
|
||
def destroy | ||
requires :server, :identity | ||
connection.delete_attachment(server.identity, identity) | ||
true | ||
end | ||
|
||
private | ||
|
||
def server | ||
collection.server | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'fog/core/collection' | ||
require 'fog/rackspace/models/compute_v2/attachment' | ||
|
||
module Fog | ||
module Compute | ||
class RackspaceV2 | ||
class Attachments < Fog::Collection | ||
|
||
model Fog::Compute::RackspaceV2::Attachment | ||
|
||
attr_accessor :server | ||
|
||
def all | ||
data = connection.list_attachments(server.id).body['volumeAttachments'] | ||
load(data) | ||
end | ||
|
||
def get(volume_id) | ||
data = connection.get_attachment(server.id, volume_id).body['volumeAttachment'] | ||
data && new(data) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Fog | ||
module Compute | ||
class RackspaceV2 | ||
class Real | ||
def attach_volume(server_id, volume_id, device) | ||
data = { | ||
'volumeAttachment' => { | ||
'volumeId' => volume_id, | ||
'device' => device | ||
} | ||
} | ||
|
||
request( | ||
:body => Fog::JSON.encode(data), | ||
:expects => [200], | ||
:method => 'POST', | ||
:path => "servers/#{server_id}/os-volume_attachments" | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
lib/fog/rackspace/requests/compute_v2/delete_attachment.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Fog | ||
module Compute | ||
class RackspaceV2 | ||
class Real | ||
def delete_attachment(server_id, volume_id) | ||
request( | ||
:expects => [202], | ||
:method => 'DELETE', | ||
:path => "servers/#{server_id}/os-volume_attachments/#{volume_id}" | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Fog | ||
module Compute | ||
class RackspaceV2 | ||
class Real | ||
def get_attachment(server_id, volume_id) | ||
request( | ||
:expects => [200, 203, 300], | ||
:method => 'GET', | ||
:path => "servers/#{server_id}/os-volume_attachments/#{volume_id}" | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Fog | ||
module Compute | ||
class RackspaceV2 | ||
class Real | ||
def list_attachments(server_id) | ||
request( | ||
:expects => [200, 203, 300], | ||
:method => 'GET', | ||
:path => "servers/#{server_id}/os-volume_attachments" | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |