<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Thu, Jun 14, 2018 at 9:16 PM Nir Soffer <<a href="mailto:nirsof@gmail.com">nirsof@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">When sending request with small or no payload, it is simpler and<br>
possibly more efficient to use the high level HTTPSConnection.request(),<br>
instead of the lower level APIs.<br>
<br>
The only reason to use the lower level APIs is to avoid copying the<br>
payload, or on python 2, to use a bigger buffer size when streaming a<br>
file-like object.<br>
---<br>
 v2v/rhv-upload-plugin.py | 35 ++++++++++++++++-------------------<br>
 1 file changed, 16 insertions(+), 19 deletions(-)<br>
<br>
diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py<br>
index ed99cc7a9..3fad865f6 100644<br>
--- a/v2v/rhv-upload-plugin.py<br>
+++ b/v2v/rhv-upload-plugin.py<br>
@@ -263,12 +263,12 @@ def pread(h, count, offset):<br>
     transfer = h['transfer']<br>
     transfer_service = h['transfer_service']<br>
<br>
-    http.putrequest("GET", h['path'])<br>
+    headers = {"Range", "bytes=%d-%d" % (offset, offset+count-1)}<br>
     # Authorization is only needed for old imageio.<br>
     if h['needs_auth']:<br>
-        http.putheader("Authorization", transfer.signed_ticket)<br>
-    http.putheader("Range", "bytes=%d-%d" % (offset, offset+count-1))<br>
-    http.endheaders()<br>
+        headers["Authorization"] = transfer.signed_ticket<br>
+<br>
+    http.request("GET", h['path'], headers=headers)<br>
<br>
     r = http.getresponse()<br>
     # 206 = HTTP Partial Content.<br>
@@ -319,11 +319,10 @@ def zero(h, count, offset, may_trim):<br>
                       'size': count,<br>
                       'flush': False}).encode()<br>
<br>
-    http.putrequest("PATCH", h['path'])<br>
-    http.putheader("Content-Type", "application/json")<br>
-    http.putheader("Content-Length", len(buf))<br>
-    http.endheaders()<br>
-    http.send(buf)<br>
+    headers = {"Content-Type": "application/json",<br>
+               "Content-Length", str(len(buf))}<br>
+<br>
+    http.request("PATCH", h['path'], body=buf, headers=headers)<br>
<br>
     r = http.getresponse()<br>
     if r.status != 200:<br>
@@ -368,11 +367,10 @@ def trim(h, count, offset):<br>
                       'size': count,<br>
                       'flush': False}).encode()<br>
<br>
-    http.putrequest("PATCH", h['path'])<br>
-    http.putheader("Content-Type", "application/json")<br>
-    http.putheader("Content-Length", len(buf))<br>
-    http.endheaders()<br>
-    http.send(buf)<br>
+    headers = {"Content-Type": "application/json",<br>
+               "Content-Length", str(len(buf))}<br>
+<br>
+    http.request("PATCH", h['path'], body=buf, headers=headers)<br>
<br>
     r = http.getresponse()<br>
     if r.status != 200:<br>
@@ -387,11 +385,10 @@ def flush(h):<br>
     # Construct the JSON request for flushing.<br>
     buf = json.dumps({'op': "flush"}).encode()<br>
<br>
-    http.putrequest("PATCH", h['path'])<br>
-    http.putheader("Content-Type", "application/json")<br>
-    http.putheader("Content-Length", len(buf))<br>
-    http.endheaders()<br>
-    http.send(buf)<br>
+    headers = {"Content-Type": "application/json",<br>
+               "Content-Length", str(len(buf))}<br>
+<br>
+    http.request("PATCH", h['path'], body=buf, headers=headers)<br>
<br>
     r = http.getresponse()<br>
     if r.status != 200:<br>
-- <br>
2.17.1<br></blockquote><div><br></div><div>WARNING: this is not tested, but I tested similar code here:</div><div><a href="https://github.com/oVirt/ovirt-imageio/blob/master/examples/upload">https://github.com/oVirt/ovirt-imageio/blob/master/examples/upload</a><br></div><div>(which need the same change).</div><div><br></div><div>Do we have an easy way to test the plugin without running the entire</div><div>virt-v2v pipeline?</div><div><br></div><div>Ideally, a way to run nbdkit with the plugin against an existing ovirt</div><div>system, and then use qemu-img to convert a file to the nbdkit nbd socket.</div><div><br></div><div>Nir</div></div></div>