mirror of
https://gitlab.com/libvirt/libvirt-python.git
synced 2025-07-05 08:59:36 +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:
committed by
Daniel P. Berrangé
parent
53565fe096
commit
283e2bc693
@ -34,8 +34,9 @@ if len(sys.argv) != 2:
|
|||||||
name = sys.argv[1]
|
name = sys.argv[1]
|
||||||
|
|
||||||
# Connect to libvirt
|
# Connect to libvirt
|
||||||
conn = libvirt.openReadOnly(None)
|
try:
|
||||||
if conn is None:
|
conn = libvirt.openReadOnly(None)
|
||||||
|
except libvirt.libvirtError:
|
||||||
print('Failed to open connection to the hypervisor')
|
print('Failed to open connection to the hypervisor')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -20,8 +20,9 @@ if len(sys.argv) != 2:
|
|||||||
dir = sys.argv[1]
|
dir = sys.argv[1]
|
||||||
imgs = os.listdir(dir)
|
imgs = os.listdir(dir)
|
||||||
|
|
||||||
conn = libvirt.open(None)
|
try:
|
||||||
if conn is None:
|
conn = libvirt.open(None)
|
||||||
|
except libvirt.libvirtError:
|
||||||
print('Failed to open connection to the hypervisor')
|
print('Failed to open connection to the hypervisor')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -18,8 +18,9 @@ if len(sys.argv) != 2:
|
|||||||
|
|
||||||
dir = sys.argv[1]
|
dir = sys.argv[1]
|
||||||
|
|
||||||
conn = libvirt.open(None)
|
try:
|
||||||
if conn is None:
|
conn = libvirt.open(None)
|
||||||
|
except libvirt.libvirtError:
|
||||||
print('Failed to open connection to the hypervisor')
|
print('Failed to open connection to the hypervisor')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -32,8 +32,9 @@ if len(sys.argv) != 2:
|
|||||||
|
|
||||||
(name, xmldesc) = read_domain(sys.argv[1])
|
(name, xmldesc) = read_domain(sys.argv[1])
|
||||||
|
|
||||||
conn = libvirt.open(None)
|
try:
|
||||||
if conn is None:
|
conn = libvirt.open(None)
|
||||||
|
except libvirt.libvirtError:
|
||||||
print('Failed to open connection to the hypervisor')
|
print('Failed to open connection to the hypervisor')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -97,9 +97,9 @@ uri = "esx://%s/?no_verify=1" % hostname
|
|||||||
# in order to log into the vCenter
|
# in order to log into the vCenter
|
||||||
auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_NOECHOPROMPT],
|
auth = [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_NOECHOPROMPT],
|
||||||
request_credentials, None]
|
request_credentials, None]
|
||||||
conn = libvirt.openAuth(uri, auth, 0)
|
try:
|
||||||
|
conn = libvirt.openAuth(uri, auth, 0)
|
||||||
if conn is None:
|
except libvirt.libvirtError:
|
||||||
print("Failed to open connection to %s" % hostname)
|
print("Failed to open connection to %s" % hostname)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user