2012-08-02 18:01:18 -04:00
|
|
|
module Fog
|
2013-01-14 17:51:41 -05:00
|
|
|
module HP
|
|
|
|
class BlockStorage
|
2012-08-02 18:01:18 -04:00
|
|
|
class Real
|
|
|
|
|
|
|
|
# Create a new block storage snapshot
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
|
|
|
# * name<~String> - Name of the snapshot
|
|
|
|
# * description<~String> - Description of the snapshot
|
|
|
|
# * volume_id<~Integer> - Id of the volume to create snapshot of
|
|
|
|
# * options<~Hash>:
|
2012-08-03 12:37:16 -04:00
|
|
|
# * 'force'<~Boolean> - Not implemented yet. True or False, to allow online snapshots (i.e. when volume is attached)
|
2012-08-02 18:01:18 -04:00
|
|
|
#
|
|
|
|
# ==== Returns
|
|
|
|
# * response<~Excon::Response>:
|
|
|
|
# * body<~Hash>:
|
|
|
|
# * snapshot<~Hash>:
|
|
|
|
# * 'id'<~Integer>: - Id for the snapshot
|
|
|
|
# * 'displayName'<~String>: - Name of the snapshot
|
|
|
|
# * 'displayDescription'<~String>: - Description of the snapshot
|
|
|
|
# * 'size'<~Integer>: - Size in GB for the snapshot
|
|
|
|
# * 'status'<~String>: - Status of the snapshot i.e. "creating"
|
2012-08-02 18:58:33 -04:00
|
|
|
# * 'volumeId'<~Integer>: - Id of the volume from which the snapshot was created
|
2012-08-02 18:01:18 -04:00
|
|
|
# * 'createdAt'<~String>: - Timestamp in UTC when snapshot was created
|
|
|
|
def create_snapshot(name, description, volume_id, options={})
|
|
|
|
data = {
|
|
|
|
'snapshot' => {
|
|
|
|
'display_name' => name,
|
|
|
|
'display_description' => description,
|
|
|
|
'volume_id' => volume_id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
l_options = ['force']
|
|
|
|
l_options.select{|o| options[o]}.each do |key|
|
|
|
|
data['snapshot'][key] = options[key]
|
|
|
|
end
|
|
|
|
|
|
|
|
request(
|
2013-01-18 15:08:27 -05:00
|
|
|
:body => Fog::JSON.encode(data),
|
2012-08-02 18:01:18 -04:00
|
|
|
:expects => 200,
|
|
|
|
:method => 'POST',
|
|
|
|
:path => "os-snapshots"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Mock # :nodoc:all
|
|
|
|
|
|
|
|
def create_snapshot(name, description, volume_id, options={})
|
|
|
|
response = Excon::Response.new
|
|
|
|
if self.data[:volumes][volume_id]
|
|
|
|
response.status = 200
|
|
|
|
data = {
|
|
|
|
'id' => Fog::Mock.random_numbers(3).to_i,
|
|
|
|
'displayName' => name,
|
|
|
|
'displayDescription' => description,
|
|
|
|
'size' => self.data[:volumes][volume_id]['size'],
|
|
|
|
'status' => 'available',
|
|
|
|
'volumeId' => volume_id,
|
|
|
|
'createdAt' => Time.now.to_s
|
|
|
|
}
|
|
|
|
self.data[:snapshots][data['id']] = data
|
|
|
|
response.body = { 'snapshot' => data }
|
|
|
|
else
|
2013-01-14 17:51:41 -05:00
|
|
|
raise Fog::HP::BlockStorage::NotFound
|
2012-08-02 18:01:18 -04:00
|
|
|
end
|
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|