mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[rackspace|blockstorage] Add snapshots to block storage.
This commit is contained in:
parent
4206fcfae2
commit
5fcb9e6e37
8 changed files with 162 additions and 9 deletions
|
@ -42,15 +42,15 @@ module Fog
|
|||
end
|
||||
end
|
||||
|
||||
service(:block_storage, 'rackspace/block_storage', 'BlockStorage')
|
||||
service(:cdn, 'rackspace/cdn', 'CDN')
|
||||
service(:compute, 'rackspace/compute', 'Compute')
|
||||
service(:compute_v2, 'rackspace/compute_v2', 'Compute v2')
|
||||
service(:dns, 'rackspace/dns', 'DNS')
|
||||
service(:storage, 'rackspace/storage', 'Storage')
|
||||
service(:load_balancers, 'rackspace/load_balancers', 'LoadBalancers')
|
||||
service(:identity, 'rackspace/identity', 'Identity')
|
||||
service(:databases, 'rackspace/databases', 'Databases')
|
||||
service(:block_storage, 'rackspace/block_storage', 'BlockStorage')
|
||||
service(:cdn, 'rackspace/cdn', 'CDN')
|
||||
service(:compute, 'rackspace/compute', 'Compute')
|
||||
service(:compute_v2, 'rackspace/compute_v2', 'Compute v2')
|
||||
service(:dns, 'rackspace/dns', 'DNS')
|
||||
service(:storage, 'rackspace/storage', 'Storage')
|
||||
service(:load_balancers, 'rackspace/load_balancers', 'LoadBalancers')
|
||||
service(:identity, 'rackspace/identity', 'Identity')
|
||||
service(:databases, 'rackspace/databases', 'Databases')
|
||||
|
||||
def self.authenticate(options, connection_options = {})
|
||||
rackspace_auth_url = options[:rackspace_auth_url] || "auth.api.rackspacecloud.com"
|
||||
|
|
|
@ -19,17 +19,28 @@ module Fog
|
|||
model_path 'fog/rackspace/models/block_storage'
|
||||
model :volume
|
||||
collection :volumes
|
||||
|
||||
model :volume_type
|
||||
collection :volume_types
|
||||
model :snapshot
|
||||
collection :snapshots
|
||||
|
||||
model :snapshot
|
||||
collection :snapshots
|
||||
|
||||
request_path 'fog/rackspace/requests/block_storage'
|
||||
request :create_volume
|
||||
request :delete_volume
|
||||
request :get_volume
|
||||
request :list_volumes
|
||||
|
||||
request :get_volume_type
|
||||
request :list_volume_types
|
||||
|
||||
request :create_snapshot
|
||||
request :delete_snapshot
|
||||
request :get_snapshot
|
||||
request :list_snapshots
|
||||
|
||||
class Mock
|
||||
def request(params)
|
||||
|
|
46
lib/fog/rackspace/models/block_storage/snapshot.rb
Normal file
46
lib/fog/rackspace/models/block_storage/snapshot.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Rackspace
|
||||
class BlockStorage
|
||||
class Snapshot < Fog::Model
|
||||
AVAILABLE = 'available'
|
||||
CREATING = 'creating'
|
||||
DELETING = 'deleting'
|
||||
ERROR = 'error'
|
||||
ERROR_DELETING = 'error_deleting'
|
||||
|
||||
identity :id
|
||||
|
||||
attribute :created_at, :aliases => 'createdAt'
|
||||
attribute :state, :aliases => 'status'
|
||||
attribute :display_name
|
||||
attribute :display_description
|
||||
attribute :size
|
||||
attribute :volume_id
|
||||
attribute :availability_zone
|
||||
|
||||
def ready?
|
||||
state == AVAILABLE
|
||||
end
|
||||
|
||||
def save(force = false)
|
||||
requires :volume_id
|
||||
data = connection.create_snapshot(volume_id, {
|
||||
:display_name => display_name,
|
||||
:display_description => display_description,
|
||||
:force => force
|
||||
})
|
||||
merge_attributes(data.body['snapshot'])
|
||||
true
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :identity
|
||||
connection.delete_snapshot(identity)
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
25
lib/fog/rackspace/models/block_storage/snapshots.rb
Normal file
25
lib/fog/rackspace/models/block_storage/snapshots.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/rackspace/models/block_storage/snapshot'
|
||||
|
||||
module Fog
|
||||
module Rackspace
|
||||
class BlockStorage
|
||||
class Snapshots < Fog::Collection
|
||||
|
||||
model Fog::Rackspace::BlockStorage::Snapshot
|
||||
|
||||
def all
|
||||
data = connection.list_snapshots.body['snapshots']
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(snapshot_id)
|
||||
data = connection.get_snapshot(snapshot_id).body['snapshot']
|
||||
new(data)
|
||||
rescue Fog::Rackspace::BlockStorage::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
26
lib/fog/rackspace/requests/block_storage/create_snapshot.rb
Normal file
26
lib/fog/rackspace/requests/block_storage/create_snapshot.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class BlockStorage
|
||||
class Real
|
||||
def create_snapshot(volume_id, options = {})
|
||||
data = {
|
||||
'snapshot' => {
|
||||
'volume_id' => volume_id
|
||||
}
|
||||
}
|
||||
|
||||
data['snapshot']['display_name'] = options[:display_name] unless options[:display_name].nil?
|
||||
data['snapshot']['display_description'] = options[:display_description] unless options[:display_description].nil?
|
||||
data['snapshot']['force'] = options[:force] unless options[:force].nil?
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:expects => [200],
|
||||
:method => 'POST',
|
||||
:path => "snapshots"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
15
lib/fog/rackspace/requests/block_storage/delete_snapshot.rb
Normal file
15
lib/fog/rackspace/requests/block_storage/delete_snapshot.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class BlockStorage
|
||||
class Real
|
||||
def delete_snapshot(snapshot_id)
|
||||
request(
|
||||
:expects => [202],
|
||||
:method => 'DELETE',
|
||||
:path => "snapshots/#{snapshot_id}"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
15
lib/fog/rackspace/requests/block_storage/get_snapshot.rb
Normal file
15
lib/fog/rackspace/requests/block_storage/get_snapshot.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class BlockStorage
|
||||
class Real
|
||||
def get_snapshot(snapshot_id)
|
||||
request(
|
||||
:expects => [200],
|
||||
:method => 'GET',
|
||||
:path => "snapshots/#{snapshot_id}"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
15
lib/fog/rackspace/requests/block_storage/list_snapshots.rb
Normal file
15
lib/fog/rackspace/requests/block_storage/list_snapshots.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
module Fog
|
||||
module Rackspace
|
||||
class BlockStorage
|
||||
class Real
|
||||
def list_snapshots
|
||||
request(
|
||||
:expects => [200],
|
||||
:method => 'GET',
|
||||
:path => 'snapshots'
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue