mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
rework mock openstack snapshot to have same behavior as servers...
This commit is contained in:
parent
9cd7ffc241
commit
57db292404
7 changed files with 40 additions and 33 deletions
|
@ -895,3 +895,4 @@
|
|||
* Обоев Рулон ибн Хаттаб <me@nomadrain.com>
|
||||
* 应俊 <yj2317916@gmail.com>
|
||||
* Raul Roa <raulroa@playfulcorp.com>
|
||||
* zhitongLBN <z.liu@linkbynet.com>
|
||||
|
|
|
@ -292,7 +292,8 @@ module Fog
|
|||
'cores' => 20,
|
||||
'ram' => 51200
|
||||
},
|
||||
:volumes => {}
|
||||
:volumes => {},
|
||||
:snapshots => {}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,20 +23,27 @@ module Fog
|
|||
|
||||
class Mock
|
||||
def create_volume_snapshot(volume_id, name, description, force=false)
|
||||
volume_response = get_volume_details(volume_id)
|
||||
volume = volume_response.data[:body]['volume']
|
||||
unless volume.nil?
|
||||
response = Excon::Response.new
|
||||
response.status = 202
|
||||
response.body = {
|
||||
"snapshot"=> {
|
||||
"status"=>"creating",
|
||||
"display_name"=>name,
|
||||
data = {
|
||||
"status" => "availble",
|
||||
"name" => name,
|
||||
"created_at" => Time.now,
|
||||
"display_description"=>description,
|
||||
"description" => description,
|
||||
"volume_id" => volume_id,
|
||||
"id"=>"5",
|
||||
"size"=>1
|
||||
}
|
||||
"id" => Fog::Mock.random_numbers(2),
|
||||
"size" => volume['size']
|
||||
}
|
||||
|
||||
self.data[:snapshots][data['id']] = data
|
||||
response.body = { "snapshot" => data }
|
||||
response.status = 202
|
||||
response
|
||||
else
|
||||
raise Fog::Compute::OpenStack::NotFound
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,6 +15,11 @@ module Fog
|
|||
def delete_snapshot(snapshot_id)
|
||||
response = Excon::Response.new
|
||||
response.status = 204
|
||||
if list_snapshots_detail.body['snapshots'].find { |_| _['id'] == snapshot_id }
|
||||
self.data[:snapshots].delete(snapshot_id)
|
||||
else
|
||||
raise Fog::Compute::OpenStack::NotFound
|
||||
end
|
||||
response
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,19 +14,14 @@ module Fog
|
|||
class Mock
|
||||
def get_snapshot_details(snapshot_id)
|
||||
response = Excon::Response.new
|
||||
if snapshot = list_snapshots_detail.body['snapshots'].find{
|
||||
|_| _['id'] == snapshot_id }
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'snapshot' => {
|
||||
'id' => '1',
|
||||
'display_name' => Fog::Mock.random_letters(rand(8) + 5),
|
||||
'display_description' => Fog::Mock.random_letters(rand(12) + 10),
|
||||
'size' => 3,
|
||||
'volume_id' => '4',
|
||||
'status' => 'online',
|
||||
'created_at' => Time.now
|
||||
}
|
||||
}
|
||||
response.body = { 'snapshot' => snapshot }
|
||||
response
|
||||
else
|
||||
raise Fog::Compute::OpenStack::NotFound
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -30,9 +30,8 @@ module Fog
|
|||
def list_snapshots(options = true)
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'snapshots' => [get_snapshot_details.body["snapshot"]]
|
||||
}
|
||||
snapshots = self.data[:snapshots].values
|
||||
response.body = { 'snapshots' => snapshots }
|
||||
response
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,9 +16,8 @@ module Fog
|
|||
def list_snapshots_detail(options = {})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
response.body = {
|
||||
'snapshots' => [get_snapshot_details.body["snapshot"]]
|
||||
}
|
||||
snapshots = self.data[:snapshots].values
|
||||
response.body = { 'snapshots' => snapshots }
|
||||
response
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue