1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2025-07-04 04:59:37 +03:00

examples: Fix connection error handling

libvirt.open*() does not return None but raises an exception

Signed-off-by: Philipp Hahn <hahn@univention.de>
This commit is contained in:
Philipp Hahn
2020-04-20 08:05:00 +02:00
committed by Daniel P. Berrangé
parent 53565fe096
commit 283e2bc693
5 changed files with 15 additions and 11 deletions

View File

@ -34,8 +34,9 @@ if len(sys.argv) != 2:
name = sys.argv[1]
# Connect to libvirt
conn = libvirt.openReadOnly(None)
if conn is None:
try:
conn = libvirt.openReadOnly(None)
except libvirt.libvirtError:
print('Failed to open connection to the hypervisor')
sys.exit(1)