2012-08-09 16:51:19 -04:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
2013-01-14 17:51:41 -05:00
|
|
|
module HP
|
|
|
|
class BlockStorage
|
2012-08-09 16:51:19 -04:00
|
|
|
|
|
|
|
class Snapshot < Fog::Model
|
|
|
|
|
|
|
|
identity :id
|
|
|
|
|
|
|
|
attribute :name, :aliases => 'displayName'
|
|
|
|
attribute :description, :aliases => 'displayDescription'
|
|
|
|
attribute :size
|
|
|
|
attribute :status
|
|
|
|
attribute :created_at, :aliases => 'createdAt'
|
|
|
|
attribute :volume_id, :aliases => 'volumeId'
|
|
|
|
#attribute :metadata
|
|
|
|
|
|
|
|
def initialize(attributes = {})
|
2013-01-18 15:08:27 -05:00
|
|
|
# assign these attributes first to prevent race condition with persisted?
|
2012-08-09 16:51:19 -04:00
|
|
|
self.force = attributes.delete(:force) # force snapshotting of attached volumes
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
requires :id
|
2013-01-18 15:08:27 -05:00
|
|
|
service.delete_snapshot(id)
|
2012-08-09 16:51:19 -04:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def force=(new_force)
|
|
|
|
@force = new_force
|
|
|
|
end
|
|
|
|
|
|
|
|
def ready?
|
|
|
|
self.status == 'available'
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
2013-01-18 15:08:27 -05:00
|
|
|
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
2012-08-09 16:51:19 -04:00
|
|
|
requires :name, :volume_id
|
|
|
|
options = {
|
|
|
|
#'metadata' => metadata, # TODO: Add metadata when snapshots support it
|
|
|
|
'force' => @force
|
|
|
|
}
|
|
|
|
options = options.reject {|key, value| value.nil?}
|
2013-01-18 15:08:27 -05:00
|
|
|
data = service.create_snapshot(name, description, volume_id, options)
|
2012-08-09 16:51:19 -04:00
|
|
|
merge_attributes(data.body['snapshot'])
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|