On 8/6/20 5:54 PM, Nir Soffer wrote:
This is mainly for testing the new parallel python threading model, but it also an example how to manage multiple connection from a plugin.
I tested this with local imageio server, serving qcow2 image on local SSD.
diff --git a/plugins/python/examples/imageio.py b/plugins/python/examples/imageio.py new file mode 100644 index 00000000..e77fd2f4 --- /dev/null +++ b/plugins/python/examples/imageio.py @@ -0,0 +1,167 @@ +# Example Python plugin. +# +# This example can be freely used for any purpose. +# +# Upload and download images to oVirt with nbdkit and qemu-img. +# +# Install ovirt-imageio-client +# +# dnf copr enable nsoffer/ovirt-imageio-preview +# dnf install ovirt-imageio-client
Even after running these steps,...
+# +# To upload or download images, you need to start an image transfer. The +# easiest way is using oVirt image_transfer.py example: +# +# /usr/share/doc/python3-ovirt-enigne-sdk4/eamples/image_transfer.py \
...I do not have a /usr/share/doc/python3-ovirt-* directory at all. Where am I supposed to get it from? Also, I suspect you want s/enigne/engine/; s/eamples/examples/
+# --engine-url https://my.engine \ +# --username admin@internal \ +# --password-file password \ +# --cafile my.engine.pem \ +# upload disk-uuid +# +# This will print the trasnfer URL for this image transfer.
s/trasnfer/transfer/
+# +# Run this example from the build directory: +# +# ./nbdkit -t4 -f -v -U /tmp/nbd.sock -t4 python \
-t4 does not need to be listed twice.
+# ./plugins/python/examples/imageio.py \ +# transfer_url=https://server:54322/images/ticket-id \ +# connections=4 \ +# secure=no +# +# Note that number of nbdkit threads and imageio connections should match. +# +# To upload an image run: +# +# qemu-img convert -f qcow2 -O raw disk.img nbd:///?socket=tmp/nbd.sock
URIs containing ? should be shell-quoted (in the unlikely case that someone has an 'nbd:' subdirectory that could interfere with shell globbing).
+# +# Downloading image is not efficient with this version, since we don't report +# extents yet.
I'll push the obvious typo fixes.
+ +def boolify(key, value): + v = value.lower() + if v in ("yes", "true", "1"): + return True + if v in ("no", "false", 0): + return False + raise RuntimeError("Invalid boolean value for {}: {!r}".format(key, value))
nbdkit_parse_bool also handles 'on/off'. Should we make that function more easily available to python plugins, so you aren't having to reimplement it yourself?
+ + +def config_complete(): + """ + Called when configuration completed.
missing 'is' -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org