mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Add bootable_volumes collection for managing only bootable volumes.
This commit is contained in:
parent
35234ff2b6
commit
023db627f0
4 changed files with 130 additions and 0 deletions
|
@ -11,6 +11,7 @@ module Fog
|
||||||
model_path 'fog/hp/models/block_storage'
|
model_path 'fog/hp/models/block_storage'
|
||||||
model :volume
|
model :volume
|
||||||
collection :volumes
|
collection :volumes
|
||||||
|
collection :bootable_volumes
|
||||||
|
|
||||||
model :snapshot
|
model :snapshot
|
||||||
collection :snapshots
|
collection :snapshots
|
||||||
|
|
28
lib/fog/hp/models/block_storage/bootable_volumes.rb
Normal file
28
lib/fog/hp/models/block_storage/bootable_volumes.rb
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
require 'fog/core/collection'
|
||||||
|
require 'fog/hp/models/block_storage/volume'
|
||||||
|
|
||||||
|
module Fog
|
||||||
|
module BlockStorage
|
||||||
|
class HP
|
||||||
|
|
||||||
|
class BootableVolumes < Fog::Collection
|
||||||
|
|
||||||
|
model Fog::BlockStorage::HP::Volume
|
||||||
|
|
||||||
|
def all
|
||||||
|
data = connection.list_bootable_volumes.body['volumes']
|
||||||
|
load(data)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get(volume_id)
|
||||||
|
volume = connection.get_bootable_volume_details(volume_id).body['volume']
|
||||||
|
new(volume)
|
||||||
|
rescue Fog::BlockStorage::HP::NotFound
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
23
tests/hp/models/block_storage/bootable_volume_tests.rb
Normal file
23
tests/hp/models/block_storage/bootable_volume_tests.rb
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
Shindo.tests("Fog::BlockStorage[:hp] | bootable volumes", ['hp', 'block_storage', 'volumes']) do
|
||||||
|
|
||||||
|
@base_image_id = ENV["BASE_IMAGE_ID"] || 1242
|
||||||
|
|
||||||
|
model_tests(Fog::BlockStorage[:hp].bootable_volumes, {:name => "fogbvoltests", :description => "fogbvoltests-desc", :size => 10, :image_id => @base_image_id}, true)
|
||||||
|
|
||||||
|
tests("new volume") do
|
||||||
|
@volume = Fog::BlockStorage[:hp].bootable_volumes.create(:name => "testbvol", :size => 10, :image_id => @base_image_id)
|
||||||
|
@volume.wait_for { ready? } unless Fog.mocking?
|
||||||
|
|
||||||
|
test("get(#{@volume.id})") do
|
||||||
|
Fog::BlockStorage[:hp].bootable_volumes.get(@volume.id) != nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
test("has_attachments?") do
|
||||||
|
@volume.has_attachments? == false
|
||||||
|
end
|
||||||
|
after do
|
||||||
|
@volume.destroy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
78
tests/hp/requests/block_storage/bootable_volume_tests.rb
Normal file
78
tests/hp/requests/block_storage/bootable_volume_tests.rb
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
Shindo.tests('Fog::BlockStorage[:hp] | bootable volume requests', ['hp', 'block_storage', 'volumes']) do
|
||||||
|
|
||||||
|
@volume_format = {
|
||||||
|
'status' => String,
|
||||||
|
'displayDescription' => Fog::Nullable::String,
|
||||||
|
'availabilityZone' => String,
|
||||||
|
'displayName' => Fog::Nullable::String,
|
||||||
|
'attachments' => [Fog::Nullable::Hash],
|
||||||
|
'volumeType' => Fog::Nullable::String,
|
||||||
|
'snapshotId' => Fog::Nullable::String,
|
||||||
|
'size' => Integer,
|
||||||
|
'id' => Integer,
|
||||||
|
'createdAt' => String,
|
||||||
|
'metadata' => Fog::Nullable::Hash
|
||||||
|
}
|
||||||
|
|
||||||
|
@boot_volume_format = {
|
||||||
|
'status' => String,
|
||||||
|
'displayDescription' => Fog::Nullable::String,
|
||||||
|
'availabilityZone' => String,
|
||||||
|
'displayName' => Fog::Nullable::String,
|
||||||
|
'attachments' => [Fog::Nullable::Hash],
|
||||||
|
'volumeType' => Fog::Nullable::String,
|
||||||
|
'snapshotId' => Fog::Nullable::String,
|
||||||
|
'source_image_id' => Fog::Nullable::String,
|
||||||
|
'size' => Integer,
|
||||||
|
'id' => Integer,
|
||||||
|
'createdAt' => String,
|
||||||
|
'metadata' => Fog::Nullable::Hash
|
||||||
|
}
|
||||||
|
|
||||||
|
@volume_attach_format = {
|
||||||
|
"volumeId" => Integer,
|
||||||
|
"id" => Integer
|
||||||
|
}
|
||||||
|
|
||||||
|
tests('success') do
|
||||||
|
|
||||||
|
@volume_id = nil
|
||||||
|
@volume_name = "fogbvolumetests"
|
||||||
|
@volume_desc = @volume_name + " desc"
|
||||||
|
@base_image_id = ENV["BASE_IMAGE_ID"] || 1242
|
||||||
|
|
||||||
|
tests("#create_volume(#{@volume_name}, #{@volume_desc}, 10, {'imageRef' => '#{@base_image_id}'})").formats(@volume_format) do
|
||||||
|
data = Fog::BlockStorage[:hp].create_volume(@volume_name, @volume_desc, 10, {'imageRef' => "#{@base_image_id}"}).body['volume']
|
||||||
|
@volume_id = data['id']
|
||||||
|
data
|
||||||
|
end
|
||||||
|
|
||||||
|
Fog::BlockStorage[:hp].volumes.get(@volume_id).wait_for { ready? }
|
||||||
|
tests("#get_bootable_volume_details(#{@volume_id})").formats(@boot_volume_format) do
|
||||||
|
Fog::BlockStorage[:hp].get_bootable_volume_details(@volume_id).body['volume']
|
||||||
|
end
|
||||||
|
|
||||||
|
tests("#list_bootable_volumes").formats({'volumes' => [@boot_volume_format]}) do
|
||||||
|
Fog::BlockStorage[:hp].list_bootable_volumes.body
|
||||||
|
end
|
||||||
|
|
||||||
|
Fog::BlockStorage[:hp].volumes.get(@volume_id).wait_for { ready? }
|
||||||
|
tests("#delete_volume(#{@volume_id})").succeeds do
|
||||||
|
Fog::BlockStorage[:hp].delete_volume(@volume_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('failure') do
|
||||||
|
|
||||||
|
tests("#get_bootable_volume_details(0)").raises(Fog::BlockStorage::HP::NotFound) do
|
||||||
|
Fog::BlockStorage[:hp].get_bootable_volume_details(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
tests("#delete_volume(0)").raises(Fog::BlockStorage::HP::NotFound) do
|
||||||
|
Fog::BlockStorage[:hp].delete_volume(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue