Class: Kitchen::Driver::Openstack::Volume
- Inherits:
-
Object
- Object
- Kitchen::Driver::Openstack::Volume
- Defined in:
- lib/kitchen/driver/openstack/volume.rb
Overview
A class to allow the Kitchen Openstack driver to use Openstack volumes
Constant Summary collapse
- @@default_creation_timeout =
60
Instance Method Summary collapse
- #create_volume(config, os) ⇒ Object
- #get_bdm(config, os) ⇒ Object
-
#initialize(logger) ⇒ Volume
constructor
A new instance of Volume.
- #volume(openstack_server) ⇒ Object
Constructor Details
#initialize(logger) ⇒ Volume
Returns a new instance of Volume.
33 34 35 |
# File 'lib/kitchen/driver/openstack/volume.rb', line 33 def initialize(logger) @logger = logger end |
Instance Method Details
#create_volume(config, os) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/kitchen/driver/openstack/volume.rb', line 41 def create_volume(config, os) opt = {} bdm = config[:block_device_mapping] = i{snapshot_id imageRef volume_type source_volid availability_zone} .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) ⇒ Object
88 89 90 91 92 93 94 |
# 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) ⇒ Object
37 38 39 |
# File 'lib/kitchen/driver/openstack/volume.rb', line 37 def volume(openstack_server) Fog::OpenStack::Volume.new(openstack_server) end |