Show Table of Contents
3.9. エラーの処理
エラーが発生した場合に、ソフトウェア開発キットは例外を使用してエラーを強調します。ソフトウェア開発キットは、Python インタープリター自体が定義したものに加え、例外タイプも定義します。これらの例外は、
ovirtsdk.infrastructure.errors モジュールにあります。
- ConnectionError
- トランスポート層エラーが発生した場合に送出されます。
- DisconnectedError
- SDK が明示的に切断された後に使用を試みた場合に送出されます。
- ImmutableError
- 同じドメイン下に SDK インスタンスがすでに存在している間に SDK の開始を試みた場合に送出されます。SDK 3.2 以降のバージョンに適用されます。
- NoCertificatesError
- CA が提供されず、--insecure が 'False' に指定されている場合に送出されます。
- RequestError
- あらゆる種類の oVirt サーバーエラーが発生した場合に送出されます。
- UnsecuredConnectionAttemptError
- サーバーが HTTPS を実行中に HTTP プロトコルが使用された場合に送出されます。
- MissingParametersError
- ID または名前のいずれも提供せずに get() メソッドの使用を試みた場合に送出されます。
これらの例外は、他の Python 例外と同様にキャッチおよび処理できます。
例3.9 ConnectionError 例外のキャッチ
from ovirtsdk.api import API
from ovirtsdk.xml import params
try:
api = API(url="https://HOST",
user="USER,
pass="PASS,
ca_file="/etc/pki/ovirt-engine/ca.pem")
except ConnectionError, err:
print "Connection failed: %s" % err
Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.