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

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