mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[hp|block_storage_v2] Add volume backups model, along with tests.
This commit is contained in:
parent
ee796dfa2f
commit
99975f6f48
5 changed files with 132 additions and 0 deletions
|
@ -14,6 +14,8 @@ module Fog
|
|||
model_path 'fog/hp/models/block_storage_v2'
|
||||
model :volume
|
||||
collection :volumes
|
||||
model :volume_backup
|
||||
collection :volume_backups
|
||||
model :snapshot
|
||||
collection :snapshots
|
||||
|
||||
|
|
58
lib/fog/hp/models/block_storage_v2/volume_backup.rb
Normal file
58
lib/fog/hp/models/block_storage_v2/volume_backup.rb
Normal file
|
@ -0,0 +1,58 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module HP
|
||||
class BlockStorageV2
|
||||
|
||||
class VolumeBackup < Fog::Model
|
||||
|
||||
identity :id
|
||||
|
||||
attribute :name
|
||||
attribute :description
|
||||
attribute :size
|
||||
attribute :status
|
||||
attribute :created_at
|
||||
attribute :availability_zone
|
||||
attribute :volume_id
|
||||
attribute :container
|
||||
attribute :fail_reason
|
||||
attribute :object_count
|
||||
attribute :links
|
||||
|
||||
def restoring?
|
||||
self.status == 'restoring'
|
||||
end
|
||||
|
||||
def ready?
|
||||
self.status == 'available'
|
||||
end
|
||||
|
||||
def restore(volume_id=nil)
|
||||
requires :id
|
||||
if volume_id
|
||||
service.restore_volume_backup(id, :volume_id => volume_id)
|
||||
else
|
||||
service.restore_volume_backup(id)
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :id
|
||||
service.delete_volume_backup(id)
|
||||
true
|
||||
end
|
||||
|
||||
def save
|
||||
requires :volume_id
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
merge_attributes(service.create_volume_backup(volume_id, attributes).body['backup'])
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
41
lib/fog/hp/models/block_storage_v2/volume_backups.rb
Normal file
41
lib/fog/hp/models/block_storage_v2/volume_backups.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/hp/models/block_storage_v2/volume_backup'
|
||||
|
||||
module Fog
|
||||
module HP
|
||||
class BlockStorageV2
|
||||
|
||||
class VolumeBackups < Fog::Collection
|
||||
|
||||
attribute :filters
|
||||
|
||||
model Fog::HP::BlockStorageV2::VolumeBackup
|
||||
|
||||
def initialize(attributes)
|
||||
self.filters ||= {}
|
||||
super
|
||||
end
|
||||
|
||||
def all(filters = filters)
|
||||
details = filters.delete(:details)
|
||||
self.filters = filters
|
||||
if details
|
||||
data = service.list_volume_backups_detail(filters).body['backups']
|
||||
else
|
||||
data = service.list_volume_backups(filters).body['backups']
|
||||
end
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(backup_id)
|
||||
backup = service.get_volume_backup_details(backup_id).body['backup']
|
||||
new(backup)
|
||||
rescue Fog::HP::BlockStorageV2::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
22
tests/hp/models/block_storage_v2/volume_backup_tests.rb
Normal file
22
tests/hp/models/block_storage_v2/volume_backup_tests.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
Shindo.tests("HP::BlockStorage | volume backup model", ['hp', 'v2', 'block_storage', 'backup']) do
|
||||
|
||||
@volume = HP[:block_storage_v2].volumes.create(:name => 'fogvolbkp2tests', :description => 'fogvolbkp2tests-desc', :size => 1)
|
||||
@volume.wait_for { ready? } unless Fog.mocking?
|
||||
|
||||
model_tests(HP[:block_storage_v2].volume_backups, {:name => 'fogbkp2tests', :description => 'fogbkp2tests-desc', :volume_id => @volume.id}, true) do
|
||||
|
||||
# restore to new volume
|
||||
tests('restore()').succeeds do
|
||||
@instance.restore
|
||||
end
|
||||
|
||||
# restore to specified volume
|
||||
tests("restore(#{@volume.id})").succeeds do
|
||||
@instance.restore(@volume.id)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@volume.destroy
|
||||
|
||||
end
|
9
tests/hp/models/block_storage_v2/volume_backups_tests.rb
Normal file
9
tests/hp/models/block_storage_v2/volume_backups_tests.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
Shindo.tests("Fog::Compute::HPV2 | volume backups collection", ['hp', 'v2', 'block_storage', 'backup']) do
|
||||
|
||||
@volume = HP[:block_storage_v2].volumes.create(:name => 'fogvolbkp2tests', :description => 'fogvolbkp2tests-desc', :size => 1)
|
||||
@volume.wait_for { ready? } unless Fog.mocking?
|
||||
|
||||
collection_tests(HP[:block_storage_v2].volume_backups, {:name => 'fogbkp2tests', :description => 'fogbkp2tests-desc', :volume_id => @volume.id}, true)
|
||||
|
||||
@volume.destroy
|
||||
end
|
Loading…
Reference in a new issue