[libvirt] [ruby-libvirt 1/2] Add .gitignore

--- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f033dcf --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +ext/libvirt/extconf.h +ext/libvirt/_libvirt.so +ext/libvirt/Makefile +ext/libvirt/mkmf.log +*.o +*~ -- 2.8.1

--- examples/upload_volume.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 examples/upload_volume.rb diff --git a/examples/upload_volume.rb b/examples/upload_volume.rb new file mode 100644 index 0000000..a051d46 --- /dev/null +++ b/examples/upload_volume.rb @@ -0,0 +1,36 @@ +require 'libvirt' + +abort("No file to upload given") unless ARGV.length > 0 + +file_path = ARGV[0] + +c = Libvirt::open("qemu:///system") + +vol_xml = <<EOF +<volume> + <name>#{File.basename(file_path)}</name> + <allocation unit="G">0</allocation> + <capacity unit="b">#{File.size(file_path)}</capacity> +</volume> +EOF + +pool = c.lookup_storage_pool_by_name("default") +volume = pool.create_volume_xml(vol_xml) +stream = c.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) + # This works with and without 03f18670c79e6664fb424d6731f95ea2be4531f4 + r ? [r.length, r] : [0, ""] + # This works with 03f18670c79e6664fb424d6731f95ea2be4531f4 and matches the + # docs + r ? [0, r] : [0, ""] + rescue Exception => e + $stderr.puts "Got exception #{e}" + [-1, ""] + end +end +stream.finish -- 2.8.1

On Sun, Jun 12, 2016 at 7:33 AM, Guido Günther <agx@sigxcpu.org> wrote:
--- examples/upload_volume.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 examples/upload_volume.rb
That example is great, thanks. I cleaned it up a little bit, moved it into doc/site/examples, and added some comments. Thanks again! Chris
participants (2)
-
Chris Lalancette
-
Guido Günther