[Libguestfs] [PATCH] v2v: rhv plugin - find suitable host

Daniel Erez derez at redhat.com
Thu Jul 5 07:46:17 UTC 2018


From: root <root at localhost.localdomain>

For direct upload, a suitable host must be in status 'Up'
and belong to the same datacenter as the created disk.
Added these criteria to the host search query.
---
 v2v/rhv-upload-plugin.py | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py
index da309e288..c72f5e181 100644
--- a/v2v/rhv-upload-plugin.py
+++ b/v2v/rhv-upload-plugin.py
@@ -67,11 +67,23 @@ def find_host(connection):
         debug("cannot read /etc/vdsm/vdsm.id, using any host: %s" % e)
         return None
 
-    debug("hw_id = %r" % vdsm_id)
+    system_service = connection.system_service()
+    storage_name = params['output_storage']
+    data_centers = system_service.data_centers_service().list(
+        search='storage=%s' % storage_name,
+        case_sensitive=False,
+    )
+    if len(data_centers) == 0:
+        # The storage domain is not attached to a datacenter
+        # (shouldn't happen, would fail on disk creation).
+        return None
+
+    datacenter = data_centers[0]
+    debug("hw_id = %r, datacenter = %s" % (vdsm_id, datacenter.name))
 
-    hosts_service = connection.system_service().hosts_service()
+    hosts_service = system_service.hosts_service()
     hosts = hosts_service.list(
-        search="hw_id=%s" % vdsm_id,
+        search="hw_id=%s and datacenter=%s and status=Up" % (vdsm_id, datacenter.name),
         case_sensitive=False,
     )
     if len(hosts) == 0:
-- 
2.17.1




More information about the Libguestfs mailing list