summaryrefslogtreecommitdiff
path: root/examples/esxlist.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/esxlist.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/esxlist.py')
-rwxr-xr-xexamples/esxlist.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/examples/esxlist.py b/examples/esxlist.py
index d86e064..caeced1 100755
--- a/examples/esxlist.py
+++ b/examples/esxlist.py
@@ -97,9 +97,9 @@ uri = "esx://%s/?no_verify=1" % hostname
# in order to log into the vCenter
auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_NOECHOPROMPT],
request_credentials, None]
-conn = libvirt.openAuth(uri, auth, 0)
-
-if conn is None:
+try:
+ conn = libvirt.openAuth(uri, auth, 0)
+except libvirt.libvirtError:
print("Failed to open connection to %s" % hostname)
sys.exit(1)