第5章 Red Hat Satellite API の使用
本章では、Red Hat Satellite API を使用して各種タスクを実行する方法をさまざまな例を挙げて説明します。Satellite Server で API を使用するには、ポート 443 の HTTPS を、Capsule Server で API を使用するには、ポート 8443 の HTTPS を使用します。
スクリプト自体で、異なるポートの要件に対応することができます。たとえば、Ruby では Satellite および Capsule の URL を以下のように指定することができます。
url = 'https://satellite.example.com/api/v2/' capsule_url = 'https://capsule.example.com:8443/api/v2/' katello_url = 'https://satellite.example.com/katello/api/v2/'
url = 'https://satellite.example.com/api/v2/'
capsule_url = 'https://capsule.example.com:8443/api/v2/'
katello_url = 'https://satellite.example.com/katello/api/v2/'
ホストが Satellite Server または Capsule Server にサブスクライブしている場合は、/etc/rhsm/rhsm.conf の [server] セクションのポートエントリーをもとに、API へのアクセスに必要な、正しいポートを判断できます。これらの値を使用してスクリプトを完全に自動化し、使用するポートを検証する必要性をなくします。
本章では、curl を使用して API 要求を送信します。詳細は、「curl を使用した API 要求」 を参照してください。
本章の例では、Python json.tool モジュールを使用して出力をフォーマットしています。
5.1. ホストの使用方法 リンクのコピーリンクがクリップボードにコピーされました!
ホストのリスト
以下の例では、Satellite ホストのリストを返します。
要求例:
curl -request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts | python -m json.tool
$ curl -request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/api/v2/hosts | python -m json.tool
応答例:
ホストの情報要求
この要求は、satellite.example.com ホストの情報を返します。
要求例:
curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts/satellite.example.com \ | python -m json.tool
$ curl --request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/api/v2/hosts/satellite.example.com \
| python -m json.tool
応答例:
ホストのファクト表示
この要求は、satellite.example.com ホストの全ファクトを返します。
要求例:
curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts/satellite.example.com/facts \ | python -m json.tool
$ curl --request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/api/v2/hosts/satellite.example.com/facts \
| python -m json.tool
応答例:
パターンが一致するホストの検索
以下のクエリーは、「example」というパターンと一致するホストをすべて返します。
要求例:
curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts?search=example \ | python -m json.tool
$ curl --request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/api/v2/hosts?search=example \
| python -m json.tool
応答例:
環境でのホストの検索
以下のクエリーは、production 環境内の全ホストを返します。
要求例:
curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts?search=environment=production \ | python -m json.tool
$ curl --request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/api/v2/hosts?search=environment=production \
| python -m json.tool
応答例:
特定のファクト値を含むホストの検索
以下のクエリーでは、RHEV Hypervisor というモデル名のホストがすべて返されます。
要求例:
curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts?search=model=\"RHEV+Hypervisor\" \ | python -m json.tool
$ curl --request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/api/v2/hosts?search=model=\"RHEV+Hypervisor\" \
| python -m json.tool
応答例:
ホストの削除
この要求は、名前が host1.example.com のホストを削除します。
要求例:
curl --request DELETE --insecure --user sat_username:sat_password \ https://satellite.example.com/api/v2/hosts/host1.example.com \ | python -m json.tool
$ curl --request DELETE --insecure --user sat_username:sat_password \
https://satellite.example.com/api/v2/hosts/host1.example.com \
| python -m json.tool
完全な起動ディスクイメージのダウンロード
以下の要求では、ホストの完全な起動ディスクイメージを ID を使用してダウンロードします。
要求例:
curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/bootdisk/api/hosts/host_ID?full=true \ --output image.iso
$ curl --request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/bootdisk/api/hosts/host_ID?full=true \
--output image.iso