Blame SOURCES/0068-v2v-rhv-plugin-find-suitable-host-RHBZ-1596810-RHBZ-.patch

e9bfca
From 39b3bdb8f3a430ac585ed75fa85f51bacebdf22e Mon Sep 17 00:00:00 2001
e9bfca
From: Daniel Erez <derez@redhat.com>
e9bfca
Date: Thu, 5 Jul 2018 20:23:35 +0300
e9bfca
Subject: [PATCH] v2v: rhv plugin - find suitable host (RHBZ#1596810)
e9bfca
 (RHBZ#1596851)
e9bfca
e9bfca
For direct upload, a suitable host must be in status 'Up'
e9bfca
and belong to the same datacenter as the created disk.
e9bfca
Added these criteria to the host search query.
e9bfca
e9bfca
(cherry picked from commit 4ed1bc5a79a77ad3a620b339f9ac2ecc8df6fd03)
e9bfca
---
e9bfca
 v2v/rhv-upload-plugin.py | 28 ++++++++++++++++++++++++----
e9bfca
 1 file changed, 24 insertions(+), 4 deletions(-)
e9bfca
e9bfca
diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py
e9bfca
index da309e288..931fcfaa2 100644
e9bfca
--- a/v2v/rhv-upload-plugin.py
e9bfca
+++ b/v2v/rhv-upload-plugin.py
e9bfca
@@ -69,14 +69,34 @@ def find_host(connection):
e9bfca
 
e9bfca
     debug("hw_id = %r" % vdsm_id)
e9bfca
 
e9bfca
-    hosts_service = connection.system_service().hosts_service()
e9bfca
+    system_service = connection.system_service()
e9bfca
+    storage_name = params['output_storage']
e9bfca
+    data_centers = system_service.data_centers_service().list(
e9bfca
+        search='storage=%s' % storage_name,
e9bfca
+        case_sensitive=False,
e9bfca
+    )
e9bfca
+    if len(data_centers) == 0:
e9bfca
+        # The storage domain is not attached to a datacenter
e9bfca
+        # (shouldn't happen, would fail on disk creation).
e9bfca
+        debug("storange domain (%s) is not attached to a DC" % storage_name)
e9bfca
+        return None
e9bfca
+
e9bfca
+    datacenter = data_centers[0]
e9bfca
+    debug("datacenter = %s" % datacenter.name)
e9bfca
+
e9bfca
+    hosts_service = system_service.hosts_service()
e9bfca
     hosts = hosts_service.list(
e9bfca
-        search="hw_id=%s" % vdsm_id,
e9bfca
+        search="hw_id=%s and datacenter=%s and status=Up" % (vdsm_id, datacenter.name),
e9bfca
         case_sensitive=False,
e9bfca
     )
e9bfca
     if len(hosts) == 0:
e9bfca
-        # This oVirt host is not registered with engine.
e9bfca
-        debug("cannot find host with hw_id=%r, using any host" % vdsm_id)
e9bfca
+        # Couldn't find a host that's fulfilling the following criteria:
e9bfca
+        # - 'hw_id' equals to 'vdsm_id'
e9bfca
+        # - Its status is 'Up'
e9bfca
+        # - Belongs to the storage domain's datacenter
e9bfca
+        debug("cannot find a running host with hw_id=%r, " \
e9bfca
+              "that belongs to datacenter '%s', " \
e9bfca
+              "using any host" % (vdsm_id, datacenter.name))
e9bfca
         return None
e9bfca
 
e9bfca
     host = hosts[0]
e9bfca
-- 
8ff76f
2.20.1
e9bfca