From e1401de974b6ac6d3e6e94e774f24a9b74f806f2 Mon Sep 17 00:00:00 2001 From: Daniel Erez Date: Thu, 5 Jul 2018 20:23:35 +0300 Subject: [PATCH] v2v: rhv plugin - find suitable host (RHBZ#1596810) (RHBZ#1596851) 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. (cherry picked from commit 4ed1bc5a79a77ad3a620b339f9ac2ecc8df6fd03) --- v2v/rhv-upload-plugin.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py index da309e288..931fcfaa2 100644 --- a/v2v/rhv-upload-plugin.py +++ b/v2v/rhv-upload-plugin.py @@ -69,14 +69,34 @@ def find_host(connection): debug("hw_id = %r" % vdsm_id) - hosts_service = connection.system_service().hosts_service() + 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). + debug("storange domain (%s) is not attached to a DC" % storage_name) + return None + + datacenter = data_centers[0] + debug("datacenter = %s" % datacenter.name) + + 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: - # This oVirt host is not registered with engine. - debug("cannot find host with hw_id=%r, using any host" % vdsm_id) + # Couldn't find a host that's fulfilling the following criteria: + # - 'hw_id' equals to 'vdsm_id' + # - Its status is 'Up' + # - Belongs to the storage domain's datacenter + debug("cannot find a running host with hw_id=%r, " \ + "that belongs to datacenter '%s', " \ + "using any host" % (vdsm_id, datacenter.name)) return None host = hosts[0] -- 2.20.1