第6章 API チートシート
Red Hat Satellite API を使用してさまざまなタスクを実行する方法については、次の例を参照してください。ポート 443 の HTTPS 経由で Satellite Server 上の API を使用できます。
たとえば、Ruby では、Satellite Server の URL を次のように指定できます。
url = 'https://satellite.example.com/api/v2/' katello_url = 'https://satellite.example.com/katello/api/v2/'
url = 'https://satellite.example.com/api/v2/'
katello_url = 'https://satellite.example.com/katello/api/v2/'
これらの値を使用してスクリプトを完全に自動化し、使用するポートを検証する必要性をなくします。
次の例では、API リクエストの送信に curl を使用します。詳細は、「curl での API の呼び出し」 を参照してください。
6.1. ホストの使用方法 リンクのコピーリンクがクリップボードにコピーされました!
ホストのリスト表示
以下の例では、Satellite ホストのリストを返します。
要求例:
curl --request GET --user My_User_Name:My_Password \ https://satellite.example.com/api/v2/hosts | python3 -m json.tool
$ curl --request GET --user My_User_Name:My_Password \
https://satellite.example.com/api/v2/hosts | python3 -m json.tool
応答例:
ホストの情報要求
この要求は、satellite.example.com ホストの情報を返します。
要求例:
curl --request GET --user My_User_Name:My_Password \ https://satellite.example.com/api/v2/hosts/satellite.example.com \ | python3 -m json.tool
$ curl --request GET --user My_User_Name:My_Password \
https://satellite.example.com/api/v2/hosts/satellite.example.com \
| python3 -m json.tool
応答例:
ホストのファクト表示
この要求は、satellite.example.com ホストの全ファクトを返します。
要求例:
curl --request GET --user My_User_Name:My_Password \ https://satellite.example.com/api/v2/hosts/satellite.example.com/facts \ | python3 -m json.tool
$ curl --request GET --user My_User_Name:My_Password \
https://satellite.example.com/api/v2/hosts/satellite.example.com/facts \
| python3 -m json.tool
応答例:
パターンが一致するホストの検索
以下のクエリーは、"example" というパターンと一致するホストをすべて返します。
要求例:
curl --request GET --user My_User_Name:My_Password \ https://satellite.example.com/api/v2/hosts?search=example \ | python3 -m json.tool
$ curl --request GET --user My_User_Name:My_Password \
https://satellite.example.com/api/v2/hosts?search=example \
| python3 -m json.tool
応答例:
環境でのホストの検索
以下のクエリーは、production 環境内の全ホストを返します。
要求例:
curl --request GET --user My_User_Name:My_Password \ https://satellite.example.com/api/v2/hosts?search=environment=production \ | python3 -m json.tool
$ curl --request GET --user My_User_Name:My_Password \
https://satellite.example.com/api/v2/hosts?search=environment=production \
| python3 -m json.tool
応答例:
特定のファクト値を含むホストの検索
以下のクエリーでは、RHV Hypervisor というモデル名のホストがすべて返されます。
要求例:
curl --request GET --user My_User_Name:My_Password \ https://satellite.example.com/api/v2/hosts?search=model=\"RHV+Hypervisor\" \ | python3 -m json.tool
$ curl --request GET --user My_User_Name:My_Password \
https://satellite.example.com/api/v2/hosts?search=model=\"RHV+Hypervisor\" \
| python3 -m json.tool
応答例:
ホストの削除
この要求は、名前が host1.example.com のホストを削除します。
要求例:
curl --request DELETE --user My_User_Name:My_Password \ https://satellite.example.com/api/v2/hosts/host1.example.com \ | python3 -m json.tool
$ curl --request DELETE --user My_User_Name:My_Password \
https://satellite.example.com/api/v2/hosts/host1.example.com \
| python3 -m json.tool
全ホストのブートディスクイメージのダウンロード
以下の要求では、ホストの完全な起動ディスクイメージを ID を使用してダウンロードします。
要求例:
curl --request GET --user My_User_Name:My_Password \ https://satellite.example.com/api/bootdisk/hosts/host_ID?full=true \ --output image.iso
$ curl --request GET --user My_User_Name:My_Password \
https://satellite.example.com/api/bootdisk/hosts/host_ID?full=true \
--output image.iso