-
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#1698 from dm1try/master
[cloudstack] add snapshot model
- Loading branch information
Showing
5 changed files
with
132 additions
and
0 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,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 |
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,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 |
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,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 |