[Libguestfs] [PATCH v2 05/11] rhv-upload: Get host before creating disk

Nir Soffer nirsof at gmail.com
Mon Nov 18 21:53:44 UTC 2019


If getting the host object raised, we forgot to remove the disk. Getting
the host object before creating the disk avoids the error handling, and
will fail faster on errors, without waiting until the disk is ready.

This will help to extract the code for creating transfer out of open().
---
 v2v/rhv-upload-plugin.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py
index 11f18041..78e396aa 100644
--- a/v2v/rhv-upload-plugin.py
+++ b/v2v/rhv-upload-plugin.py
@@ -77,14 +77,15 @@ def open(readonly):
         insecure = params['insecure'],
     )
 
+    # Use the local host is possible.
+    host = find_host(connection) if params['rhv_direct'] else None
     disk = create_disk(connection)
 
     # Get a reference to the transfer service.
     system_service = connection.system_service()
     transfers_service = system_service.image_transfers_service()
 
-    # Create a new image transfer, using the local host is possible.
-    host = find_host(connection) if params['rhv_direct'] else None
+    # Create a new image transfer.
     transfer = transfers_service.add(
         types.ImageTransfer(
             disk = types.Disk(id = disk.id),
-- 
2.21.0





More information about the Libguestfs mailing list