第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. ホストの使用方法 リンクのコピーリンクがクリップボードにコピーされました!
6.1.1. ホストのリスト表示 リンクのコピーリンクがクリップボードにコピーされました!
この例では、登録されたホストの一覧を返します。
API 要求
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
API 応答
6.1.2. ホストの情報要求 リンクのコピーリンクがクリップボードにコピーされました!
この要求は、satellite.example.com
ホストの情報を返します。
API 要求
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
API 応答
6.1.3. ホストのファクト表示 リンクのコピーリンクがクリップボードにコピーされました!
この要求は、satellite.example.com
ホストの全ファクトを返します。
API 要求
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
API 応答
6.1.4. パターンが一致するホストの検索 リンクのコピーリンクがクリップボードにコピーされました!
以下のクエリーは、"example" というパターンと一致するホストをすべて返します。
API 要求
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
API 応答
6.1.5. 環境でのホストの検索 リンクのコピーリンクがクリップボードにコピーされました!
以下のクエリーは、production
環境内の全ホストを返します。
API 要求
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
API 応答
6.1.6. 特定のファクト値を含むホストの検索 リンクのコピーリンクがクリップボードにコピーされました!
以下のクエリーでは、RHV Hypervisor
というモデル名のホストがすべて返されます。
API 要求
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
API 応答
6.1.7. ホストの削除 リンクのコピーリンクがクリップボードにコピーされました!
この要求は、名前が host1.example.com のホストを削除します。
API 要求
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
6.1.8. 全ホストのブートディスクイメージのダウンロード リンクのコピーリンクがクリップボードにコピーされました!
以下の要求では、ホストの完全な起動ディスクイメージを ID を使用してダウンロードします。
API 要求
curl \ --request GET \ --user My_User_Name:My_Password \ --output My_Image.iso \ https://satellite.example.com/api/bootdisk/hosts/host_ID?full=true
$ curl \
--request GET \
--user My_User_Name:My_Password \
--output My_Image.iso \
https://satellite.example.com/api/bootdisk/hosts/host_ID?full=true