summaryrefslogtreecommitdiff
path: root/examples/domrestore.py
diff options
context:
space:
mode:
authorPhilipp Hahn <hahn@univention.de>2020-04-20 08:05:00 +0200
committerDaniel P. Berrangé <berrange@redhat.com>2020-04-20 13:21:55 +0100
commit283e2bc693746164b22226e14d6fe3ccd38a07bf (patch)
tree1015159551acea6406a64bcff38b821925807a3e /examples/domrestore.py
parent53565fe096d9f91cf06ed2100d252a7c62939a71 (diff)
downloadlibvirt-python-283e2bc693746164b22226e14d6fe3ccd38a07bf.tar.gz
examples: Fix connection error handling
libvirt.open*() does not return None but raises an exception Signed-off-by: Philipp Hahn <hahn@univention.de>
Diffstat (limited to 'examples/domrestore.py')
-rwxr-xr-xexamples/domrestore.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/examples/domrestore.py b/examples/domrestore.py
index 96f4955..7fd5c8e 100755
--- a/examples/domrestore.py
+++ b/examples/domrestore.py
@@ -20,8 +20,9 @@ if len(sys.argv) != 2:
dir = sys.argv[1]
imgs = os.listdir(dir)
-conn = libvirt.open(None)
-if conn is None:
+try:
+ conn = libvirt.open(None)
+except libvirt.libvirtError:
print('Failed to open connection to the hypervisor')
sys.exit(1)