Skip to content

Commit

Permalink
Merge pull request fog#518 from NormandLemay/master
Browse files Browse the repository at this point in the history
Adding volume v3 supported
  • Loading branch information
ares authored Feb 4, 2022
2 parents e5bf96d + 4d5685d commit 5526d4d
Show file tree
Hide file tree
Showing 62 changed files with 808 additions and 12 deletions.
21 changes: 11 additions & 10 deletions lib/fog/openstack/volume.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@


module Fog
module OpenStack
class Volume < Fog::Service
autoload :V1, 'fog/openstack/volume/v1'
autoload :V2, 'fog/openstack/volume/v2'
autoload :V3, 'fog/openstack/volume/v3'

@@recognizes = [:openstack_auth_token, :openstack_management_url,
:persistent, :openstack_service_type, :openstack_service_name,
Expand All @@ -17,16 +16,18 @@ class Volume < Fog::Service
:openstack_project_domain_id, :openstack_user_domain_id, :openstack_domain_id,
:openstack_identity_api_version]

# Fog::OpenStack::Image.new() will return a Fog::OpenStack::Volume::V2 or a Fog::OpenStack::Volume::V1,
# choosing the V2 by default, as V1 is deprecated since OpenStack Juno
# Fog::OpenStack::Image.new() will return a Fog::OpenStack::Volume::V3 or a Fog::OpenStack::Volume::V2 or a
# Fog::OpenStack::Volume::V1, choosing the V3 by default, as V2 is deprecated since OpenStackWallaby and V1 is
# deprecated since OpenStack Juno
def self.new(args = {})
@openstack_auth_uri = URI.parse(args[:openstack_auth_url]) if args[:openstack_auth_url]
service = if inspect == 'Fog::OpenStack::Volume'
Fog::OpenStack::Volume::V2.new(args) || Fog::OpenStack::Volume::V1.new(args)
else
super
end
service
if inspect == 'Fog::OpenStack::Volume'
Fog::OpenStack::Volume::V3.new(args) \
|| Fog::OpenStack::Volume::V2.new(args) \
|| Fog::OpenStack::Volume::V1.new(args)
else
super
end
end
end
end
Expand Down
94 changes: 94 additions & 0 deletions lib/fog/openstack/volume/v3.rb
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
68 changes: 68 additions & 0 deletions lib/fog/openstack/volume/v3/mock.rb
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
15 changes: 15 additions & 0 deletions lib/fog/openstack/volume/v3/models/availability_zone.rb
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
16 changes: 16 additions & 0 deletions lib/fog/openstack/volume/v3/models/availability_zones.rb
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
15 changes: 15 additions & 0 deletions lib/fog/openstack/volume/v3/models/backup.rb
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
16 changes: 16 additions & 0 deletions lib/fog/openstack/volume/v3/models/backups.rb
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
44 changes: 44 additions & 0 deletions lib/fog/openstack/volume/v3/models/snapshot.rb
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
16 changes: 16 additions & 0 deletions lib/fog/openstack/volume/v3/models/snapshots.rb
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
18 changes: 18 additions & 0 deletions lib/fog/openstack/volume/v3/models/transfer.rb
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
16 changes: 16 additions & 0 deletions lib/fog/openstack/volume/v3/models/transfers.rb
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
Loading

0 comments on commit 5526d4d

Please sign in to comment.