libvirt python API "lookupbyname()"を使用してドメインが存在するかどうかを確認しようとしています。ドメインが存在しない場合は、コンソールに "ドメインが見つかりません"というエラーメッセージが表示されます "。 syslogにのみエラーやログが必要です。私はstderrとstdoutをリダイレクトしようとしました。しかし、それは何の効果もありません。また、https://libvirt.org/logging.htmlに記載されているlibvirtロギングの設定を試してみました。もう一度効果はありません。 /etc/libvirt/qemu.confの "stdio_handler"フラグも "file"に設定されています。Libvirt Qemu python APIによるコンソール印刷の回避
以下は、私のテストコードです:
import os, sys
import libvirt
conn = libvirt.open('qemu:///system')
# Find the application in the virsh domain
try:
sys.stdout = open(os.devnull, "w")
sys.stderr = open(os.devnull, "w")
dom = conn.lookupByName('abcd')
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
except Exception as e:
syslog.syslog (syslog.LOG_ERR, 'Could not find the domain. ERROR: %s.' % (e))
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
出力:
$ python test.py
libvirt: QEMU Driver error : Domain not found: no domain with matching name 'abcd'
$
このコンソールのプリントを回避する方法はありますか?
私はネットワークルックアップやその他のlibvirt python APIに関して同様の問題を抱えていました。このような問題はすべて解決されます。ありがとうございました! – Swaru