-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from fog/add_block_storage
Add block storage
- Loading branch information
Showing
17 changed files
with
710 additions
and
18 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,15 @@ | ||
module Fog | ||
module Compute | ||
class DigitalOcean | ||
class Volume < Fog::Model | ||
identity :id | ||
attribute :name | ||
attribute :region | ||
attribute :droplet_ids | ||
attribute :description | ||
attribute :size_gigabytes | ||
attribute :created_at | ||
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,42 @@ | ||
require 'fog/digitalocean/models/paging_collection' | ||
|
||
module Fog | ||
module Compute | ||
class DigitalOcean | ||
class Volumes < Fog::Compute::DigitalOcean::PagingCollection | ||
model Fog::Compute::DigitalOcean::Volume | ||
|
||
# Retrieves volumes | ||
# @return [Fog::Compute::DigitalOcean::Volume] | ||
# @raise [Fog::Compute::DigitalOcean::NotFound] - HTTP 404 | ||
# @raise [Fog::Compute::DigitalOcean::BadRequest] - HTTP 400 | ||
# @raise [Fog::Compute::DigitalOcean::InternalServerError] - HTTP 500 | ||
# @raise [Fog::Compute::DigitalOcean::ServiceError] | ||
# @see https://developers.digitalocean.com/documentation/v2/#list-all-images | ||
def all(filters = {}) | ||
data = service.list_volumes(filters) | ||
links = data.body["links"] | ||
get_paged_links(links) | ||
volumes = data.body["volumes"] | ||
load(volumes) | ||
end | ||
|
||
# Retrieves volume | ||
# @param [String] id for volume to be returned | ||
# @return [Fog::Compute::DigitalOcean:Image] | ||
# @raise [Fog::Compute::DigitalOcean::NotFound] - HTTP 404 | ||
# @raise [Fog::Compute::DigitalOcean::BadRequest] - HTTP 400 | ||
# @raise [Fog::Compute::DigitalOcean::InternalServerError] - HTTP 500 | ||
# @raise [Fog::Compute::DigitalOcean::ServiceError] | ||
# @see https://developers.digitalocean.com/documentation/v2/#retrieve-an-existing-image-by-id | ||
def get(id) | ||
volume = service.get_volume_details(id).body['volume'] | ||
new(volume) if volume | ||
rescue Fog::Errors::NotFound | ||
nil | ||
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,122 @@ | ||
module Fog | ||
module Compute | ||
class DigitalOcean | ||
class Real | ||
def attach_volume(volume_id, droplet_id, region) | ||
body = { :type => 'attach', droplet_id: droplet_id, region: region} | ||
|
||
encoded_body = Fog::JSON.encode(body) | ||
|
||
request( | ||
:expects => [201], | ||
:headers => { | ||
'Content-Type' => "application/json; charset=UTF-8", | ||
}, | ||
:method => 'POST', | ||
:path => "v2/volumes/#{volume_id}/actions", | ||
:body => encoded_body, | ||
) | ||
end | ||
|
||
def attach_volume_by_name(volume_name, droplet_id, region) | ||
body = { :type => 'attach', volume_name: volume_name, droplet_id: droplet_id, region: region} | ||
|
||
encoded_body = Fog::JSON.encode(body) | ||
|
||
request( | ||
:expects => [201], | ||
:headers => { | ||
'Content-Type' => "application/json; charset=UTF-8", | ||
}, | ||
:method => 'POST', | ||
:path => "v2/volumes/actions", | ||
:body => encoded_body, | ||
) | ||
end | ||
end | ||
|
||
class Mock | ||
def attach_volume(volume_id, droplet_id, region) | ||
response = Excon::Response.new | ||
response.status = 201 | ||
response.body = { | ||
"action" => { | ||
"id" => 72531856, | ||
"status" => "completed", | ||
"type" => "attach_volume", | ||
"started_at" => "2015-11-12T17:51:03Z", | ||
"completed_at" => "2015-11-12T17:51:14Z", | ||
"resource_id" => "null", | ||
"resource_type" => "volume", | ||
"region" => { | ||
"name" => "New York 1", | ||
"slug" => "nyc1", | ||
"sizes" => [ | ||
"1gb", | ||
"2gb", | ||
"4gb", | ||
"8gb", | ||
"32gb", | ||
"64gb", | ||
"512mb", | ||
"48gb", | ||
"16gb" | ||
], | ||
"features" => [ | ||
"private_networking", | ||
"backups", | ||
"ipv6", | ||
"metadata" | ||
], | ||
"available" => true | ||
}, | ||
"region_slug" => "nyc1" | ||
} | ||
} | ||
|
||
response | ||
end | ||
def attach_volume_by_name(volume_name, droplet_id, region) | ||
response = Excon::Response.new | ||
response.status = 201 | ||
response.body = { | ||
"action" => { | ||
"id" => 72531856, | ||
"status" => "completed", | ||
"type" => "attach_volume", | ||
"started_at" => "2015-11-12T17:51:03Z", | ||
"completed_at" => "2015-11-12T17:51:14Z", | ||
"resource_id" => "null", | ||
"resource_type" => "volume", | ||
"region" => { | ||
"name" => "New York 1", | ||
"slug" => "nyc1", | ||
"sizes" => [ | ||
"1gb", | ||
"2gb", | ||
"4gb", | ||
"8gb", | ||
"32gb", | ||
"64gb", | ||
"512mb", | ||
"48gb", | ||
"16gb" | ||
], | ||
"features" => [ | ||
"private_networking", | ||
"backups", | ||
"ipv6", | ||
"metadata" | ||
], | ||
"available" => true | ||
}, | ||
"region_slug" => "nyc1" | ||
} | ||
} | ||
|
||
response | ||
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
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,50 @@ | ||
module Fog | ||
module Compute | ||
class DigitalOcean | ||
# noinspection RubyStringKeysInHashInspection | ||
class Real | ||
|
||
def create_volume(options={}) | ||
create_options = { | ||
:name => "name", | ||
:region => "nyc1", | ||
:size_gigabytes => 1 | ||
}.merge(options) | ||
|
||
encoded_body = Fog::JSON.encode(create_options) | ||
|
||
request( | ||
:expects => [201], | ||
:headers => { | ||
'Content-Type' => "application/json; charset=UTF-8", | ||
}, | ||
:method => 'POST', | ||
:path => '/v2/volumes', | ||
:body => encoded_body, | ||
) | ||
end | ||
end | ||
|
||
# noinspection RubyStringKeysInHashInspection | ||
class Mock | ||
def create_volume(options) | ||
response = Excon::Response.new | ||
response.status = 201 | ||
|
||
response.body ={ | ||
'volume' => { | ||
"id" => Fog::Mock.random_numbers(6).to_i, | ||
"fingerprint" => (["00"] * 16).join(':'), | ||
"region" => options[:region], | ||
"size_gigabytes" => 10, | ||
"description" => options[:description], | ||
"name" => options[:name] | ||
} | ||
} | ||
|
||
response | ||
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,32 @@ | ||
module Fog | ||
module Compute | ||
class DigitalOcean | ||
# noinspection RubyStringKeysInHashInspection | ||
class Real | ||
def destroy_volume(id) | ||
request( | ||
:expects => [204], | ||
:headers => { | ||
'Content-Type' => "application/json; charset=UTF-8", | ||
}, | ||
:method => 'DELETE', | ||
:path => "/v2/volumes/#{id}", | ||
) | ||
end | ||
end | ||
|
||
# noinspection RubyStringKeysInHashInspection | ||
class Mock | ||
def destroy_volume(id) | ||
self.data[:volumes].select! do |key| | ||
key["id"] != id | ||
end | ||
|
||
response = Excon::Response.new | ||
response.status = 204 | ||
response | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.