Sha256: 877dde4e8b89e921f3837d969177909425dff2ef9d704fcaa0e661f41f20fb49

Contents?: true

Size: 806 Bytes

Versions: 11

Compression:

Stored size: 806 Bytes

Contents

module Fog
  module Libvirt
    class Compute
      class Real
        def upload_volume(pool_name, volume_name, file_path)
          volume = client.lookup_storage_pool_by_name(pool_name).lookup_volume_by_name(volume_name)
          stream = client.stream

          image_file = File.open(file_path, "rb")
          volume.upload(stream, 0, image_file.size)
          stream.sendall do |_opaque, n|
            begin
              r = image_file.read(n)
              r ? [r.length, r] : [0, ""]
            rescue Exception => e
              [-1, ""]
            end
          end
          stream.finish
        ensure
          image_file.close if image_file
        end
      end

      class Mock
        def upload_volume(pool_name, volume_name, file_path)
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
fog-libvirt-0.12.2 lib/fog/libvirt/requests/compute/upload_volume.rb
fog-libvirt-0.12.1 lib/fog/libvirt/requests/compute/upload_volume.rb
fog-libvirt-0.12.0 lib/fog/libvirt/requests/compute/upload_volume.rb
fog-libvirt-0.11.0 lib/fog/libvirt/requests/compute/upload_volume.rb
fog-libvirt-0.10.1 lib/fog/libvirt/requests/compute/upload_volume.rb
fog-libvirt-0.10.0 lib/fog/libvirt/requests/compute/upload_volume.rb
fog-libvirt-csem-0.9.0 lib/fog/libvirt/requests/compute/upload_volume.rb
fog-libvirt-0.9.0 lib/fog/libvirt/requests/compute/upload_volume.rb
fog-libvirt-0.8.0 lib/fog/libvirt/requests/compute/upload_volume.rb
fog-libvirt-0.7.0 lib/fog/libvirt/requests/compute/upload_volume.rb
fog-libvirt-0.6.0 lib/fog/libvirt/requests/compute/upload_volume.rb