mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[openstack|compute] support block_device_mapping
Servers can be booted with block_device_mapping instead of image_id.
This commit is contained in:
parent
f53fc98ff2
commit
8433a74807
2 changed files with 24 additions and 3 deletions
|
@ -41,6 +41,7 @@ module Fog
|
|||
|
||||
attr_reader :password
|
||||
attr_writer :image_ref, :flavor_ref, :nics, :os_scheduler_hints
|
||||
attr_accessor :block_device_mapping
|
||||
|
||||
|
||||
def initialize(attributes={})
|
||||
|
@ -52,6 +53,7 @@ module Fog
|
|||
self.max_count = attributes.delete(:max_count)
|
||||
self.nics = attributes.delete(:nics)
|
||||
self.os_scheduler_hints = attributes.delete(:os_scheduler_hints)
|
||||
self.block_device_mapping = attributes.delete(:block_device_mapping)
|
||||
|
||||
super
|
||||
end
|
||||
|
@ -267,10 +269,10 @@ module Fog
|
|||
true
|
||||
end
|
||||
|
||||
# TODO: Implement /os-volumes-boot support with 'block_device_mapping'
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||
requires :flavor_ref, :image_ref, :name
|
||||
requires :flavor_ref, :name
|
||||
requires_one :image_ref, :block_device_mapping
|
||||
options = {
|
||||
'personality' => personality,
|
||||
'accessIPv4' => accessIPv4,
|
||||
|
@ -283,6 +285,7 @@ module Fog
|
|||
'max_count' => @max_count,
|
||||
'nics' => @nics,
|
||||
'os:scheduler_hints' => @os_scheduler_hints,
|
||||
'block_device_mapping' => @block_device_mapping
|
||||
}
|
||||
options['metadata'] = metadata.to_hash unless @metadata.nil?
|
||||
options = options.reject {|key, value| value.nil?}
|
||||
|
|
|
@ -56,11 +56,29 @@ module Fog
|
|||
data['os:scheduler_hints'] = options['os:scheduler_hints']
|
||||
end
|
||||
|
||||
if options['block_device_mapping']
|
||||
data['server']['block_device_mapping'] =
|
||||
[options['block_device_mapping']].flatten.map do |mapping|
|
||||
{
|
||||
'volume_size' => mapping[:volume_size],
|
||||
'volume_id' => mapping[:volume_id],
|
||||
'delete_on_termination' => mapping[:delete_on_termination],
|
||||
'device_name' => mapping[:device_name]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
path = if data['server']['block_device_mapping']
|
||||
'os-volumes_boot.json'
|
||||
else
|
||||
'servers.json'
|
||||
end
|
||||
|
||||
request(
|
||||
:body => Fog::JSON.encode(data),
|
||||
:expects => [200, 202],
|
||||
:method => 'POST',
|
||||
:path => 'servers.json'
|
||||
:path => path
|
||||
)
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue