Show Table of Contents
2.2. 例: Python を使用した API エントリーポイントへのアクセス
ovirtsdk Python ライブラリーは、API のエントリーポイントとして機能する
API クラスを提供します。
例2.1 Python を使用した API エントリーポイントへのアクセス
以下の Python の例は、
rhevm.demo.redhat.com で Red Hat Virtualization Manager によって提供される REST API のインスタンスに接続します。以下の例では、API クラスのインスタンスを作成して接続します。接続が成功した場合には、メッセージが表示されます。最後に、API クラスの disconnect() メソッドが呼び出されて接続が終了します。
この例で
API クラスのコンストラクターに以下のパラメーターを提供します。
- 接続する Manager の
url - 認証するユーザーの
username - 認証するユーザーの
username - 証明書へのパスである
ca_file。証明書は、Manager の認証局用コピーであることが想定されます。これは、https://[engine-fqdn]ovirt-engine/services/pki-resource?resource=ca-certificate&format=X509-PEM-CAから取得できます。
API クラスのコンストラクターは、他のパラメーターをサポートしますが、以下の例では、必須パラメーターのみを指定しています。
from ovirtsdk.api import API
from ovirtsdk.xml import params
try:
api = API (url="https://HOST",
username="USER@DOMAIN",
password="PASS",
ca_file="ca.crt")
print "Connected to %s successfully!" % api.get_product_info().name
api.disconnect()
except Exception as ex:
print "Unexpected error: %s" % ex
接続試行が成功した場合には、次の例のような出力が表示されます。
Connected to Red Hat Virtualization Manager successfully!

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.