2012-08-23 16:03:28 -03:00
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'
2013-03-21 15:40:24 -05:00
# @!attribute [r] id
# @return [String] The snapshot id
2012-08-23 16:03:28 -03:00
identity :id
2013-03-21 15:40:24 -05:00
# @!attribute [r] created_at
# @return [String] snapshot creation time
2012-08-23 16:03:28 -03:00
attribute :created_at , :aliases = > 'createdAt'
2013-03-21 15:40:24 -05:00
# @!attribute [r] state
# @return [String] snapshot status
2012-08-23 16:03:28 -03:00
attribute :state , :aliases = > 'status'
2013-03-21 15:40:24 -05:00
# @!attribute [rw] display_name
# @return [String] display name of snapshot
2012-08-23 16:03:28 -03:00
attribute :display_name
2013-03-21 15:40:24 -05:00
# @!attribute [rw] display_description
# @return [String] display description of snapshot
2012-08-23 16:03:28 -03:00
attribute :display_description
2013-03-21 15:40:24 -05:00
# @!attribute [rw] size
# @return [String] size of snapshot
2012-08-23 16:03:28 -03:00
attribute :size
2013-03-21 15:40:24 -05:00
# @!attribute [rw] volume_id
# @return [String] the volume_id of the snapshot
2012-08-23 16:03:28 -03:00
attribute :volume_id
2013-03-21 15:40:24 -05:00
# @!attribute [r] availability_zone
# @return [String] region of the snapshot
2012-08-23 16:03:28 -03:00
attribute :availability_zone
2013-03-21 15:40:24 -05:00
# Returns true if the snapshot is in a ready state
# @return [Boolean] returns true if snapshot is in a ready state
2012-08-23 16:03:28 -03:00
def ready?
state == AVAILABLE
end
2013-03-21 15:40:24 -05:00
# Creates the snapshot
# @param force [Boolean] Set to true to force service to create snapshot
# @raise [Fog::Rackspace::BlockStorage::IdentifierTaken] if the snapshot has been previously saved.
# @return [Boolean] returns true if snapshot is being created
2013-03-27 09:50:30 -05:00
# @raise [Fog::Rackspace::Errors::NotFound] - HTTP 404
# @raise [Fog::Rackspace::Errors::BadRequest] - HTTP 400
# @raise [Fog::Rackspace::Errors::InternalServerError] - HTTP 500
# @raise [Fog::Rackspace::Errors::ServiceError]
2013-03-21 15:40:24 -05:00
# @note A snapshot object cannot be updated
# @note All writes to the volume should be flushed before creating the snapshot, either by un-mounting any file systems on the volume or by detaching the volume.
# @see http://docs.rackspace.com/cbs/api/v1.0/cbs-devguide/content/POST_createSnapshot__v1__tenant_id__snapshots.html
2012-08-23 16:03:28 -03:00
def save ( force = false )
requires :volume_id
2012-12-23 02:45:05 +00:00
raise IdentifierTaken . new ( 'Resaving may cause a duplicate snapshot to be created' ) if persisted?
2012-12-22 23:24:03 +00:00
data = service . create_snapshot ( volume_id , {
2012-08-23 16:03:28 -03:00
:display_name = > display_name ,
:display_description = > display_description ,
:force = > force
} )
merge_attributes ( data . body [ 'snapshot' ] )
true
end
2013-03-21 15:40:24 -05:00
# Destroys snapshot
# @return [Boolean] returns true if snapshot was deleted
2013-03-27 09:50:30 -05:00
# @raise [Fog::Rackspace::Errors::NotFound] - HTTP 404
# @raise [Fog::Rackspace::Errors::BadRequest] - HTTP 400
# @raise [Fog::Rackspace::Errors::InternalServerError] - HTTP 500
# @raise [Fog::Rackspace::Errors::ServiceError]
2013-03-21 15:40:24 -05:00
# @see http://docs.rackspace.com/cbs/api/v1.0/cbs-devguide/content/DELETE_deleteSnapshot__v1__tenant_id__snapshots.html
2012-08-23 16:03:28 -03:00
def destroy
requires :identity
2012-12-22 23:24:03 +00:00
service . delete_snapshot ( identity )
2012-08-23 16:03:28 -03:00
true
end
end
end
end
end