class Kitchen::Driver::Openstack::Volume
A class to allow the Kitchen
Openstack
driver to use Openstack
volumes
@author Liam Haworth <liam.haworth@bluereef.com.au>
Public Class Methods
new(logger)
click to toggle source
# File lib/kitchen/driver/openstack/volume.rb, line 33 def initialize(logger) @logger = logger end
Public Instance Methods
create_volume(config, os)
click to toggle source
# File lib/kitchen/driver/openstack/volume.rb, line 41 def create_volume(config, os) opt = {} bdm = config[:block_device_mapping] vanilla_options = %i{snapshot_id imageRef volume_type source_volid availability_zone} vanilla_options.select { |o| bdm[o] }.each do |key| opt[key] = bdm[key] end @logger.info "Creating Volume..." resp = volume(os) .create_volume( "#{config[:server_name]}-volume", "#{config[:server_name]} volume", bdm[:volume_size], opt ) vol_id = resp[:body]["volume"]["id"] # Get Volume Model to make waiting for ready easy vol_model = volume(os).volumes.first { |x| x.id == vol_id } # Use default creation timeout or user supplied creation_timeout = @@default_creation_timeout if bdm.key?(:creation_timeout) creation_timeout = bdm[:creation_timeout] end @logger.debug "Waiting for volume to be ready for #{creation_timeout} seconds" vol_model.wait_for(creation_timeout) do sleep(1) raise("Failed to make volume") if status.casecmp("error".downcase) == 0 ready? end attach_timeout = bdm.key?(:attach_timeout) ? bdm[:attach_timeout] : 0 if attach_timeout > 0 @logger.debug "Sleeping for an additional #{attach_timeout} seconds before attaching volume to wait for Openstack to finish disk creation process.." sleep(attach_timeout) end @logger.debug "Volume Ready" vol_id end
get_bdm(config, os)
click to toggle source
# File lib/kitchen/driver/openstack/volume.rb, line 88 def get_bdm(config, os) bdm = config[:block_device_mapping] bdm[:volume_id] = create_volume(config, os) if bdm[:make_volume] bdm.delete_if { |k, _| k == :make_volume } bdm.delete_if { |k, _| k == :snapshot_id } bdm end
volume(openstack_server)
click to toggle source
# File lib/kitchen/driver/openstack/volume.rb, line 37 def volume(openstack_server) Fog::OpenStack::Volume.new(openstack_server) end