mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Update volume model and collection to handle bootable volumes as well.
This commit is contained in:
parent
e724889f0f
commit
d4feba66df
2 changed files with 26 additions and 5 deletions
|
@ -16,12 +16,20 @@ module Fog
|
|||
attribute :created_at, :aliases => 'createdAt'
|
||||
attribute :availability_zone, :aliases => 'availabilityZone'
|
||||
attribute :snapshot_id, :aliases => 'snapshotId'
|
||||
attribute :source_image_id, :aliases => 'sourceImageRef' # only for bootable volumes
|
||||
attribute :attachments
|
||||
attribute :metadata
|
||||
|
||||
attr_reader :server_id
|
||||
attr_reader :device
|
||||
|
||||
def initialize(attributes = {})
|
||||
# assign these attributes first to prevent race condition with new_record?
|
||||
self.image_id = attributes.delete(:image_id)
|
||||
@connection = attributes[:connection]
|
||||
super
|
||||
end
|
||||
|
||||
def device
|
||||
attachments[0]['device'] if has_attachments?
|
||||
end
|
||||
|
@ -30,6 +38,11 @@ module Fog
|
|||
attachments[0]['serverId'] if has_attachments?
|
||||
end
|
||||
|
||||
# used for creating bootable volumes
|
||||
def image_id=(new_image_id)
|
||||
@image_id = new_image_id
|
||||
end
|
||||
|
||||
# a volume can be attached to only one server at a time
|
||||
def has_attachments?
|
||||
!(attachments.nil? || attachments.empty? || attachments[0].empty?)
|
||||
|
@ -74,7 +87,8 @@ module Fog
|
|||
requires :name, :size
|
||||
options = {
|
||||
'metadata' => metadata,
|
||||
'snapshot_id' => snapshot_id
|
||||
'snapshot_id' => snapshot_id,
|
||||
'imageRef' => @image_id
|
||||
}
|
||||
options = options.reject {|key, value| value.nil?}
|
||||
data = connection.create_volume(name, description, size, options)
|
||||
|
|
|
@ -9,15 +9,22 @@ module Fog
|
|||
|
||||
model Fog::BlockStorage::HP::Volume
|
||||
|
||||
def all
|
||||
data = connection.list_volumes.body['volumes']
|
||||
def all(options={})
|
||||
if @bootable = options[:only_bootable]
|
||||
data = connection.list_bootable_volumes.body['volumes']
|
||||
else
|
||||
data = connection.list_volumes.body['volumes']
|
||||
end
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(volume_id)
|
||||
if volume = connection.get_volume_details(volume_id).body['volume']
|
||||
new(volume)
|
||||
if @bootable
|
||||
volume = connection.get_bootable_volume_details(volume_id).body['volume']
|
||||
else
|
||||
volume = connection.get_volume_details(volume_id).body['volume']
|
||||
end
|
||||
new(volume)
|
||||
rescue Fog::BlockStorage::HP::NotFound
|
||||
nil
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue