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

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