1
0
Fork 0
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:
Rupak Ganguly 2012-11-14 15:09:48 -05:00
parent e724889f0f
commit d4feba66df
2 changed files with 26 additions and 5 deletions

View file

@ -16,12 +16,20 @@ module Fog
attribute :created_at, :aliases => 'createdAt' attribute :created_at, :aliases => 'createdAt'
attribute :availability_zone, :aliases => 'availabilityZone' attribute :availability_zone, :aliases => 'availabilityZone'
attribute :snapshot_id, :aliases => 'snapshotId' attribute :snapshot_id, :aliases => 'snapshotId'
attribute :source_image_id, :aliases => 'sourceImageRef' # only for bootable volumes
attribute :attachments attribute :attachments
attribute :metadata attribute :metadata
attr_reader :server_id attr_reader :server_id
attr_reader :device 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 def device
attachments[0]['device'] if has_attachments? attachments[0]['device'] if has_attachments?
end end
@ -30,6 +38,11 @@ module Fog
attachments[0]['serverId'] if has_attachments? attachments[0]['serverId'] if has_attachments?
end 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 # a volume can be attached to only one server at a time
def has_attachments? def has_attachments?
!(attachments.nil? || attachments.empty? || attachments[0].empty?) !(attachments.nil? || attachments.empty? || attachments[0].empty?)
@ -74,7 +87,8 @@ module Fog
requires :name, :size requires :name, :size
options = { options = {
'metadata' => metadata, 'metadata' => metadata,
'snapshot_id' => snapshot_id 'snapshot_id' => snapshot_id,
'imageRef' => @image_id
} }
options = options.reject {|key, value| value.nil?} options = options.reject {|key, value| value.nil?}
data = connection.create_volume(name, description, size, options) data = connection.create_volume(name, description, size, options)

View file

@ -9,15 +9,22 @@ module Fog
model Fog::BlockStorage::HP::Volume model Fog::BlockStorage::HP::Volume
def all def all(options={})
data = connection.list_volumes.body['volumes'] if @bootable = options[:only_bootable]
data = connection.list_bootable_volumes.body['volumes']
else
data = connection.list_volumes.body['volumes']
end
load(data) load(data)
end end
def get(volume_id) def get(volume_id)
if volume = connection.get_volume_details(volume_id).body['volume'] if @bootable
new(volume) volume = connection.get_bootable_volume_details(volume_id).body['volume']
else
volume = connection.get_volume_details(volume_id).body['volume']
end end
new(volume)
rescue Fog::BlockStorage::HP::NotFound rescue Fog::BlockStorage::HP::NotFound
nil nil
end end