mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Add a create_snapshot request method, a corresponding mock, and add support for it in the block storage provider.
This commit is contained in:
parent
d5ead5d6af
commit
78165031ba
2 changed files with 77 additions and 0 deletions
|
@ -18,6 +18,7 @@ module Fog
|
|||
request :get_volume_details
|
||||
request :list_volumes
|
||||
|
||||
request :create_snapshot
|
||||
request :list_snapshots
|
||||
|
||||
module Utils
|
||||
|
|
76
lib/fog/hp/requests/block_storage/create_snapshot.rb
Normal file
76
lib/fog/hp/requests/block_storage/create_snapshot.rb
Normal file
|
@ -0,0 +1,76 @@
|
|||
module Fog
|
||||
module BlockStorage
|
||||
class HP
|
||||
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>:
|
||||
# * 'force'<~Boolean> - True or False
|
||||
#
|
||||
# ==== 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"
|
||||
# * 'volumeId'<~String>: - Id of the volume from which the snapshot was created
|
||||
# * '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(
|
||||
:body => MultiJson.encode(data),
|
||||
: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
|
||||
raise Fog::BlockStorage::HP::NotFound
|
||||
end
|
||||
response
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue