From nobody Mon May 6 07:24:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1587362729; cv=none; d=zohomail.com; s=zohoarc; b=AjU8ScShTFdyQqUTU7y91bUaXZE3tn8Ybf6W/eEUYKDt/R1kKYzMdJGvRy6emZ4pB4AcTZtS8yAwBXSntknHUwq0rJdPxaXSxKXgo/3Hw+/dd7JYZrtbMopoSw6A1D0S1rSHOHFR/5/vpor81xIitZpKGSocSmQAxN3wT7jKg3k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587362729; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=YCT4nlCxDik/9BJPsr8ehEcdcL6t0BvTuuXljOecAr4=; b=fkwXGZsIh793FyPGVg1jgZeLSy0jXsYoMWc/6zmgCDbvCtadEJbpecp6DM9l0lnoFRonhqozOgXnuveiv4OhI+WVku+mDol75woY+csz6VVHQKjrVP46O3c+zuzChDSYYwgNu0K2/r2HvDXf/RlSpGitbyK+WCAne5vpZEJLiy4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1587362729003318.5367159213648; Sun, 19 Apr 2020 23:05:29 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-118-v2ecsmhmPUSEUjtpnhEn_Q-1; Mon, 20 Apr 2020 02:05:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A2387801E53; Mon, 20 Apr 2020 06:05:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 466445E001; Mon, 20 Apr 2020 06:05:19 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B356A18089C8; Mon, 20 Apr 2020 06:05:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 03K65IIR025168 for ; Mon, 20 Apr 2020 02:05:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id 06755110F0C3; Mon, 20 Apr 2020 06:05:18 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 01E08110F0C2 for ; Mon, 20 Apr 2020 06:05:16 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 11A86185A78F for ; Mon, 20 Apr 2020 06:05:16 +0000 (UTC) Received: from mail.univention.de (mail.univention.de [82.198.197.8]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-162-p2rg_jt9OwmtLwnOknJJAQ-1; Mon, 20 Apr 2020 02:05:12 -0400 Received: from localhost (localhost [127.0.0.1]) by solig.knut.univention.de (Postfix) with ESMTP id 8A9848E321E3 for ; Mon, 20 Apr 2020 08:05:11 +0200 (CEST) Received: from mail.univention.de ([127.0.0.1]) by localhost (solig.knut.univention.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0Hny7xwnThEA; Mon, 20 Apr 2020 08:05:01 +0200 (CEST) Received: from fixa.knut.univention.de (p5B21E7E0.dip0.t-ipconnect.de [91.33.231.224]) by solig.knut.univention.de (Postfix) with ESMTPSA id 7FFA38E321CD; Mon, 20 Apr 2020 08:05:01 +0200 (CEST) Received: by fixa.knut.univention.de (Postfix, from userid 2260) id CAA3115F6A7; Mon, 20 Apr 2020 08:05:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587362727; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=YCT4nlCxDik/9BJPsr8ehEcdcL6t0BvTuuXljOecAr4=; b=hw1x347dFtLzoc6jo7N2APo7pyd90s79gO6LwEl/GSeVN4pB2a7xt8uuFFYqRaccNKjgVa MKphq7hyX7/7NIh/ElrOu06/BCsnebW+rdXDNpTIBqdBqZ4O0y5EX0wsSgLDL/iwCUJanF 2LLA0GcXOliisiq8Lm3gqs/M9HDWAP8= X-MC-Unique: v2ecsmhmPUSEUjtpnhEn_Q-1 X-MC-Unique: p2rg_jt9OwmtLwnOknJJAQ-1 X-Virus-Scanned: by amavisd-new-2.10.1 (20141025) (Debian) at knut.univention.de From: Philipp Hahn To: libvir-list@redhat.com Subject: [PATCH libvirt-python] examples: Fix connection error handling Date: Mon, 20 Apr 2020 08:05:00 +0200 Message-Id: <2bc470d077156f9e23b6872d17eaa2791c6ec028.1587362695.git.hahn@univention.de> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 03K65IIR025168 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" libvirt.open*() does not return None but raises an exception Signed-off-by: Philipp Hahn Reviewed-by: Daniel P. Berrang=C3=A9 --- examples/dominfo.py | 5 +++-- examples/domrestore.py | 5 +++-- examples/domsave.py | 5 +++-- examples/domstart.py | 5 +++-- examples/esxlist.py | 6 +++--- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/examples/dominfo.py b/examples/dominfo.py index 0a39f4c..fcfb8ed 100755 --- a/examples/dominfo.py +++ b/examples/dominfo.py @@ -34,8 +34,9 @@ if len(sys.argv) !=3D 2: name =3D sys.argv[1] =20 # Connect to libvirt -conn =3D libvirt.openReadOnly(None) -if conn is None: +try: + conn =3D libvirt.openReadOnly(None) +except libvirt.libvirtError: print('Failed to open connection to the hypervisor') sys.exit(1) =20 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) !=3D 2: dir =3D sys.argv[1] imgs =3D os.listdir(dir) =20 -conn =3D libvirt.open(None) -if conn is None: +try: + conn =3D libvirt.open(None) +except libvirt.libvirtError: print('Failed to open connection to the hypervisor') sys.exit(1) =20 diff --git a/examples/domsave.py b/examples/domsave.py index 4940cce..f8922d6 100755 --- a/examples/domsave.py +++ b/examples/domsave.py @@ -18,8 +18,9 @@ if len(sys.argv) !=3D 2: =20 dir =3D sys.argv[1] =20 -conn =3D libvirt.open(None) -if conn is None: +try: + conn =3D libvirt.open(None) +except libvirt.libvirtError: print('Failed to open connection to the hypervisor') sys.exit(1) =20 diff --git a/examples/domstart.py b/examples/domstart.py index 7ff6cb9..f342e95 100755 --- a/examples/domstart.py +++ b/examples/domstart.py @@ -32,8 +32,9 @@ if len(sys.argv) !=3D 2: =20 (name, xmldesc) =3D read_domain(sys.argv[1]) =20 -conn =3D libvirt.open(None) -if conn is None: +try: + conn =3D libvirt.open(None) +except libvirt.libvirtError: print('Failed to open connection to the hypervisor') sys.exit(1) =20 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 =3D "esx://%s/?no_verify=3D1" % hostname # in order to log into the vCenter auth =3D [[libvirt.VIR_CRED_AUTHNAME, libvirt.VIR_CRED_NOECHOPROMPT], request_credentials, None] -conn =3D libvirt.openAuth(uri, auth, 0) - -if conn is None: +try: + conn =3D libvirt.openAuth(uri, auth, 0) +except libvirt.libvirtError: print("Failed to open connection to %s" % hostname) sys.exit(1) =20 --=20 2.20.1