mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[cloudstack] add snapshot model
This commit is contained in:
parent
33ad60352f
commit
7fe7796412
5 changed files with 132 additions and 0 deletions
|
@ -33,6 +33,8 @@ module Fog
|
|||
collection :security_group_rules
|
||||
model :volume
|
||||
collection :volumes
|
||||
model :snapshot
|
||||
collection :snapshots
|
||||
model :zone
|
||||
collection :zones
|
||||
|
||||
|
@ -420,6 +422,7 @@ module Fog
|
|||
:jobs => {},
|
||||
:volumes => {},
|
||||
:security_groups => {},
|
||||
:snapshots => {}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
46
lib/fog/cloudstack/models/compute/snapshot.rb
Normal file
46
lib/fog/cloudstack/models/compute/snapshot.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class Snapshot < Fog::Model
|
||||
identity :id, :aliases => 'id'
|
||||
|
||||
attribute :name, :aliases => 'name'
|
||||
attribute :volume_type, :aliases => 'volumetype'
|
||||
attribute :volume_name, :aliases => 'volumename'
|
||||
attribute :volume_id, :aliases => 'volumeid'
|
||||
attribute :created, :aliases => 'created'
|
||||
attribute :state, :aliases => 'state'
|
||||
attribute :account, :aliases => 'account'
|
||||
attribute :domain_id, :aliases => 'domainid'
|
||||
attribute :domain, :aliases => 'domain'
|
||||
attribute :snapshot_type, :aliases => 'snapshot_type'
|
||||
attribute :interval_type, :aliases => 'interval_type'
|
||||
|
||||
def save
|
||||
requires :volume_id
|
||||
|
||||
options = {
|
||||
'volumeid' => volume_id,
|
||||
'domainid' => domain_id
|
||||
}
|
||||
data = service.create_snapshot(options)
|
||||
merge_attributes(data['createsnapshotresponse'])
|
||||
end
|
||||
|
||||
def ready?
|
||||
state == 'BackedUp'
|
||||
end
|
||||
|
||||
def volume
|
||||
service.volumes.get(volume_id) if volume_id
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :id
|
||||
service.delete_snapshot('id' => id)
|
||||
true
|
||||
end
|
||||
end # Snapshot
|
||||
end # Cloudstack
|
||||
end # Compute
|
||||
end # Fog
|
25
lib/fog/cloudstack/models/compute/snapshots.rb
Normal file
25
lib/fog/cloudstack/models/compute/snapshots.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/cloudstack/models/compute/snapshot'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
|
||||
class Snapshots < Fog::Collection
|
||||
|
||||
model Fog::Compute::Cloudstack::Snapshot
|
||||
|
||||
def all
|
||||
data = service.list_snapshots["listsnapshotsresponse"]["snapshot"] || []
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(snapshot_id)
|
||||
snapshot = service.list_snapshots('id' => snapshot_id)["listsnapshotsresponse"]["snapshot"].first
|
||||
new(snapshot) if snapshot
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -15,6 +15,30 @@ module Fog
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
def create_snapshot(options={})
|
||||
snapshot_id = Fog::Cloudstack.uuid
|
||||
|
||||
unless volume_id = options['volumeid']
|
||||
raise Fog::Compute::Cloudstack::BadRequest.new('Unable to execute API command createsnapshot due to missing parameter volumeid')
|
||||
end
|
||||
|
||||
snapshot = {
|
||||
"id" => snapshot_id,
|
||||
"name" => "ROOT-6",
|
||||
"created" => "2013-05-22T14:52:55-0500",
|
||||
"state" => "BackedUp",
|
||||
"account" => "accountname",
|
||||
"domainid" => "6023b6fe-5bef-4358-bc76-9f4e75afa52f",
|
||||
"domain" => "ROOT",
|
||||
"intervaltype" => "weekly"
|
||||
}
|
||||
|
||||
self.data[:snapshots][snapshot_id]= snapshot
|
||||
{'createsnapshotresponse' => snapshot}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
34
tests/cloudstack/compute/models/snapshot_tests.rb
Normal file
34
tests/cloudstack/compute/models/snapshot_tests.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
def snapshot_tests(connection, params, mocks_implemented = true)
|
||||
model_tests(connection.snapshots, params[:snapshot_attributes], mocks_implemented) do
|
||||
if !Fog.mocking? || mocks_implemented
|
||||
@instance.wait_for { ready? }
|
||||
end
|
||||
|
||||
@volume = @instance.connection.volumes.create(params[:volumes_attributes])
|
||||
@volume.wait_for { ready? }
|
||||
|
||||
tests('create').succeeds do
|
||||
@instance.create volume_id: @volume.id
|
||||
end
|
||||
|
||||
tests('destroy').succeeds do
|
||||
@instance.destroy
|
||||
end
|
||||
|
||||
@volume.destroy
|
||||
end
|
||||
end
|
||||
|
||||
Shindo.tests("Fog::Compute[:cloudstack] | snapshot", "cloudstack") do
|
||||
|
||||
config = compute_providers[:cloudstack]
|
||||
|
||||
snapshot_tests(Fog::Compute[:cloudstack], config, config[:mocked]) do
|
||||
if Fog.mocking? && !mocks_implemented
|
||||
pending
|
||||
else
|
||||
responds_to(:ready?)
|
||||
responds_to(:volume)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue