2012-07-09 11:53:23 -04:00
module Fog
2013-01-14 17:51:41 -05:00
module HP
class BlockStorage
2012-07-09 11:53:23 -04:00
class Real
# Create a new block storage volume
#
# ==== Parameters
# * name<~String> - Name of the volume
# * description<~String> - Description of the volume
# * size<~Integer> - Size of the volume (in GBs)
# * options<~Hash>:
2012-11-06 20:46:54 -05:00
# * 'snapshot_id'<~String> - Id of the volume snapshot to create the volume from. The request is invalid if both the snapshot_id and the imageRef parameters are specified and are not null.
# * 'imageRef'<~String> - Id of the image to create the volume from. This creates a bootable volume. The request is invalid if both the snapshot_id and the imageRef parameters are specified and are not null.
2012-07-09 11:53:23 -04:00
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * volume<~Hash>:
2012-11-06 20:46:54 -05:00
# * 'id'<~Integer> - Id for the volume
# * 'displayName'<~String> - Name of the volume
# * 'displayDescription'<~String> - Description of the volume
# * 'size'<~Integer> - Size in GB for the volume
# * 'status'<~String> - Status of the volume i.e. "creating"
# * 'volumeType'<~String> - Type of the volume
# * 'snapshotId'<~String> - Id of the snapshot, the volume was created from.
# * 'imageRef'<~String> - Id of the image, the volume was created from. A not null value means it is a bootable volume.
# * 'createdAt'<~String> - Timestamp in UTC when volume was created
# * 'availabilityZone'<~String> - Availability zone i.e. "nova"
2012-07-09 11:53:23 -04:00
# * attachments<~Array>: Array of hashes of attachments
# * metadata<~Hash>: Hash of metadata for the volume
def create_volume ( name , description , size , options = { } )
data = {
'volume' = > {
'display_name' = > name ,
'display_description' = > description ,
'size' = > size
}
}
2012-11-06 20:46:54 -05:00
l_options = [ 'snapshot_id' , 'imageRef' , 'metadata' ]
2012-07-09 11:53:23 -04:00
l_options . select { | o | options [ o ] } . each do | key |
data [ 'volume' ] [ key ] = options [ key ]
end
2012-07-09 12:52:31 -04:00
2012-07-09 11:53:23 -04:00
request (
2013-01-18 15:08:27 -05:00
:body = > Fog :: JSON . encode ( data ) ,
2012-07-09 11:53:23 -04:00
:expects = > 200 ,
:method = > 'POST' ,
:path = > " os-volumes "
)
end
end
class Mock # :nodoc:all
def create_volume ( name , description , size , options = { } )
2012-11-08 15:27:33 -05:00
if options [ 'snapshotId' ] && options [ 'imageRef' ]
2012-11-06 20:46:54 -05:00
raise Fog :: Errors :: BadRequest . new ( " Snapshot and image cannot be specified together. " )
else
response = Excon :: Response . new
response . status = 200
data = {
'id' = > Fog :: Mock . random_numbers ( 3 ) . to_i ,
'displayName' = > name ,
'displayDescription' = > description ,
'size' = > size ,
'status' = > 'available' ,
'snapshotId' = > options [ 'snapshot_id' ] || " " ,
#'imageRef' => options['imageRef'] || "", # TODO: not implemented to preserve backward compatibility
'volumeType' = > nil ,
'availabilityZone' = > 'nova' ,
'createdAt' = > Time . now . to_s ,
'metadata' = > options [ 'metadata' ] || { } ,
'attachments' = > [ { } ]
}
self . data [ :volumes ] [ data [ 'id' ] ] = data
response . body = { 'volume' = > data }
response
end
2012-07-09 11:53:23 -04:00
end
end
end
end
end