mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #1922 from grk/volume-create-image-ref
OpenStack: create volumes from images, boot servers with block device mapping
This commit is contained in:
commit
2340c8029e
5 changed files with 33 additions and 7 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?}
|
||||
|
|
|
@ -12,11 +12,13 @@ module Fog
|
|||
attribute :display_description, :aliases => 'displayDescription'
|
||||
attribute :status
|
||||
attribute :size
|
||||
attribute :type, :aliases => 'volumeType'
|
||||
attribute :volume_type, :aliases => ['volumeType', 'type']
|
||||
attribute :snapshot_id, :aliases => 'snapshotId'
|
||||
attribute :imageRef, :aliases => 'image_id'
|
||||
attribute :availability_zone, :aliases => 'availabilityZone'
|
||||
attribute :created_at, :aliases => 'createdAt'
|
||||
attribute :attachments
|
||||
attribute :source_volid
|
||||
|
||||
|
||||
def initialize(attributes)
|
||||
|
|
|
@ -12,13 +12,14 @@ module Fog
|
|||
load(service.list_volumes(detailed).body['volumes'])
|
||||
end
|
||||
|
||||
def find_by_id(volume_id)
|
||||
def get(volume_id)
|
||||
if volume = service.get_volume_details(volume_id).body['volume']
|
||||
new(volume)
|
||||
end
|
||||
rescue Fog::Volume::OpenStack::NotFound
|
||||
nil
|
||||
end
|
||||
alias_method :find_by_id, :get
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -12,7 +12,8 @@ module Fog
|
|||
}
|
||||
}
|
||||
|
||||
vanilla_options = ['snapshot_id']
|
||||
vanilla_options = [:snapshot_id, :imageRef, :volume_type,
|
||||
:source_volid]
|
||||
vanilla_options.select{|o| options[o]}.each do |key|
|
||||
data['volume'][key] = options[key]
|
||||
end
|
||||
|
@ -38,7 +39,8 @@ module Fog
|
|||
'display_description' => description,
|
||||
'size' => size,
|
||||
'status' => 'creating',
|
||||
'snapshot_id' => options["snapshot_id"] || nil,
|
||||
'snapshot_id' => options[:snapshot_id] || nil,
|
||||
'image_id' => options[:imageRef] || nil,
|
||||
'volume_type' => nil,
|
||||
'availability_zone' => 'nova',
|
||||
'created_at' => Time.now,
|
||||
|
|
Loading…
Add table
Reference in a new issue