[PATCH libvirt-python] examples: Fix connection error handling 2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Fix two more cases in examples as
libvirt.open*() does not return None but raises an exception

Fixes: 283e2bc693746164b22226e14d6fe3ccd38a07bf
Signed-off-by: Philipp Hahn <hahn@xxxxxxxxxxxxx>
---
 examples/dhcpleases.py | 5 +++--
 examples/domipaddrs.py | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/examples/dhcpleases.py b/examples/dhcpleases.py
index f394541..6f80fd5 100755
--- a/examples/dhcpleases.py
+++ b/examples/dhcpleases.py
@@ -22,8 +22,9 @@ else:
     usage()
     sys.exit(2)
 
-conn = libvirt.open(uri)
-if conn == None:
+try:
+    conn = libvirt.open(uri)
+except libvirt.libvirtError:
     print("Unable to open connection to libvirt")
     sys.exit(1)
 
diff --git a/examples/domipaddrs.py b/examples/domipaddrs.py
index bda308c..e893995 100755
--- a/examples/domipaddrs.py
+++ b/examples/domipaddrs.py
@@ -21,8 +21,9 @@ else:
     usage()
     sys.exit(2)
 
-conn = libvirt.open(uri)
-if conn == None:
+try:
+    conn = libvirt.open(uri)
+except libvirt.libvirtError:
     print "Unable to open connection to libvirt"
     sys.exit(1)
 
-- 
2.20.1






[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux