diff options
author | Philipp Hahn <hahn@univention.de> | 2020-04-20 08:05:00 +0200 |
---|---|---|
committer | Daniel P. Berrangé <berrange@redhat.com> | 2020-04-20 13:21:55 +0100 |
commit | 283e2bc693746164b22226e14d6fe3ccd38a07bf (patch) | |
tree | 1015159551acea6406a64bcff38b821925807a3e /examples/esxlist.py | |
parent | 53565fe096d9f91cf06ed2100d252a7c62939a71 (diff) | |
download | libvirt-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-x | examples/esxlist.py | 6 |
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) |