forked from fog/fog-openstack
-
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.
Merge pull request fog#518 from NormandLemay/master
Adding volume v3 supported
- Loading branch information
Showing
62 changed files
with
808 additions
and
12 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,94 @@ | ||
require 'fog/openstack/core' | ||
require 'fog/openstack/volume' | ||
|
||
module Fog | ||
module OpenStack | ||
class Volume | ||
class V3 < Fog::OpenStack::Volume | ||
SUPPORTED_VERSIONS = /v3(\.(0-9))*/ | ||
|
||
requires :openstack_auth_url | ||
|
||
recognizes *@@recognizes | ||
|
||
model_path 'fog/openstack/volume/v3/models' | ||
|
||
model :volume | ||
collection :volumes | ||
|
||
model :availability_zone | ||
collection :availability_zones | ||
|
||
model :volume_type | ||
collection :volume_types | ||
|
||
model :snapshot | ||
collection :snapshots | ||
|
||
model :transfer | ||
collection :transfers | ||
|
||
model :backup | ||
collection :backups | ||
|
||
request_path 'fog/openstack/volume/v3/requests' | ||
|
||
# Volume | ||
request :list_volumes | ||
request :list_volumes_detailed | ||
request :create_volume | ||
request :update_volume | ||
request :get_volume_details | ||
request :extend_volume | ||
request :delete_volume | ||
|
||
request :list_zones | ||
|
||
request :list_volume_types | ||
request :create_volume_type | ||
request :update_volume_type | ||
request :delete_volume_type | ||
request :get_volume_type_details | ||
|
||
request :create_snapshot | ||
request :update_snapshot | ||
request :list_snapshots | ||
request :list_snapshots_detailed | ||
request :get_snapshot_details | ||
request :delete_snapshot | ||
request :update_snapshot_metadata | ||
request :delete_snapshot_metadata | ||
|
||
request :list_transfers | ||
request :list_transfers_detailed | ||
request :create_transfer | ||
request :get_transfer_details | ||
request :accept_transfer | ||
request :delete_transfer | ||
|
||
request :list_backups | ||
request :list_backups_detailed | ||
request :create_backup | ||
request :get_backup_details | ||
request :restore_backup | ||
request :delete_backup | ||
|
||
request :update_quota | ||
request :get_quota | ||
request :get_quota_defaults | ||
request :get_quota_usage | ||
|
||
request :update_metadata | ||
request :replace_metadata | ||
request :delete_metadata | ||
|
||
request :set_tenant | ||
request :action | ||
request :snapshot_action | ||
|
||
autoload :Mock, 'fog/openstack/volume/v3/mock' | ||
autoload :Real, 'fog/openstack/volume/v3/real' | ||
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,68 @@ | ||
module Fog | ||
module OpenStack | ||
class Volume | ||
class V3 < Fog::OpenStack::Volume | ||
class Mock | ||
def self.data | ||
@data ||= Hash.new do |hash, key| | ||
hash[key] = { | ||
:users => {}, | ||
:tenants => {}, | ||
:quota => { | ||
'gigabytes' => 1000, | ||
'volumes' => 10, | ||
'snapshots' => 10 | ||
} | ||
} | ||
end | ||
end | ||
|
||
def self.reset | ||
@data = nil | ||
end | ||
|
||
def initialize(options = {}) | ||
@openstack_username = options[:openstack_username] | ||
@openstack_tenant = options[:openstack_tenant] | ||
@openstack_auth_uri = URI.parse(options[:openstack_auth_url]) | ||
|
||
@auth_token = Fog::Mock.random_base64(64) | ||
@auth_token_expiration = (Time.now.utc + 86400).iso8601 | ||
|
||
management_url = URI.parse(options[:openstack_auth_url]) | ||
management_url.port = 8776 | ||
management_url.path = '/v1' | ||
@openstack_management_url = management_url.to_s | ||
|
||
@data ||= {:users => {}} | ||
unless @data[:users].find { |u| u['name'] == options[:openstack_username] } | ||
id = Fog::Mock.random_numbers(6).to_s | ||
@data[:users][id] = { | ||
'id' => id, | ||
'name' => options[:openstack_username], | ||
'email' => "#{options[:openstack_username]}@mock.com", | ||
'tenantId' => Fog::Mock.random_numbers(6).to_s, | ||
'enabled' => true | ||
} | ||
end | ||
end | ||
|
||
def data | ||
self.class.data[@openstack_username] | ||
end | ||
|
||
def reset_data | ||
self.class.data.delete(@openstack_username) | ||
end | ||
|
||
def credentials | ||
{:provider => 'openstack', | ||
:openstack_auth_url => @openstack_auth_uri.to_s, | ||
:openstack_auth_token => @auth_token, | ||
:openstack_management_url => @openstack_management_url} | ||
end | ||
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 @@ | ||
require 'fog/openstack/volume/models/availability_zone' | ||
|
||
module Fog | ||
module OpenStack | ||
class Volume | ||
class V3 | ||
class AvailabilityZone < Fog::OpenStack::Volume::AvailabilityZone | ||
identity :zoneName | ||
|
||
attribute :zoneState | ||
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,16 @@ | ||
require 'fog/openstack/models/collection' | ||
require 'fog/openstack/volume/v3/models/availability_zone' | ||
require 'fog/openstack/volume/models/availability_zones' | ||
|
||
module Fog | ||
module OpenStack | ||
class Volume | ||
class V3 | ||
class AvailabilityZones < Fog::OpenStack::Collection | ||
model Fog::OpenStack::Volume::V3::AvailabilityZone | ||
include Fog::OpenStack::Volume::AvailabilityZones | ||
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 @@ | ||
require 'fog/openstack/volume/models/backup' | ||
|
||
module Fog | ||
module OpenStack | ||
class Volume | ||
class V3 | ||
class Backup < Fog::OpenStack::Volume::Backup | ||
identity :id | ||
|
||
superclass.attributes.each { |attrib| attribute attrib } | ||
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,16 @@ | ||
require 'fog/openstack/models/collection' | ||
require 'fog/openstack/volume/v3/models/backup' | ||
require 'fog/openstack/volume/models/backups' | ||
|
||
module Fog | ||
module OpenStack | ||
class Volume | ||
class V3 | ||
class Backups < Fog::OpenStack::Collection | ||
model Fog::OpenStack::Volume::V3::Backup | ||
include Fog::OpenStack::Volume::Backups | ||
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,44 @@ | ||
require 'fog/openstack/volume/models/snapshot' | ||
|
||
module Fog | ||
module OpenStack | ||
class Volume | ||
class V3 | ||
class Snapshot < Fog::OpenStack::Volume::Snapshot | ||
identity :id | ||
|
||
attribute :name | ||
attribute :status | ||
attribute :description | ||
attribute :metadata | ||
attribute :force | ||
attribute :size | ||
|
||
def save | ||
requires :name | ||
data = if id.nil? | ||
service.create_snapshot(attributes[:volume_id], name, description, force) | ||
else | ||
service.update_snapshot(id, attributes.reject { |k, _v| k == :id }) | ||
end | ||
merge_attributes(data.body['snapshot']) | ||
true | ||
end | ||
|
||
def create | ||
requires :name | ||
|
||
# volume_id, name, description, force=false | ||
response = service.create_snapshot(attributes[:volume_id], | ||
attributes[:name], | ||
attributes[:description], | ||
attributes[:force]) | ||
merge_attributes(response.body['snapshot']) | ||
|
||
self | ||
end | ||
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,16 @@ | ||
require 'fog/openstack/models/collection' | ||
require 'fog/openstack/volume/v3/models/snapshot' | ||
require 'fog/openstack/volume/models/snapshots' | ||
|
||
module Fog | ||
module OpenStack | ||
class Volume | ||
class V3 | ||
class Snapshots < Fog::OpenStack::Collection | ||
model Fog::OpenStack::Volume::V3::Snapshot | ||
include Fog::OpenStack::Volume::Snapshots | ||
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,18 @@ | ||
require 'fog/openstack/volume/models/transfer' | ||
|
||
module Fog | ||
module OpenStack | ||
class Volume | ||
class V3 | ||
class Transfer < Fog::OpenStack::Volume::Transfer | ||
identity :id | ||
|
||
attribute :auth_key, :aliases => 'authKey' | ||
attribute :created_at, :aliases => 'createdAt' | ||
attribute :name | ||
attribute :volume_id, :aliases => 'volumeId' | ||
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,16 @@ | ||
require 'fog/openstack/models/collection' | ||
require 'fog/openstack/volume/v3/models/transfer' | ||
require 'fog/openstack/volume/models/transfers' | ||
|
||
module Fog | ||
module OpenStack | ||
class Volume | ||
class V3 | ||
class Transfers < Fog::OpenStack::Collection | ||
model Fog::OpenStack::Volume::V3::Transfer | ||
include Fog::OpenStack::Volume::Transfers | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.