[Kimchi-devel] [PATCH] [Kimchi 3/3] Adding libvirt remote connection verification

dhbarboza82 at gmail.com dhbarboza82 at gmail.com
Tue Oct 11 15:49:49 UTC 2016


From: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>

Depending on the remote libvirt configuration, setting a password-less
login between the hosts isn't enough to ensure a password-less API
connection to the remote libvirt service.

This patch adds a virsh verification to ensure that this password-less
connection can be estabished before moving further with the live
migration process. If the verification fails, a proper error message
is given to warn the user about the need of making a manual configuration
in the libvirt service of the remote host.

Signed-off-by: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
---
 i18n.py      |  1 +
 model/vms.py | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/i18n.py b/i18n.py
index 35a147c..814a8d9 100644
--- a/i18n.py
+++ b/i18n.py
@@ -140,6 +140,7 @@ messages = {
     "KCHVM0087E": _("console parameter is only supported for s390x/s390 architecture."),
     "KCHVM0088E": _("invalid console type, supported types are sclp/virtio."),
     "KCHVM0089E": _("Unable to setup password-less login at remote host %(host)s using user %(user)s: remote directory %(sshdir)s does not exist."),
+    "KCHVM0090E": _("Unable to create a password-less libvirt connection to the remote libvirt daemon at host %(host)s with the user %(user)s. Please verify the remote server libvirt configuration. More information: http://libvirt.org/auth.html ."),
 
     "KCHVMHDEV0001E": _("VM %(vmid)s does not contain directly assigned host device %(dev_name)s."),
     "KCHVMHDEV0002E": _("The host device %(dev_name)s is not allowed to directly assign to VM."),
diff --git a/model/vms.py b/model/vms.py
index b702fe1..79660a4 100644
--- a/model/vms.py
+++ b/model/vms.py
@@ -25,6 +25,7 @@ import paramiko
 import platform
 import pwd
 import random
+import signal
 import socket
 import subprocess
 import string
@@ -1841,6 +1842,22 @@ class VMModel(object):
             if ssh_client:
                 ssh_client.close()
 
+    def _check_remote_libvirt_conn(self, remote_host,
+                                   user='root', transport='ssh'):
+
+        dest_uri = 'qemu+%s://%s@%s/system' % (transport, user, remote_host)
+        cmd = ['virsh', '-c', dest_uri, 'list']
+        proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+                                shell=True, preexec_fn=os.setsid)
+        timeout = 0
+        while proc.poll() is None:
+            time.sleep(1)
+            timeout += 1
+            if timeout == 5:
+                os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
+                raise OperationFailed("KCHVM0090E",
+                                      {'host': remote_host, 'user': user})
+
     def _get_remote_libvirt_conn(self, remote_host,
                                  user='root', transport='ssh'):
         dest_uri = 'qemu+%s://%s@%s/system' % (transport, user, remote_host)
@@ -1854,6 +1871,7 @@ class VMModel(object):
             user,
             password
         )
+        self._check_remote_libvirt_conn(remote_host, user)
         self._check_if_migrating_same_arch_hypervisor(remote_host, user)
 
         if platform.machine() in ['ppc64', 'ppc64le']:
-- 
2.7.4




More information about the Kimchi-devel mailing list